On Thu, Jul 3, 2008 at 12:18 PM, infinite8s
<[EMAIL PROTECTED]> wrote:
> You mentioned above that your problems with pyglet and twisted have
> been solved. Did you find a way to integrate twisted with pyglet's
> event loop, or the other way around? Would you be willing to share
> some of your experiences integrating the two? Also, do you have any
> sample code of a successful coupling between twisted and pyglet?
> Thanks.
Sure, no problem. I ended up integrating a pyglet 1.0 style-loop into
twisted like this:
class MonitorWindow(pyglet.window.Window):
def update(self):
pass
def draw(self):
pass
def run(self):
# 1-time GL setup functions would go here
# Main Pyglet Loop
while not self.has_exit:
self.update()
self.dispatch_events()
media.dispatch_events()
self.clear()
self.draw()
self.flip()
yield 1
def shutdown(self, result=None):
print "User-initiated shutdown."
reactor.stop()
def bailout(self, reason):
print "Ouch! Bailing out..."
reason.printTraceback()
reactor.stop()
def twisted_stuff():
# Twisted stuff goes here
pass
if __name__ == '__main__':
monitor_window = MonitorWindow()
task.coiterate(monitor_window.run()).addCallback(monitor_window.shutdown).addErrback(monitor_window.bailout)
reactor.callWhenRunning(twisted_stuff)
reactor.run()
That's a stripped-down version of my actual code. You'll need to
import the correct stuff and actually do something useful, of course.
The result of that code is that Twisted calls monitor_window.run() and
pyglet takes over until the "yield" statement. Then Twisted takes
back control and does whatever it wants and returns to the
monitor_window.run() loop whenever it feels like it (I don't know how
often coiterate actually calls it), and then pyglet gets full control
until the yield statement again...etc. At least that's how I
understand it. In practice, I've limited pyglet to 30 fps, and had no
trouble maintaining that.
I know that some others have done some work to do the integration the
other way around on OS X and Linux, but as the pyglet+twisted
interaction is a relatively minor part of a work project for my job
and this method is working so far, I haven't been able to spend the
time to see how those work yet. Hopefully I'll get some time to work
on that in the next couple of months, though I wouldn't complain if
Alex et. al wanted to provide a more elegant "built-in" way for pyglet
to integrate with Twisted, as their python-fu is much superior to
mine. ;-)
~ Nathan
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---