Usage¶
signalslot.Signal
objects¶
Module defining the Signal class.
-
class
signalslot.signal.
DummyLock
[source]¶ Class that implements a no-op instead of a re-entrant lock.
-
class
signalslot.signal.
Signal
(args=None, name=None, threadsafe=False)[source]¶ Define a signal by instanciating a
Signal
object, ie.:>>> conf_pre_load = Signal()
Optionaly, you can declare a list of argument names for this signal, ie.:
>>> conf_pre_load = Signal(args=['conf'])
Any callable can be connected to a Signal, it must accept keywords (
**kwargs
), ie.:>>> def yourmodule_conf(conf, **kwargs): ... conf['yourmodule_option'] = 'foo' ...
Connect your function to the signal using
connect()
:>>> conf_pre_load.connect(yourmodule_conf)
Emit the signal to call all connected callbacks using
emit()
:>>> conf = {} >>> conf_pre_load.emit(conf=conf) >>> conf {'yourmodule_option': 'foo'}
Note that you may disconnect a callback from a signal if it is already connected:
>>> conf_pre_load.is_connected(yourmodule_conf) True >>> conf_pre_load.disconnect(yourmodule_conf) >>> conf_pre_load.is_connected(yourmodule_conf) False
-
emit
(**kwargs)[source]¶ Emit this signal which will execute every connected callback
slot
, passing keyword arguments.If a slot returns anything other than None, then
emit()
will return that value preventing any other slot from being called.>>> need_something = Signal() >>> def get_something(**kwargs): ... return 'got something' ... >>> def make_something(**kwargs): ... print('I will not be called') ... >>> need_something.connect(get_something) >>> need_something.connect(make_something) >>> need_something.emit() 'got something'
-
slots
¶ Return a list of slots for this signal.
-