Reference

Event

class whistle.Event[source]

Base class to represent whistle’s events. You can subclass this if you want to embed special data and associated logic with your events, or just let the event dispatcher create instances for you

The event handlers will have Event instances passed, so you can bundle any data required by your handlers there.

propagation_stopped = False

Has the event propagation ended?

stop_propagation()[source]

Stop event propagation, meaning that the remaining handlers won’t be called after this one.

EventDispatcher

class whistle.EventDispatcher[source]

A logical event dispatcher. All events can only be dispatched in the context of an EventDispatcher, and event dispatchers are fully independant and isolated.

add_listener(event_id, listener, priority=0)[source]
dispatch(event_id, event=None)[source]
do_dispatch(listeners, event)[source]
get_listeners(event_id=None)[source]
has_listeners(event_id=None)[source]
listen(event_id, priority=0)[source]

Decorator that add the decorated functions as one of this instance listeners, for the given event name.

Parameters:
  • event_id
  • priority
Returns:

remove_listener(event_id, listener)[source]

Remove a fiven listener from this event dispatcher. For now, if the listener is not registered for this event, this method has no effect, but we may raise ValueError in the future if the given listener is not found, you should catch it if you’re not certain the listener is registered.

TODO raise ValueError if not found.

Parameters:
  • event_id
  • listener
Returns:

sort_listeners(event_id)[source]