Package AccessEngine :: Package AEState :: Module Base :: Class AEState
[hide private]
[frames] | no frames]

Class AEState

source code

object --+
         |
        AEState

Abstract base class for objects containing data that will have their data serialized to disk or configured by the user. All new* methods construct Setting objects which contain metadata describing setting values for the purpose of checking bounds, generating configuration dialogs, etc.

All subclasses of AEState should override init and getGroups. The init method should be used to create new settings and initialize non-setting instance variables. The overriden init does not need to invoke any base class init methods to create inherited settings. All baser class settings are created in the __init__ constructor instead. The getGroups method should call newGroup to create group objects containing the names of related settings to aid the generation of configuration dialogs. Group objects themselves also have newGroup methods to support nested groupings.

Two attribute names are reserved by AEState objects. settings is the dictionary containing all Setting instances. dirty is a set that stores the names of settings that have been modified in the current instance. The list is automatically reset when the instance is persisted. The isDirty, makeClean, iterDirty methods may be used to check if any part of the state is dirty, clear the list of dirty attributes, and iterate over the names and values of the dirty attributes to enable optimization at higher levels.

Note that the AEState object itself is not designed to be persisted to disk, but rather to act as a delegate for settings to be persisted. The reason for this is that not all persistence mechanisms can support the serialization of Python objects.

Instance Methods [hide private]
 
__init__(self)
Initialize the dirty set and settings dict.
source code
 
init(self)
Does nothing by default.
source code
 
getGroups(self)
Gets the root Setting.Group object and all of its child Setting names and nested groups.
source code
 
__eq__(self, other)
Compares two state objects for equality based on their attributes.
source code
 
__ne__(self, other)
Compares two state objects for inequality based on their attributes.
source code
 
copy(self)
Makes a copy of this state object and all of its Settings.
source code
 
addSetting(self, setting)
Adds a copy of an existing setting to this state object under the same name.
source code
 
newGroup(self, label=None)
Builds a new Group object relating settings.
source code
StringSetting
newString(self, name, default, label, description='', persist=True)
Adds a new StringSetting to this group.
source code
FilenameSetting
newFilename(self, name, default, label, relative_path, description='', persist=True)
Adds a new FilenameSetting to this group.
source code
BoolSetting
newBool(self, name, default, label, description='', persist=True)
Adds a new BoolSetting to this group.
source code
NumericSetting
newNumeric(self, name, default, label, min, max, precision, description='', persist=True)
Adds a new NumericSetting to this group.
source code
RangeSetting
newRange(self, name, default, label, min, max, precision, description='', persist=True)
Adds a new RangeSetting to this group.
source code
PercentRangeSetting
newPercent(self, name, default, label, min, max, precision, description='', persist=True)
Adds a new PercentRangeSetting to this group.
source code
ChoiceSetting
newChoice(self, name, default, label, choices, description='', persist=True)
Adds a new ChoiceSetting to this group.
source code
ColorSetting
newColor(self, name, default, label, description='', persist=True)
Adds a new ColorSetting to this group.
source code
EnumSetting
newEnum(self, name, default, label, choices, description='', persist=True)
Adds a new EnumSetting to this group.
source code
 
__setattr__(self, name, val)
Stores a setting value if the setting is already defined by the give name or an instance attribute if the name doesn't not define a setting.
source code
object
__getattr__(self, name)
Gets a setting value if the setting is already defined by the give name or an instance attribute if the name doesn't not define a setting.
source code
 
save(self)
Invokes Setting.Setting.save on all settings in the state.
source code
 
restore(self)
Invokes Setting.Setting.restore on all settings in the state.
source code
boolean
hasSetting(self, name)
Gets if this object has a setting with the given name.
source code
Setting
getSettingObj(self, name)
Retrieves the Setting object with the given name.
source code
object
getSettingVal(self, name)
Convenience method for getting the value of a Setting object.
source code
 
setSettingVal(self, name, val)
Convenience method for setting the value of a Setting object.
source code
dictionary
serialize(self)
Grabs all Setting values and stores them in a dictionary keyed by setting name.
source code
 
unserialize(self, data)
Stores all Setting values given a dictionary mapping setting names to values.
source code
boolean
isDirty(self)
Gets if values in settings have changed since the last call to makeClean.
source code
 
makeClean(self)
Resets the dirty set to empty.
source code
 
_makeDirty(self, state, setting)
Adds the given setting name to the dirty set.
source code
string
iterDirty(self)
Iterates over all of the names in dirty in no particular order.
source code
Setting
__iter__(self)
Iterates over all of the setting objects in settings in no particular order.
source code

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

Instance Variables [hide private]
set dirty
Set of dirty attribute names in this state object
integer ident
Unique ID for this state object which is given to all copies
dictionary settings
Dictionary of named Setting objects
Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self)
(Constructor)

source code 
Initialize the dirty set and settings dict.
Overrides: object.__init__

init(self)

source code 
Does nothing by default. Use to create settings after instantiation.

getGroups(self)

source code 
Gets the root Setting.Group object and all of its child Setting names and nested groups.
Raises:
  • NotImplementedError - When not overridden in a subclass, indicating configuration is not supported

__eq__(self, other)
(Equality operator)

source code 
Compares two state objects for equality based on their attributes.
Parameters:
  • other (AEState) - Another state object

__ne__(self, other)

source code 
Compares two state objects for inequality based on their attributes.
Parameters:
  • other (AEState) - Another state object

addSetting(self, setting)

source code 
Adds a copy of an existing setting to this state object under the same name.
Parameters:
  • setting (Setting) - Existing setting to copy and store

newGroup(self, label=None)

source code 
Builds a new Group object relating settings. The group is not stored internally, just returned for temporary use by another object.
Parameters:
  • label (string) - Label for the new Group

newString(self, name, default, label, description='', persist=True)

source code 
Adds a new StringSetting to this group.
Parameters:
  • name (string) - New name of the setting
  • default (string) - Default value of the setting
  • label (string) - Label for the new Setting
  • description (string) - Extended description of the Setting
  • persist (boolean) - Persist the setting value to disk?
Returns: StringSetting
New setting object

newFilename(self, name, default, label, relative_path, description='', persist=True)

source code 
Adds a new FilenameSetting to this group.
Parameters:
  • name (string) - New name of the setting
  • default (string) - Default value of the setting
  • label (string) - Label for the new Setting
  • relative_path (string) - Absolute path to which '.' or a filename with no path refers
  • description (string) - Extended description of the Setting
  • persist (boolean) - Persist the setting value to disk?
Returns: FilenameSetting
New setting object

newBool(self, name, default, label, description='', persist=True)

source code 
Adds a new BoolSetting to this group.
Parameters:
  • name (string) - New name of the setting
  • default (boolean) - Default value of the setting
  • label (string) - Label for the new Setting
  • description (string) - Extended description of the Setting
  • persist (boolean) - Persist the setting value to disk?
Returns: BoolSetting
New setting object

newNumeric(self, name, default, label, min, max, precision, description='', persist=True)

source code 
Adds a new NumericSetting to this group.
Parameters:
  • name (string) - New name of the setting
  • default (float) - Default value of the setting
  • label (string) - Label for the new Setting
  • min (number) - Minimum value in the range
  • max (number) - Maximum value in the range
  • precision (integer) - Number of decimal places
  • description (string) - Extended description of the Setting
  • persist (boolean) - Persist the setting value to disk?
Returns: NumericSetting
New setting object

newRange(self, name, default, label, min, max, precision, description='', persist=True)

source code 
Adds a new RangeSetting to this group.
Parameters:
  • name (string) - New name of the setting
  • default (float) - Default value of the setting
  • label (string) - Label for the new Setting
  • min (number) - Minimum value in the range
  • max (number) - Maximum value in the range
  • precision (integer) - Number of decimal places
  • description (string) - Extended description of the Setting
  • persist (boolean) - Persist the setting value to disk?
Returns: RangeSetting
New setting object

newPercent(self, name, default, label, min, max, precision, description='', persist=True)

source code 
Adds a new PercentRangeSetting to this group.
Parameters:
  • name (string) - New name of the setting
  • default (float) - Default value of the setting
  • label (string) - Label for the new Setting
  • min (number) - Minimum value in the range to be shown as 0%
  • max (number) - Maximum value in the range to be shown as 100%
  • precision (integer) - Number of decimal places
  • description (string) - Extended description of the Setting
  • persist (boolean) - Persist the setting value to disk?
Returns: PercentRangeSetting
New setting object

newChoice(self, name, default, label, choices, description='', persist=True)

source code 
Adds a new ChoiceSetting to this group.
Parameters:
  • name (string) - New name of the setting
  • default (string) - Default value of the setting
  • label (string) - Label for the new Setting
  • choices (list) - Collection of choices
  • description (string) - Extended description of the Setting
  • persist (boolean) - Persist the setting value to disk?
Returns: ChoiceSetting
New setting object

newColor(self, name, default, label, description='', persist=True)

source code 
Adds a new ColorSetting to this group.
Parameters:
  • name (string) - New name of the setting
  • default (3 or 4-tuple of integer) - Default value of the setting
  • label (string) - Label for the new Setting
  • description (string) - Extended description of the Setting
  • persist (boolean) - Persist the setting value to disk?
Returns: ColorSetting
New setting object

newEnum(self, name, default, label, choices, description='', persist=True)

source code 
Adds a new EnumSetting to this group.
Parameters:
  • name (string) - New name of the setting
  • default (integer) - Default value of the setting
  • label (string) - Label for the new Setting
  • choices (dictionary) - Collection of choices mapped to the values they represent
  • description (string) - Extended description of the Setting
  • persist (boolean) - Persist the setting value to disk?
Returns: EnumSetting
New setting object

__setattr__(self, name, val)

source code 
Stores a setting value if the setting is already defined by the give name or an instance attribute if the name doesn't not define a setting. Provided for convenience over using setSettingVal.
Parameters:
  • name (string) - Name of the setting or instance attribute
  • val (object) - Arbitrary value to store
Overrides: object.__setattr__

__getattr__(self, name)
(Qualification operator)

source code 
Gets a setting value if the setting is already defined by the give name or an instance attribute if the name doesn't not define a setting. Provided for convenience over using getSettingVal.
Parameters:
  • name (string) - Name of the setting or instance attribute
Returns: object
Arbitrary value to get
Raises:
  • AttributeError - When the name does not define a setting or instance attribute

hasSetting(self, name)

source code 
Gets if this object has a setting with the given name.
Parameters:
  • name (string) - Name of the setting
Returns: boolean
Has the setting or not?

getSettingObj(self, name)

source code 
Retrieves the Setting object with the given name.
Parameters:
  • name (string) - Name of the setting
Returns: Setting
The named setting object
Raises:
  • KeyError - When a Setting with the given name is not defined

getSettingVal(self, name)

source code 
Convenience method for getting the value of a Setting object.
Parameters:
  • name (string) - Name of the setting
Returns: object
Current value of a setting
Raises:
  • KeyError - When a Setting with the given name is not defined

setSettingVal(self, name, val)

source code 
Convenience method for setting the value of a Setting object.
Parameters:
  • name (string) - Name of the setting
  • val (object) - Value to store
Raises:
  • KeyError - When a Setting with the given name is not defined

serialize(self)

source code 
Grabs all Setting values and stores them in a dictionary keyed by setting name. Invokes restore first to ensure only user accepted values are persisted.
Returns: dictionary
Mapping from setting names to values

unserialize(self, data)

source code 
Stores all Setting values given a dictionary mapping setting names to values. Ignores names in the dictionary that do not exist in settings.
Parameters:
  • data (dictionary) - Mapping from setting names to values

isDirty(self)

source code 
Gets if values in settings have changed since the last call to makeClean.
Returns: boolean
Dirty or not?

_makeDirty(self, state, setting)

source code 
Adds the given setting name to the dirty set.
Parameters:
  • state (weakref.proxy to AEState) - State object to which the setting is attached
  • setting (Setting) - Setting that changed value

iterDirty(self)

source code 
Iterates over all of the names in dirty in no particular order.
Returns: string
Name of a dirty setting

__iter__(self)

source code 
Iterates over all of the setting objects in settings in no particular order.
Returns: Setting
A setting