Uranium
Application Framework
|
Simple implementation of signals and slots. More...
Public Member Functions | |||
def | __init__ | ||
Initialize the instance. More... | |||
def | getName | ||
def | __call__ | ||
| |||
def | getType | ||
Get type of the signal. More... | |||
def | emit | ||
Emit the signal which indirectly calls all of the connected slots. More... | |||
def | connect | ||
Connect to this signal. More... | |||
def | disconnect | ||
Disconnect from this signal. More... | |||
def | disconnectAll | ||
Disconnect all connected slots. More... | |||
def | __getstate__ | ||
To support Pickle. More... | |||
def | __deepcopy__ | ||
To properly handle deepcopy in combination with getstate More... | |||
Static Public Attributes | |
int | Direct = 1 |
Signal types. More... | |
int | Auto = 2 |
int | Queued = 3 |
Simple implementation of signals and slots.
Signals and slots can be used as a light weight event system. A class can define signals that other classes can connect functions or methods to, called slots. Whenever the signal is called, it will proceed to call the connected slots.
To create a signal, create an instance variable of type Signal. Other objects can then use that variable's connect()
method to connect methods, callable objects or signals to the signal. To emit the signal, call emit()
on the signal. Arguments can be passed along to the signal, but slots will be required to handle them. When connecting signals to other signals, the connected signal will be emitted whenever the signal is emitted.
Signal-slot connections are weak references and as such will not prevent objects from being destroyed. In addition, all slots will be implicitly disconnected when the signal is destroyed.
Loosely based on http://code.activestate.com/recipes/577980-improved-signalsslots-implementation-in-python/ #pylint: disable=wrong-spelling-in-comment
def UM.Signal.Signal.__init__ | ( | self, | |
type | |||
) |
Initialize the instance.
kwargs | Keyword arguments. Possible keywords:
|
def UM.Signal.Signal.__deepcopy__ | ( | self, | |
memo | |||
) |
To properly handle deepcopy in combination with getstate
Apparently deepcopy uses getstate internally, which is not documented. The reimplementation of getstate then breaks deepcopy. On the other hand, if we do not reimplement it like that, we break pickle. So instead make sure to also reimplement deepcopy.
def UM.Signal.Signal.__getstate__ | ( | self | ) |
To support Pickle.
Since Weak containers cannot be serialized by Pickle we just return an empty dict as state.
def UM.Signal.Signal.connect | ( | self, | |
connector | |||
) |
Connect to this signal.
connector | The signal or slot (function) to connect. |
def UM.Signal.Signal.disconnect | ( | self, | |
connector | |||
) |
Disconnect from this signal.
connector | The signal or slot (function) to disconnect. |
def UM.Signal.Signal.disconnectAll | ( | self | ) |
Disconnect all connected slots.
def UM.Signal.Signal.emit | ( | self, | |
args | |||
) |
Emit the signal which indirectly calls all of the connected slots.
args | The positional arguments to pass along. |
kwargs | The keyword arguments to pass along. |
def UM.Signal.Signal.getType | ( | self, | |
int | |||
) |
Get type of the signal.
|
static |
Signal types.
These indicate the type of a signal, that is, how the signal handles calling the connected slots.