Skip to content

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

Signal(owner, name)

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

owner property

owner

The owner of this Signal, or None if there is no owner.

publish

publish(data)

Publish the signal (invoke subscribed callbacks).

Parameters:

Name Type Description Default

data

SignalT

An argument to pass to the callbacks.

required

subscribe

subscribe(node, callback, immediate=False)

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 True, otherwise post it to the DOM node to be called once existing messages have been processed.

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

node

MessagePump

Node to unsubscribe,

required

SignalError

Bases: Exception

Raised for Signal errors.