If on_added() was getting called multiple times recursively, You would see 'on_added' printed to the screen a slew of times and then you would get an error that the max recursion depth was exceeded. Main's on_added event handler should only get called when you dispatch the event directly on main or another event dispatcher that main has been pushed onto (using push_handlers(), etc).
It might be useful to add a print statement after the child.dispatch_event() call in classB.addChild to see if that statement finishes and is called the expected number of times. -Casey On Mon, Dec 21, 2009 at 12:35 PM, omcginnis <[email protected]> wrote: > So I'm a little confused about how the EventDispatcher works... > perhaps someone can clue me in. Here goes... > > Assume the following: > > classA(EventDispatcher): > def __init__(self): > ...code.. > classA.register_event_type('on_added') > > classB(classA): > def __init__(self): > classA.__init__(self) > ...code... > > def addChild(self, child): > child.dispatch_event('on_added') > > class Main(classB): > def __init__(self): > ...code... > > def on_added(self): > print 'on_added' > # offending code > child = classB() > self.addChild(child) > > class App(object): > def __init__(self, main): > root = classB() > root.addChild(main) > > app = App(Main()) > > When I run this app 'on_added' prints to the console and then > everything freezes and I have to force quit. I can only guess that I'm > mixed up on how the EventDispatcher works. I'm guessing that my > on_added handler is getting triggered a second time when I create > another child element and add it, but I'm not positive. What I'm > unclear on is when the on_added handler get's triggered. Will Main's > on_added handler get triggered anytime any instance of classB > dispatches an 'on_added' event? I thought that I could get away with > the handler only being triggered when self dispatches the event... is > that not the case? > > Basically I'm trying to implement a simple parent/child relationship > between objects. Ideally, when Main get's added to root I'd expect > Main's on_added handler to get called. And when child get's added to > Main (in the on_added handler) I'd expect nothing to happen b/c I > haven't implemented a handler for 'on_added' events being dispatched > by child. Thanks in advance... > > -- > > 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. > > > -- 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.
