On Wed, Apr 15, 2009 at 1:36 AM, Mathew Byrne <[email protected]> wrote: > > Just playing around with the pyglet event framework, and I'm really > enjoying using the pattern in some of my applications. Just have a > small question regarding event dispatchers. Take the following > contrived example: > > import pyglet > > class Dispatcher(pyglet.event.EventDispatcher): > > def trigger(self): > self.dispatch_event('on_event') > > Dispatcher.register_event_type('on_event') > > class WatchOne(object): > > def __init__(self, subject): > subject.push_handlers(self) > self.subject = subject > > def on_event(self): > print 'event triggered' > > class WatchMany(object): > > def __init__(self): > self.subjects = [] > > def watch(self, subject): > subject.push_handlers(self) > self.subjects.append(subject) > > def on_event(self): > print 'event triggered' > > In this example the WatchOne class will always know where the event > originated since it's only expecting events dispatched from a single > object. WatchMany however will potentially be getting events from one > of many subjects and may need to know which one the event was > dispatched from. > > My question is: is there a simple way to find the event dispatcher? I > think I'm missing something obvious :S
I'd suggest including the dispatcher amongst the event parameters. Alex. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
