My take on a pythonic, and simple event system. It does not have any dependencies, beyond of course python!
####Event: This class represents an event.
Example usage:
e = Event() # Create event object
e.add_handler(myfunction) # Register handler
e() # Fire event, this will call all handlers
e.fire() # This also same as e()
Other:
If a handler raises StopIterator()
the event will not execute the rest of the handlers.
To bypass checks simply use e.append(myfunction)
instead.
####EventManager This class represents a list of events.
Example usage:
em = EventManager() # Create manager object.
em["myevent"] = Event() # Add an empty event called "myevent".
em["myevent"].add_handler(myfunction) # Add handler to an event.
em["myevent"]() # Fire the event: "myevent".
em.myevent() # You can also use '.' instead of [""], I prefer using '.'
Other:
Every EventManager
comes with a global event hook, it fires every time it gets a request to fire an event.
It acts like any ol' event
, and can be found under EventManager.got_event
- I use it in my McClientLib project. McClientLib
Add examples here, if you use this, please add a link to your code here!