aeidon.Observable

Source: aeidon/observable.py

Anchestors: builtins.object

class aeidon.Observable

Base class for observable objects.

Observable.signals

Tuple of emittable signals added automatically

In addition to the signals defined in signals, all public instance variables have a notify::NAME signal generated automatically based on the NAME of the variable. notify::NAME signals will be emitted whenever the value of the corresponding instance variable changes.

Notify signals will be emitted for mutable variables as well, which means that care should be taken not to emit thousands of signals when e.g. appending one-by-one to a large list. freeze_notify() and thaw_notify() will queue notify signals and emit only one of each once thawed.

The Observable philosophy and API is highly inspired by GObject.

Methods

Observable.__init__()

Initialize an Observable instance.

Observable.block(signal)

Block all emissions of signal.

Return False if already blocked, otherwise True.

Observable.block_all()

Block all emissions of all signals.

Return False if already blocked, otherwise True.

Observable.connect(signal, method, *args)

Register to receive notifications of signal.

Observable.disconnect(signal, method)

Remove registration to receive notifications of signal.

Observable.emit(signal, *args)

Send notification of signal to all registered observers.

Observable.freeze_notify()

Queue notify signals instead of emitting them.

Return False if already frozen, otherwise True.

Observable.notify(name)

Emit notification signal for variable.

Observable.thaw_notify(do=True)

Emit all queued notify signals and queue no more.

The optional do keyword argument should be the return value from freeze_notify() to avoid problems with nested functions where notifications were frozen at a higher level. If do is False, nothing will be done.

Return False if already thawed, otherwise True.

Observable.unblock(signal, do=True)

Unblock all emissions of signal.

The optional do keyword argument should be the return value from block() to avoid problems with nested functions where signals were blocked at a higher level. If do is False, nothing will be done.

Return False if already unblocked, otherwise True.

Observable.unblock_all(do=True)

Unblock all emissions of all signals.

The optional do keyword argument should be the return value from block_all() to avoid problems with nested functions where signals were blocked at a higher level. If do is False, nothing will be done.

Return False if already unblocked, otherwise True.