louie
Functions
f connect(receiver, signal=<class 'louie.signal.All'>, sender=<class 'louie.sender.Any'>, weak=True) ...
Connect receiver to sender for signal.
-
receiver: A callable Python object which is to receive messages/signals/events. Receivers must be hashable objects.
If weak is True, then receiver must be weak-referencable (more precisely saferef.safe_ref() must be able to create a reference to the receiver).
Receivers are fairly flexible in their specification, as the machinery in the robustapply module takes care of most of the details regarding figuring out appropriate subsets of the sent arguments to apply to a given receiver.
Note: If receiver is itself a weak reference (a callable), it will be de-referenced by the system's machinery, so generally weak references are not suitable as receivers, though some use might be found for the facility whereby a higher-level library passes in pre-weakrefed receiver references.
-
signal: The signal to which the receiver should respond.
If All, receiver will receive all signals from the indicated sender (which might also be All, but is not necessarily All).
Otherwise must be a hashable Python object other than None (DispatcherError raised on None).
-
sender: The sender to which the receiver should respond.
If Any, receiver will receive the indicated signals from any sender.
If Anonymous, receiver will only receive indicated signals from send/send_exact which do not specify a sender, or specify Anonymous explicitly as the sender.
Otherwise can be any python object.
-
weak: Whether to use weak references to the receiver.
By default, the module will attempt to use weak references to the receiver objects. If this parameter is False, then strong references will be used.
Returns None, may raise DispatcherTypeError.
f disconnect(receiver, signal=<class 'louie.signal.All'>, sender=<class 'louie.sender.Any'>, weak=True) ...
Disconnect receiver from sender for signal.
- receiver: The registered receiver to disconnect.
- signal: The registered signal to disconnect.
- sender: The registered sender to disconnect.
- weak: The weakref state to disconnect.
disconnect reverses the process of connect, the semantics for the individual elements are logically equivalent to a tuple of (receiver, signal, sender, weak) used as a key to be deleted from the internal routing tables. (The actual process is slightly more complex but the semantics are basically the same).
Note: Using disconnect is not required to cleanup routing when an object is deleted; the framework will remove routes for deleted objects automatically. It's only necessary to disconnect if you want to stop routing to a live object.
Returns None, may raise DispatcherTypeError or DispatcherKeyError.
f get_all_receivers(sender=<class 'louie.sender.Any'>, signal=<class 'louie.signal.All'>) ...
Get list of all receivers from global tables.
This gets all receivers which should receive the given signal from sender, each receiver should be produced only once by the resulting generator.
f send(signal=<class 'louie.signal.All'>, sender=<class 'louie.sender.Anonymous'>) ...
Send signal from sender to all connected receivers.
-
signal: (Hashable) signal value; see connect for details.
-
sender: The sender of the signal.
If Any, only receivers registered for Any will receive the message.
If Anonymous, only receivers registered to receive messages from Anonymous or Any will receive the message.
Otherwise can be any Python object (normally one registered with a connect if you actually want something to occur).
-
arguments: Positional arguments which will be passed to all receivers. Note that this may raise TypeError if the receivers do not allow the particular arguments. Note also that arguments are applied before named arguments, so they should be used with care.
-
named: Named arguments which will be filtered according to the parameters of the receivers to only provide those acceptable to the receiver.
Return a list of tuple pairs [(receiver, response), ...]
If any receiver raises an error, the error propagates back through send, terminating the dispatch loop, so it is quite possible to not have all receivers called if a raises an error.
f send_minimal(signal=<class 'louie.signal.All'>, sender=<class 'louie.sender.Anonymous'>) ...
Like send, but does not attach signal and sender arguments to the call to the receiver.
f send_exact(signal=<class 'louie.signal.All'>, sender=<class 'louie.sender.Anonymous'>) ...
Send signal only to receivers registered for exact message.
send_exact allows for avoiding Any/Anonymous registered handlers, sending only to those receivers explicitly registered for a particular signal on a particular sender.
f send_robust(signal=<class 'louie.signal.All'>, sender=<class 'louie.sender.Anonymous'>) ...
Send signal from sender to all connected receivers catching errors
-
signal: (Hashable) signal value, see connect for details
-
sender: The sender of the signal.
If Any, only receivers registered for Any will receive the message.
If Anonymous, only receivers registered to receive messages from Anonymous or Any will receive the message.
Otherwise can be any Python object (normally one registered with a connect if you actually want something to occur).
-
arguments: Positional arguments which will be passed to all receivers. Note that this may raise TypeError if the receivers do not allow the particular arguments. Note also that arguments are applied before named arguments, so they should be used with care.
-
named: Named arguments which will be filtered according to the parameters of the receivers to only provide those acceptable to the receiver.
Return a list of tuple pairs [(receiver, response), ... ]
If any receiver raises an error (specifically, any subclass of Exception), the error instance is returned as the result for that receiver.
Classes
C Any(...) ...
Used to represent either 'any sender'.
The Any class can be used with connect, disconnect, send, or sendExact to denote that the sender paramater should react to any sender, not just a particular sender.
This class contains 1 member.
C Plugin(...) ...
Base class for Louie plugins.
Plugins are used to extend or alter the behavior of Louie in a uniform way without having to modify the Louie code itself.
This class contains 1 member.
C Anonymous(...) ...
Singleton used to signal 'anonymous sender'.
The Anonymous class is used to signal that the sender of a message is not specified (as distinct from being 'any sender'). Registering callbacks for Anonymous will only receive messages sent without senders. Sending with anonymous will only send messages to those receivers registered for Any or Anonymous.
Note: The default sender for connect is Any, while the default sender for send is Anonymous. This has the effect that if you do not specify any senders in either function then all messages are routed as though there was a single sender (Anonymous) being used everywhere.
This class contains 1 member.
C All(...) ...
Used to represent 'all signals'.
The All class can be used with connect, disconnect, send, or sendExact to denote that the signal should react to all signals, not just a particular signal.
This class contains 1 member.
C QtWidgetPlugin(...) ...
A Plugin for Louie that knows how to handle Qt widgets when using PyQt built with SIP 4 or higher.
Weak references are not useful when dealing with QWidget instances, because even after a QWidget is closed and destroyed, only the C++ object is destroyed. The Python 'shell' object remains, but raises a RuntimeError when an attempt is made to call an underlying QWidget method.
This plugin alleviates this behavior, and if a QWidget instance is found that is just an empty shell, it prevents Louie from dispatching to any methods on those objects.
This class contains 1 member.
C TwistedDispatchPlugin(...) ...
Plugin for Louie that wraps all receivers in callables that return Twisted Deferred objects.
When the wrapped receiver is called, it adds a call to the actual receiver to the reactor event loop, and returns a Deferred that is called back with the result.
This class contains 1 member.
Modules
The louie module exposes 8 submodules:
- dispatcher
- Multiple-producer-multiple-consumer signal-dispatching.
- error
- Error types for Louie.
- plugin
- Common plugins for Louie.
- robustapply
- Robust apply mechanism.
- saferef
- Refactored 'safe reference from dispatcher.py
- sender
- Sender classes.
- signal
- Signal class.
- version
- Louie version information.
See the source for more information.