Provides a signals-like system for sending and listening for ‘events’
Events are kind of like signals, except they may be listened for on a global scale, rather than connected on a per-object basis like signals are. This means that ANY object can emit ANY event, and these events may be listened for by ANY object.
Events should be emitted AFTER the given event has taken place. Often the most appropriate spot is immediately before a return statement.
log_event(type, obj, data)¶
Sends an event.
- type (string) – the type or name of the event.
- obj (object) – the object sending the event.
- data (object) – some data about the event, None if not required
add_callback(function, type=None, obj=None, *args, **kwargs)¶
Adds a callback to an event
You should ALWAYS specify one of the two options on what to listen for. While not forbidden to listen to all events, doing so will cause your callback to be called very frequently, and possibly may cause slowness within the player itself.
- function (callable) – the function to call when the event happens
- type (string) – the type or name of the event to listen for, eg tracks_added, cover_changed. Defaults to any event if not specified.
- obj (object) – the object to listen to events from, e.g. exaile.collection or xl.covers.MANAGER. Defaults to any object if not specified.
Any additional parameters will be passed to the callback.
Returns: a convenience function that you can call to remove the callback.
remove_callback(function, type=None, obj=None)¶
Removes a callback
The parameters passed should match those that were passed when adding the callback