pele.utils.events#
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]
-
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.connect()[source]
-
def connect(self, slot):connect a function / member function to the signal
- Signal.disconnect()[source]
-
def disconnect(self, slot):disconnect a function from the signal