Hi Zach,

I've only just started using Pyglet so I can't offer any expert
advice, here's my 2 cents...
I'd suspect that running Pyglet in a separate thread could be a
problem: 
http://groups.google.com/group/pyglet-users/browse_thread/thread/11f44944d92370cf/03dd5120f11f9474
(Alex says "pyglet is completely thread-unsafe; you'll need to manage
all locking yourself. ")  I'd probably try to run the Pyglet app as
the main thread, and the other part as a background thread.
Better yet (especially since it might be easier to run a terminal this
way), you could break your code into a Pyglet application which does
the drawing, and a terminal application which handles the commands and
communicates with the pyglet app via networking (or a FIFO).  There's
been mention of a possible Twisted-based event look for Pyglet in the
works, which seems like it would make this sort of thing very easy.
On the Pyglet side of things, you could poll for input from the
terminal app, and use those to control your drawing.  I recently had a
stab at doing something like this when I got Pyglet to handle input
from a MIDI controller.  I wrote a function which polls a MIDI port
(once), and dispatches a custom event if it reads a MIDI message.
Then I called it every frame with pyglet.clock.schedule().  So far
it's stable, and responsive enough (for controlling on screen drawing,
haven't tried any audio).  In your case, you could check for messages
sent to your drawing app each frame. That said, does anyone know of a
better way to dispatch pyglet events from realtime input like this?  I
haven't done any tests yet to see how badly calling schedule() effects
the CPU load / performance.

Hope that was somewhat helpful,
Colin

On Wed, Apr 9, 2008 at 9:43 AM, Zachrahan <[EMAIL PROTECTED]> wrote:
>
>  Hello folks,
>
>  I'd like to run a pyglet window/etc in a background thread in the
>  context of an interactive interpreter, so that the interpreter isn't
>  tied up. (I'm writing a microscope-control program, and basically, I
>  want to blit images from the microscope camera to a pyglet window
>  [with live brightness/contrast controls], while actually driving the
>  microscope via interpreted, or eventually scripted, command sessions.)
>
>  I know IPython has provisions for this sort of thing with Tkinter and
>  WXPython, and I think that sympy has some code for doing this with
>  pyglet. Before I go about digging through that, does anyone know of
>  some basic example code for this sort of thing, general tips, or know
>  whether it's even possible or worth going about?
>
>  Sorry if this is a total newbie question, asked and answered
>  elsewhere, but I'm not finding a lot about this particular topic, and
>  my naive attempts to just run an event-handler loop in a separate
>  python thread from the interpreter fail pretty spectacularly for
>  reasons I more or less fail to understand...
>
>  Thanks,
>  Zach
>  >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"pyglet-users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/pyglet-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to