(Current docs for reference: http://pyglet.readthedocs.io/en/latest/programming_guide/events.html )
I've never done any serious UI programming myself so I'm not the best to comment here, but I've also found this example a little obtuse. Maybe we can come up with an alternate example, that might be a little easier to follow. I do like the Observer example at the bottom, but maybe we can just have one simple concrete example, without going into separate techniques? I suppose the question is what's a good example? :) There are some good (game related) ideas here: http://gameprogrammingpatterns.com/observer.html On Friday, July 7, 2017 at 6:56:37 AM UTC+9, Charles wrote: > > This may seem like a dumb question but trying to understand the point of > the custom event dispatcher. Looking at the example: > > class ClankingWidget(pyglet.event.EventDispatcher): > def clank(self): > self.dispatch_event('on_clank') > > def click(self, clicks): > self.dispatch_event('on_clicked', clicks) > > def on_clank(self): > print 'Default clank handler.' > > > ClankingWidget.register_event_type('on_clank') > ClankingWidget.register_event_type('on_clicked') > > widget = ClankingWidget() > > @widget.event > def on_clank(): > pass > > @widget.event > def on_clicked(clicks): > pass > > def override_on_clicked(clicks): > pass > > widget.push_handlers(on_clicked=override_on_clicked) > > > Is this just a way to do some sort of inheritance? What is the benefit of > going through the event system as opposed to Widget being its own class > with its own clank or on_clank method? For instance instead of having > on_clank at all, just have clank and any 'widgets' that need to use it will > have their own clank method. I understand the 'publisher/subscriber' case > where the EventDispatcher is the caller or some sort of controller, and the > handlers are the 'observers', but not sure how in what cases this works in > reverse. > > Can someone explain this in a little more detail and some example of how > it would be used in a game? > -- 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 https://groups.google.com/group/pyglet-users. For more options, visit https://groups.google.com/d/optout.
