A recap: my goal is to have a "queue minder" function called at (say)
30 Hz from within the pyglet event loop, without requiring that all
windows get redrawn each time the queue minder function is run. The
queue-minder receives messages sent to pyglet from other threads, but
it could conceivably be waiting for network messages or whatnot as
well.


Here's my solution. I'm not sure if it's optimal, though...

(1) Override the pyglet event loop idle function as follows:

  class BackgroundEventLoop(pyglet.app.EventLoop):
    def idle(self):
      dt = pyglet.app.clock.tick(True)
      _tend_queue(dt)
      sleep_time = pyglet.app.clock.get_sleep_time(True)
      if sleep_time is None or sleep_time > queue_check_rate:
        return queue_check_rate
      else:
        return sleep_time

  So, this loop will run at least as fast as I want the queue checked.
However (unlike the default idle()), it does not cause windows to draw
every iteration.

(2) In order to get the windows to draw when required, I have two
approaches. One is to use a pyglet.window.Window() subclass which
overrides dispatch_event() as follows:

  def dispatch_event(self, *args):
    super(GraphicWindow, self).dispatch_event(*args)
    self.switch_to()
    self.on_draw()
    self.flip()

But this seems a bit flakey, since some events (like "on_close")
probably shouldn't be followed by drawing.
The other possibility is to just manually call switch_to(), on_draw(),
and flip() at the end of every function that will need a re-draw after
it's done. That seems OK too, but I wonder if there are subtle bugs
lurking there as well.

Any thoughts? Has anyone (maybe people writing networked pyglet
applications?) dealt with this issue before?

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