Members Reference¶
📶 Python Library - emitcallback (Emit Callback)
Python library that implements callable collectors to call to react on an event.
Use cases are reducing the amount of coupling, components systems, events systems and games. This project is inspired from Godot’s game engine signals.
Hint
All classes supports being copied with Python’s copy module.
Warning
Connections with async callables or usage with threads aren’t fully supported, and their usage hasn’t been tested at all.
Other useful pages in this documentation: - Glossary - Examples
- class Single(callback: Callable[P, Any] | None = None, flags: int = 0)¶
Bases:
Generic[P]object that wraps only one callable or none.
- connect(callback: Callable[P, Any], flags: int = 0) None¶
overrides the current connection with another callable and sets the connection tags.
will always connect with a reference when
SINGLE_NO_WEAKis enabled.
- disconnect(callback: Callable[P, Any]) None¶
removes the current connection if the callable matches.
- disconnect_any() None¶
removes any current connection.
- emit(*args: P.args, **kwargs: P.kwargs) None¶
calls the current connection with the argouments.
removes the connection first if
SINGLE_ONE_SHOTis enabled.will raise any exception thrown by the callable.
- Raises:
Exception – depends on the connected callable.
- is_connected(callback: Callable[P, Any]) bool¶
checks if the current connection matches the callable.
- is_connected_any() bool¶
checks if there’s is a connection with a callable.
- class Signal¶
Bases:
Generic[P]objects that store an ordered collection of callables and emittion will call each callables sequencially.
- connect(callback: Callable[P, Any], flags: int = 0) None¶
append a new connection. won’t connect if it fails.
- Raises:
AlreadyConnectedException – if the
SIGNAL_MULTI_CONNECTisn’t enabled and the callable is already connected.
- connect_all(*callbacks: Callable[P, Any], flags: int = 0) None¶
same as
connect()but connects multiple callables at once with the same flags. won’t connect anything if at least one of the callable fails connection.- Raises:
AlreadyConnectedException – on the first callable that’s already connected whitout using the
SIGNAL_MULTI_CONNECTflag.
- disconnect(callback: Callable[P, Any]) None¶
removes any connection (if multiple exists) of a callable from this signal. won’t do anything if the callable isn’t connected.
- disconnect_all() None¶
disconnects all callables immediatly.
- disconnect_each(*callbacks: Callable[P, Any]) None¶
same as
disconnect()but disconnects multiple callbacks at once.
- emit(*args: P.args, **kwargs: P.kwargs) None¶
calls each connected callable sequencially ordered by the oldest.
will raise an exception group for all exceptiong captured from the callables.
before being called the callable will be disconnected if
SIGNAL_ONE_SHOThas been used.by default an exception won’t interrupt the call sequence but if the callable has been connected with the
SIGNAL_INTERRUPT_EXCEPTIONwill interrupt the call sequence.- Raises:
ExceptionGroup – any exception raised by the callables.
- extend(other: Signal[P]) None¶
appends all connections from another signal into this one using their original flags.
will raise an exception and won’t connect anything if at least one connection already exist in this signal whitout using the
SIGNAL_MULTI_CONNECTflag.
- is_connected(callback: Callable[P, Any]) bool¶
checks if the callable has at least connection in this signal.
- class Queue¶
Bases:
Generic[P]object that store an ordered collection of callables and emittion will call the oldest callable avaiable.
- connect(callback: Callable[P, Any], *, noweak: bool = False) None¶
appends a new connection to this queue.
by default a connection may use a weak reference to the callable if it’s an object method and automatically disconnects when the object is destroyed from memory.
- Parameters:
noweak – if enabled will always use a reference of the callable and keeps the object alive.
- connect_all(*callbacks: Callable[P, Any], noweak: bool = False) None¶
same as
connect()will connect each callable at once.
- disconnect(callback: Callable[P, Any]) None¶
disconnects all connections of a callable from this queue.
will do nothing if the callable wasn’t connected.
- disconnect_all() None¶
disconnects all callables from this queue immediatly.
- disconnect_each(*callbacks: Callable[P, Any]) None¶
same as
disconnect()but disconnects multiple callbacks at once.
- emit(*args: P.args, **kwargs: P.kwargs) bool¶
calls the oldest callable from the queue avaiable with the argouments is do nothing if none are avaiable.
returns True if a callable has been called otherwise False if the queue has called all avaiable callables.
will raise any exception thrown by the callable.
- Raises:
Exception – depends on the connected callable.
- Returns:
if a callable was avaiable and has been emitted.
- is_connected(callback: Callable[P, Any]) bool¶
checks if the callable has at least one connection in this queue.
Constants¶
- SINGLE_NO_WEAK = 1¶
int([x]) -> integer int(x, base=10) -> integer
Convert a number or string to an integer, or return 0 if no arguments are given. If x is a number, return x.__int__(). For floating-point numbers, this truncates towards zero.
If x is not a number or if base is given, then x must be a string, bytes, or bytearray instance representing an integer literal in the given base. The literal can be preceded by ‘+’ or ‘-’ and be surrounded by whitespace. The base defaults to 10. Valid bases are 0 and 2-36. Base 0 means to interpret the base from the string as an integer literal. >>> int(‘0b100’, base=0) 4
- SINGLE_ONE_SHOT = 2¶
int([x]) -> integer int(x, base=10) -> integer
Convert a number or string to an integer, or return 0 if no arguments are given. If x is a number, return x.__int__(). For floating-point numbers, this truncates towards zero.
If x is not a number or if base is given, then x must be a string, bytes, or bytearray instance representing an integer literal in the given base. The literal can be preceded by ‘+’ or ‘-’ and be surrounded by whitespace. The base defaults to 10. Valid bases are 0 and 2-36. Base 0 means to interpret the base from the string as an integer literal. >>> int(‘0b100’, base=0) 4
- SIGNAL_NO_WEAK = 1¶
int([x]) -> integer int(x, base=10) -> integer
Convert a number or string to an integer, or return 0 if no arguments are given. If x is a number, return x.__int__(). For floating-point numbers, this truncates towards zero.
If x is not a number or if base is given, then x must be a string, bytes, or bytearray instance representing an integer literal in the given base. The literal can be preceded by ‘+’ or ‘-’ and be surrounded by whitespace. The base defaults to 10. Valid bases are 0 and 2-36. Base 0 means to interpret the base from the string as an integer literal. >>> int(‘0b100’, base=0) 4
- SIGNAL_ONE_SHOT = 2¶
int([x]) -> integer int(x, base=10) -> integer
Convert a number or string to an integer, or return 0 if no arguments are given. If x is a number, return x.__int__(). For floating-point numbers, this truncates towards zero.
If x is not a number or if base is given, then x must be a string, bytes, or bytearray instance representing an integer literal in the given base. The literal can be preceded by ‘+’ or ‘-’ and be surrounded by whitespace. The base defaults to 10. Valid bases are 0 and 2-36. Base 0 means to interpret the base from the string as an integer literal. >>> int(‘0b100’, base=0) 4
- SIGNAL_MULTI_CONNECT = 4¶
int([x]) -> integer int(x, base=10) -> integer
Convert a number or string to an integer, or return 0 if no arguments are given. If x is a number, return x.__int__(). For floating-point numbers, this truncates towards zero.
If x is not a number or if base is given, then x must be a string, bytes, or bytearray instance representing an integer literal in the given base. The literal can be preceded by ‘+’ or ‘-’ and be surrounded by whitespace. The base defaults to 10. Valid bases are 0 and 2-36. Base 0 means to interpret the base from the string as an integer literal. >>> int(‘0b100’, base=0) 4
- SIGNAL_INTERRUPT_EXCEPTION = 8¶
int([x]) -> integer int(x, base=10) -> integer
Convert a number or string to an integer, or return 0 if no arguments are given. If x is a number, return x.__int__(). For floating-point numbers, this truncates towards zero.
If x is not a number or if base is given, then x must be a string, bytes, or bytearray instance representing an integer literal in the given base. The literal can be preceded by ‘+’ or ‘-’ and be surrounded by whitespace. The base defaults to 10. Valid bases are 0 and 2-36. Base 0 means to interpret the base from the string as an integer literal. >>> int(‘0b100’, base=0) 4
Exceptions¶
- exception AlreadyConnectedException¶
Bases:
Exceptionexception raised when a callable object is already connected.