orrery.models.IndirectDependentModel#

class IndirectDependentModel(parent_model=None, model_name=None)[source]#

Bases: Model

A model which reflects the value of a child model

Methods

add_invalidated_listener

Add an observer to listen to notifications that this model has become invalid

add_observer

Add an observer to receive notifications for the specified event

add_value_changed_listener

Add an observer to listen for changes to this model's value'

compare

Return True if the model value is equal to the specified value

from_yaml

Set the model value using the value reprentation returned from the YAML parser

has_value

Return True if the model has a valid value (not None)

initialise

Set model to its default state

initialised

Return True if the model value has been set (even if set to None)

notify

Trigger a callback on all observers for this event

remove_invalidated_listener

Remove a previously added observer for invalidated events

remove_observer

Remove existing observer for the specified event

remove_value_changed_listener

Remove a previously added observer for value changed events

to_yaml

Return a representation of the model value suitable for storing in YAML

Attributes

EVENT_INVALIDATED

EVENT_VALUE_CHANGED

value

Return value of model

class NotInitialised#

Bases: object

Special class for indicating a value should be non-initialised

class ObserverList#

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)#

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)#

Trigger a callback on all observers which are still in existence

remove_observer(callback_id)#

Remove an observer previously added with add_observer()

Parameters:

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

add_invalidated_listener(callback, **kwargs)#

Add an observer to listen to notifications that this model has become invalid

add_observer(event, callback, **kwargs)#

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

add_value_changed_listener(callback, **kwargs)#

Add an observer to listen for changes to this model’s value’

compare(value)#

Return True if the model value is equal to the specified value

Return type:

bool

from_yaml(value)#

Set the model value using the value reprentation returned from the YAML parser

has_value()#

Return True if the model has a valid value (not None)

Return type:

bool

initialise(error_if_already_initialised=True)[source]#

Set model to its default state

initialised()[source]#

Return True if the model value has been set (even if set to None)

Return type:

bool

notify(event, **event_args)#

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_invalidated_listener(callback_id)#

Remove a previously added observer for invalidated events

remove_observer(event, callback_id)#

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

remove_value_changed_listener(callback_id)#

Remove a previously added observer for value changed events

to_yaml()#

Return a representation of the model value suitable for storing in YAML

property value#

Return value of model