textual.signal
Signals are a simple pub-sub mechanism.
DOMNodes can subscribe to a signal, which will invoke a callback when the signal is published.
This is experimental for now, for internal use. It may be part of the public API in a future release.
Signal
¶
Bases: Generic[SignalT]
A signal that a widget may subscribe to, in order to invoke callbacks when an associated event occurs.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
|
DOMNode
|
The owner of this signal. |
required |
|
str
|
An identifier for debugging purposes. |
required |
publish
¶
publish(data)
Publish the signal (invoke subscribed callbacks).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
|
SignalT
|
An argument to pass to the callbacks. |
required |
subscribe
¶
Subscribe a node to this signal.
When the signal is published, the callback will be invoked.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
|
MessagePump
|
Node to subscribe. |
required |
|
SignalCallbackType
|
A callback function which takes a single argument and returns anything (return type ignored). |
required |
|
bool
|
Invoke the callback immediately on publish if |
False
|
Raises:
Type | Description |
---|---|
SignalError
|
Raised when subscribing a non-mounted widget. |
unsubscribe
¶
unsubscribe(node)
Unsubscribe a node from this signal.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
|
MessagePump
|
Node to unsubscribe, |
required |