I have a main object with a Pyglet window as an attribute. Pylget's window
class has a method called push handlers, which lets me push methods to the
event stack. The following code works:
import pyglet
class main:
win = None
def __init__(self, window):
self.win = window
self.win.push_handlers(self)
pyglet.app.win()
def on_mouse_press(self, x, y, button, modifier):
'''on_mouse_press() is an accepted handler for the window object.'''
variousMouseEventCheckingBitsForHappiness()
def on_draw(self):
'''Also a few draw functions, so I can see immediately
that the handlers are getting pushed.'''
openglDrawFunctionsForMoreHappiness()
m = main(pyglet.window.Window())
The above code will spawn a new window at the default size and attach the
on_mouse_press() event handler to it. That works well and good - however,
trying to call on the push_handlers() method in other classes doesn't seem
to work:
import pyglet
class main:
win = None
menuScreen = None
def __init__(self, window):
self.win = window
self.menuScreen = menu(self.win)
self.menuScreen.add()
pyglet.app.win()
class menu:
win = None
def add(self, window):
self.win = window
self.win.push_handlers(self)
def on_mouse_press(x, y, button, modifier):
'''on_mouse_press() is an accepted handler for the window object.'''
variousMouseEventCheckingBitsForHappiness()
def on_draw(self):
'''Also a few draw functions, so I can see immediately
that the handlers are getting pushed.'''
openglDrawFunctionsForMoreHappiness()
m = main(pyglet.window.Window())
The above code spawns a new window, but it doesn't attach the menu class's
handlers. Is there a reason for this, or a workaround I can use? Thanks!
--
You received this message because you are subscribed to the Google Groups
"pyglet-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/pyglet-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.