Hi everyone!
This is my first time here so I apologize in advance if I break some rules.
I've been using pyglet for a while and I've found the EventDispatcher's push_handlers() and pop_handlers() implementation very inflexible. Very often I want to add handlers between others in the stack, and likewise remove some in the middle of the stack. One particular use-case is for example having sprites or other game objects which need to receive events but are created and deleted during the lifetime of the game, but there are many others (scene management is another) which can benefit greatly from this.
The change is as simple as going from:
def push_handlers(self, *args, **kwargs):
to
def push_handlers(self, index, *args, **kwargs):
and similarly for pop_handlers(). I realize as an API change this may be unfavorable, in which case new method names can be made (e.g. push_handlers_at()). This is a very small change (Only 4 lines need to be changed, or slightly more added with the new method name implementation) but a huge increase in flexibility in pyglet's event system.
What are everyone's thoughts on this matter?
It sounds like you either have very complex needs, in which case you should probably just write your own functions to manipulate the stacks yourself, or your normal needs are suffering from an abnormally complex implementation. :-) Just my opinion -- and I'm just another pyglet user. Every time I've found myself wishing for similar modifications to pyglet's event design, I soon found that conforming to the existing design forced me to improve my own code's structure quite a bit.
By the way, you can already remove handler(s) from the middle of the stack, providing you know exactly what callable was pushed onto it:
~ Nathan