pele.utils.events#

Module source

adapted from http://code.activestate.com/recipes/577980-improved-signalsslots-implementation-in-python/

A signal/slot implementation

File: signal.py Author: Thiago Marcos P. Santos Author: Christopher S. Case Author: David H. Bronke Created: August 28, 2008 Updated: December 12, 2011 License: MIT

class pele.utils.events.Signal[source]

Source

class Signal:
class for signal slot concept

Example
-------

A simple example for a callback is
>>> event = Signal()
>>> event.connect(mfunc)
>>> # raise the signal
>>> event("hello")
>>>
>>> # functions can be disconnected
>>> even.disconnect(myfunc)

Since weak references are used, care has to be taken with object functions

>>> obj = MyClass()
>>> event.connect(obj.myfunc) # works
>>> event.connect(MyClass().myfunc) # will not work

The second example for member functions will not work since the Signal class
uses weakref and therefore does not increase the reference counter. MyClass()
only exists for the time of the function call and will be deleted afterwards
and the weakref will become invalid.
Signal.__call__()[source]

Source

def __call__(self, *args, **kargs):

raise the event

Signal.connect()[source]

Source

def connect(self, slot):

connect a function / member function to the signal

Signal.disconnect()[source]

Source

def disconnect(self, slot):

disconnect a function from the signal

Signal.clear()[source]

Source

def clear(self):

remove all callbacks from the signal