evennia.contrib.base_systems.components.signals¶
Components - ChrisLR 2022
This file contains classes functions related to signals.
- evennia.contrib.base_systems.components.signals.as_listener(func=None, signal_name=None)[source]¶
Decorator style function that marks a method to be connected as listener. It will use the provided signal name and default to the decorated function name.
- Parameters:
func (callable) – The method to mark as listener
signal_name (str) – The name of the signal to listen to, defaults to function name.
- evennia.contrib.base_systems.components.signals.as_responder(func=None, signal_name=None)[source]¶
Decorator style function that marks a method to be connected as responder. It will use the provided signal name and default to the decorated function name.
- Parameters:
func (callable) – The method to mark as responder
signal_name (str) – The name of the signal to respond to, defaults to function name.
- class evennia.contrib.base_systems.components.signals.SignalsHandler(host)[source]¶
Bases:
objectThis object handles all about signals. It holds the connected listeners and responders. It allows triggering signals or querying responders.
- add_listener(signal_name, callback)[source]¶
Connect a listener to a specific signal.
- Parameters:
signal_name (str) – The name of the signal to listen to
callback (callable) – The callable that is called when the signal is triggered
- add_responder(signal_name, callback)[source]¶
Connect a responder to a specific signal.
- Parameters:
signal_name (str) – The name of the signal to respond to
callback (callable) – The callable that is called when the signal is queried
- remove_listener(signal_name, callback)[source]¶
Removes a listener for a specific signal.
- Parameters:
signal_name (str) – The name of the signal to disconnect from
callback (callable) – The callable that was used to connect
- remove_responder(signal_name, callback)[source]¶
Removes a responder for a specific signal.
- Parameters:
signal_name (str) – The name of the signal to disconnect from
callback (callable) – The callable that was used to connect
- trigger(signal_name, *args, **kwargs)[source]¶
Triggers a specific signal with specified args and kwargs This method does not return anything
- Parameters:
signal_name (str) – The name of the signal to trigger
- query(signal_name, *args, default=None, aggregate_func=None, **kwargs)[source]¶
Queries a specific signal with specified args and kwargs This method will return the responses from its connected responders. If an aggregate_func is specified, it is called with the responses and its result is returned instead.
- Parameters:
signal_name (str) – The name of the signal to trigger
default (any) – The value to use when no responses are given It will be passed to aggregate_func if it is also given.
aggregate_func (callable) – The function to process the results before returning.
- Returns:
list –
- An iterable of the responses
OR the aggregated result when aggregate_func is specified.