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 |
---|---|---|---|
owner |
DOMNode
|
The owner of this signal. |
required |
name |
str
|
An identifier for debugging purposes. |
required |
publish ¶
Publish the signal (invoke subscribed callbacks).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data |
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 |
---|---|---|---|
node |
MessagePump
|
Node to subscribe. |
required |
callback |
SignalCallbackType
|
A callback function which takes a single argument and returns anything (return type ignored). |
required |
immediate |
bool
|
Invoke the callback immediately on publish if |
False
|
Raises:
Type | Description |
---|---|
SignalError
|
Raised when subscribing a non-mounted widget. |
unsubscribe ¶
Unsubscribe a node from this signal.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
node |
MessagePump
|
Node to unsubscribe, |
required |