Method summary
- __init__(self)
- connect(self, obj, event, callback)
- disconnect(self, obj, event = None, callback = None, obj_is_hash = False)
- get_signal_names(self, obj)
- is_registered(self, obj)
- send(self, source, event, *args, **kw_args)
Methods
- __init__(self)
Create the messenger. This class is Borg. So all instances are the same.
- connect(self, obj, event, callback)
Registers a slot given an object and its signal to slot into and also given a bound method in callback that should have two arguments. send will call the callback with the object that emitted the signal and the actual event/signal as arguments.
Parameters
obj : Python object
Any Python object that will generate the particular event.
event : An event (can be anything, usually strings)
The event obj will generate. If this is in the list self._catch_all, then any event will call this callback.
callback : function or method
This callback will be called when the object generates the particular event. The object, event and any other arguments and keyword arguments given by the obj are passed along to the callback.
- disconnect(self, obj, event = None, callback = None, obj_is_hash = False)
Disconnects the object and its event handlers.
Parameters
obj : Object
The object that generates events.
event : The event. (defaults to None)
callback : function or method
The event handler.
If event and callback are None (the default) all the events and handlers for the object are removed. If only callback is None, only this handler is removed. If obj and 'event' alone are specified, all handlers for the event are removed.
- obj_is_hash : bool
Specifies if the object passed is a hash instead of the object itself. This is needed if the object is gc'd but only the hash exists and one wants to disconnect the object.
- get_signal_names(self, obj)
Returns a list of signal names the object passed has registered.
- is_registered(self, obj)
Returns if the given object has registered itself with the messenger.
- send(self, source, event, *args, **kw_args)
To be called by the object source that desires to generate a particular event. This function in turn invokes all the handlers for the event passing the source object, event and any additional arguments and keyword arguments. If any connected callback is garbage collected without being disconnected, it is silently removed from the existing slots.
Parameters
source : Python object
This is the object that generated the event.
event : The event.
If there are handlers connected to events called 'AnyEvent' or 'all', then any event will invoke these.