Package elisa :: Package core :: Package utils :: Module signal :: Class Signal
[hide private]
[frames] | no frames]

Class Signal

source code


A Signal is a 1-to-many communication system. It provides a way for two objects to communicate without knowing about each other. They only have to know about the signal object. Receivers objects connect to the signal and emitters can trigger the emission of the signal so that it is sent to all the receivers. Signal emission is synchronous, that is, the receivers are immediatly called upon emission, one after the other.

WARNING: TODO:

Instance Methods [hide private]
 
__init__(self, name, *args_types, **kw_types)
Initialize a signal with the signature of receivers that can connect to it.
source code
string
__repr__(self)
Textual representation of the Signal
source code
 
connect(self, receiver)
Connect a receiver to the signal.
source code
 
disconnect(self, receiver)
Disconnect a receiver from the signal.
source code
 
emit(self, *args, **kw)
Call all the connected receivers.
source code
 
_check_args_types(self, args, kw)
Check the types of arguments and keywords comply with types specifications given at Signal creation.
source code

Inherited from object: __delattr__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __setattr__, __str__

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, name, *args_types, **kw_types)
(Constructor)

source code 
Initialize a signal with the signature of receivers that can connect to it.
Parameters:
  • name (string) - name of the signal. Not unique, but developer friendly
  • args_types (tuple of types) - arguments types of the receivers that can connect to the signal
  • kw_types (dictionary of types) - arguments types of the receivers that can connect to the signal
Overrides: object.__init__

__repr__(self)
(Representation operator)

source code 
Textual representation of the Signal
Returns: string
information about the signal and its receivers
Overrides: object.__repr__

connect(self, receiver)

source code 
Connect a receiver to the signal. It will be called when the signal is emitted.
Parameters:
  • receiver (callable) - object to be called when the signal is emitted
Raises:
  • TypeError - raised if the receiver is not callable

disconnect(self, receiver)

source code 
Disconnect a receiver from the signal.
Parameters:
  • receiver (callable) - object to be disconnected
Raises:
  • Exception - raised if the receiver is not connected

emit(self, *args, **kw)

source code 
Call all the connected receivers. It avoids calling the neutralized ones. Since receivers calling is not ordered, one should be careful with the potential side effects in the receivers.
Parameters:
  • args (tuple) - arguments passed to the receivers
  • kw (dictionary) - arguments passed to the receivers
Raises:
  • WrongArgument - Raised if one of the arguments is of the wrong type

_check_args_types(self, args, kw)

source code 
Check the types of arguments and keywords comply with types specifications given at Signal creation.
Raises:
  • WrongArgument - Raised if one of the arguments is of the wrong type