orrery.observable.Observable#

class Observable[source]#

Bases: object

Base class for objects which can send notifications to observers.

Maintains a dictionary of event types to ObserverList objects

Methods

add_observer

Add an observer to receive notifications for the specified event

notify

Trigger a callback on all observers for this event

remove_observer

Remove existing observer for the specified event

class ObserverList[source]#

Bases: object

Class for managing observers and sending notifications for events

Makes special use of WeakKeyDictionary and WeakMethod so that the Observable won’t prevent observers from being destroyed, and if an observer is destroyed it will automatically be removed from the observers

class CallbackArgs(callback, kwargs)#

Bases: tuple

Create new instance of CallbackArgs(callback, kwargs)

__add__(value, /)#

Return self+value.

__mul__(value, /)#

Return self*value.

callback#

Alias for field number 0

count(value, /)#

Return number of occurrences of value.

index(value, start=0, stop=9223372036854775807, /)#

Return first index of value.

Raises ValueError if the value is not present.

kwargs#

Alias for field number 1

add_observer(callback, **kwargs)[source]#

Add an observer to receive notification events

Parameters:
  • callback – bound method which will receive the callbacks

  • kwargs – additional arguments which will be passed to the callback

notify(**event_args)[source]#

Trigger a callback on all observers which are still in existence

remove_observer(callback_id)[source]#

Remove an observer previously added with add_observer()

Parameters:

callback_id – the callback id returned by the add_observer() call

add_observer(event, callback, **kwargs)[source]#

Add an observer to receive notifications for the specified event

Parameters:
  • event – describes a unique event generated by this object

  • callback – bound method which will receive the callbacks

  • kwargs – additional arguments to be passed to the callbacks - these are added to the arguments passed in through the call to notify()

Returns:

An id which can be used to remove the callback if necessary

notify(event, **event_args)[source]#

Trigger a callback on all observers for this event

Parameters:
  • event – describes a unique event generated by this object

  • event_args – named arguments to be passed to pass to callbacks

remove_observer(event, callback_id)[source]#

Remove existing observer for the specified event

Parameters:
  • event – describes a unique event generated by this object

  • callback_id – the identifier passed when the observer was added