orrery.models.ClassModel#
- class ClassModel(value=<orrery.models.Model.NotInitialised object>, default=None)[source]#
Bases:
ValueModel
A model wrapping an instance. No copy will be made when getting or setting the value; the value refers to the original object. This is intended for storing a runtime instance of a class and is not intended to be serialisable
Methods
Add an observer to listen to notifications that this model has become invalid
Add an observer to receive notifications for the specified event
Add an observer to listen for changes to this model's value'
Return True if the model value is equal to the specified value
Set the model value using the value reprentation returned from the YAML parser
Return True if the model has a valid value (not None)
Set model to its default state
Return True if the model value has been set (even if set to None)
Trigger a callback on all observers for this event
Remove a previously added observer for invalidated events
Remove existing observer for the specified event
Remove a previously added observer for value changed events
Return a representation of the model value suitable for storing in YAML
Attributes
EVENT_INVALIDATED
EVENT_VALUE_CHANGED
Return value of model
- 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’
- from_yaml(value)[source]#
Set the model value using the value reprentation returned from the YAML parser
- initialise(error_if_already_initialised=True)#
Set model to its default state
- 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
- property value#
Return value of model