AccessEngine :: AEState :: Setting :: Setting :: Class Setting
[hide private]
[frames] | no frames]

Class Setting

source code

object --+
         |
        Setting

A wrapper around a value with a strict type in a AEState.AEState object. Provides a label and longer description of the value. Has a flag indicating whether the value should be persisted or not. Defines methods for caching the current value and restoring it later. Supports the observer pattern to notify listeners of changes to the value.

All instance variables should be considered public readable except for those prefixed with an underscore. The value property should also be considered public writable. value is a property which will correctly notify observers when changed.

Subclasses may define new value properties that perform conversions or do other tasks. The data retrieved via the value property must always be the data that should be persisted to disk for a setting.

Instance Methods [hide private]
 
__init__(self, state, name, default, label, description, persist)
Initializes all instance variables.
source code
 
update(self, setting)
Updates this setting with the default value and current value of another setting of the same kind.
source code
Setting
copy(self)
Makes a shallow copy of this object.
source code
object
_getValue(self)
Gets the value.
source code
 
_setValue(self, val)
Sets the value and notifies all observers only if the new value is different from the old.
source code
 
_notify(self)
Notifies all observers of a change in value.
source code
 
addObserver(self, ob, *args)
Stores a weak reference to the observer to be notified when the value of this setting changes.
source code
 
removeObserver(self, ob)
Removes a weak reference to the observer.
source code
 
clearObservers(self)
Remove all observers.
source code
 
save(self)
Caches the current value for later restoration.
source code
 
restore(self)
Restores the cached value.
source code
object
serialize(self)
Gets the current _value as the data to serialize.
source code
 
unserialize(self, val)
Sets the current _value from data that was unserialized.
source code

Inherited from object: __delattr__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __str__

Class Variables [hide private]
  value = property(_getValue, _setValue)
Instance Variables [hide private]
object _cached
Cached value from the last save invocation
dictionary _observers
Callables to notify on a value change mapped to their arguments
object _value
Arbitrary protected value of this setting.
object default
Default value of the setting
string description
Extended description of the setting
string label
Label of the setting
string name
Name of the setting
boolean persist
Should this setting value be persisted to disk?
weakref.proxy to AEState.AEState state
Object in which this setting resides
Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, state, name, default, label, description, persist)
(Constructor)

source code 
Initializes all instance variables.
Overrides: object.__init__

update(self, setting)

source code 
Updates this setting with the default value and current value of another setting of the same kind.
Parameters:
  • setting (Setting) - Setting of the same kind as this one

copy(self)

source code 
Makes a shallow copy of this object.
Returns: Setting
Shallow copy of this setting

_getValue(self)

source code 
Gets the value.
Returns: object
Current value of the setting

_setValue(self, val)

source code 
Sets the value and notifies all observers only if the new value is different from the old.
Parameters:
  • val (object) - New value to store in the setting

_notify(self)

source code 
Notifies all observers of a change in value. If an observer is dead, as indicated by a ReferenceError, removes it from the list of observers.

addObserver(self, ob, *args)

source code 

Stores a weak reference to the observer to be notified when the value of this setting changes. Bound methods will work as observers.

Additional arguments will be passed to the observer on notification. Weak reference proxies to arguments will be used whenever possible to avoid inhibiting garbage collection.
Parameters:
  • ob (callable) - The observer

Note: Because weak references are used, a reference may be dead when it is later delivered to an observer. The observer may safely ignore this error as it will be caught by the _notify method. Notification will cease immediately as soon as the first ReferenceError is encountered.

removeObserver(self, ob)

source code 
Removes a weak reference to the observer. Pass a strong reference to the observer to remove, not a weak reference.
Parameters:
  • ob (callable) - The observer
Raises:
  • KeyError - When the given callable is not an observer of this setting

save(self)

source code 
Caches the current value for later restoration. Only one value may be cached at a time. It's a box, not a stack.

restore(self)

source code 
Restores the cached value. Sends notification only if the value in the cache is different from the current value.

serialize(self)

source code 
Gets the current _value as the data to serialize. This default implementation bypasses the property fget method.
Returns: object
Data value to serialize

unserialize(self, val)

source code 
Sets the current _value from data that was unserialized. This default implementation bypasses the property fset method.
Parameters:
  • val (object) - Data value to store