bootstack.Signal#
- class bootstack.Signal(value, name=None, master=None)#
Bases:
Generic[T]A reactive value that widgets can bind to.
Holds a typed value and notifies subscribers when it changes. Read it by calling the signal, update it with
set(), derive new signals withmap(), and react to changes withsubscribe().Bind a signal to a widget by passing it as
textsignal=for text-bearing widgets, orsignal=for boolean and numeric widgets.- property type: Type[T]#
The original type of the signal value.
- Returns:
A Python type (e.g., int, str).
- __call__()#
Get the current value of the signal.
- Returns:
The current typed value.
- Return type:
T
- map(transform)#
Create a derived signal that transforms this signal’s value.
The derived signal recomputes whenever this signal changes. It is held weakly, so keep a reference to it — for example, by binding it to a widget — or it will stop updating once garbage-collected.
- set(value)#
Set the signal to a new value and notify subscribers.
- Parameters:
value (T) – The new value. Must match the signal’s type, except that an
intmay be set on afloat-typed signal (it is widened).- Raises:
TypeError – If the value type does not match the signal’s type (and is not an
intwidened to afloat).
- subscribe(callback, *, immediate=False)#
Subscribe to value changes of this signal.
- Parameters:
- Returns:
A subscription id — pass it to
unsubscribe()to stop listening.- Return type:
- unsubscribe(funcid)#
Remove a previously registered subscriber.
- Parameters:
funcid (str) – The function id returned from
subscribe().
- unsubscribe_all()#
Remove all currently subscribed callbacks.