Hello all, I've ironed a few bugs out of my method for running a pyglet event loop in a background thread, so that it is possible to interact with active pyglet windows from within an interactive python session. This seems to work pretty smoothly on both mac and windows, but I haven't tested with linux (no reason it wouldn't work, though).
The concept is very simple: pyglet functions must be called from the thread that pyglet set up its context in. So, I start a pyglet event loop in a background thread, and then just have the event loop check for "messages" from a queue periodically, where the "messages" are simply functions to call from within the pyglet thread. There are also some helper functions to add calls to the queue, and to construct "proxy" pyglet objects that look like live objects in the foreground thread, but really funnel all method invocations through the queue. The upshot being that you can do things like: >>> import background_pyglet >>> import background_opengl >>> window = background_pyglet.PygletProxy(background_opengl.GLWindow, >>> resizable=True) >>> window.set_color(1,0,1,1) >>> window.speed = 0.5 >>> window.close() Code and examples are here: http://pyglet-users.googlegroups.com/web/background_pyglet.zip There are a few caveats, related to how the background event loop works. Basically, to keep things responsive to both GUI and CLI interaction, the event loop no longer calls switch_to(), on_draw(), and flip() on every window during each iteration of the event loop. This means that any functions that alter a window's state need to call on_draw() on that window directly, and that on_draw() itself must call switch_to() first and flip() last. (Also, it means that other functions that interact with the GL context of a window also need to call switch_to() to ensure that window's context is active first. The exception is that if a function is an event handler of some sort, switch_to gets called automatically beforehand.) Hope this is useful, Zach Pincus --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
