A class for managing user preferences.
Preferences are stored in a platform-specific storage area. Under
UNIX, this will be a ~/.<classname> file. On the Macintosh, the
file will be written to the Preferences folder. On win32 systems,
the values will be stored in the registry.
Members:
- allowedValues
The allowedValues class attribute is a
dictionary defining the preferences managed. The keys of the
dictionary should be the names of the preference values. The
values should be tuples of the form (type name, default value,
comment). Type name can be any value which appears as a key
in the converters dictionary (see below). The default value
should be of the correct time. The comment should be a string
which will help the user make sense of the value when it is
written out to the storage area.
- storeOnChange
The storeOnChange instance attribute is a boolean flag
indicating whether or not all preference values should be
written to the storage area each time any value is modified.
- converters
Listed in the class attribute converters
should be a mapping of a type name to a conversion function.
The conversion function should take one parameter and should
attempt to conver that value to the named type. If the value
cannot be converted to the specified type, a ValueError
should be raised to prevent the input value from being stored.
If the value can be converted, the converted value should be
returned.
- enumValues
The enumValues dictionary is keyed on value
names. Associated with the name of the value should be a
sequence of allowed enumeration items.
Methods
|
|
|
|
__init__
|
__init__ ( self )
|
|
__setitem__
|
__setitem__ (
self,
item,
value,
)
|
|
convert_on_read
|
convert_on_read (
self,
item,
value,
)
Exceptions
|
|
ValueError( 'Unknown preference %s' % item )
ValueError('Could not convert "%s" to a %s for %s' %( value, prefType, item ), str( msg ) )
|
|
|
getPrefsStorageName
|
getPrefsStorageName ( self )
Returns the name of the storage for the preferences.
The location might be a filename or self.REGISTRY .
|
|
initializeDefaults
|
initializeDefaults ( self )
Initialize internal default values.
Initialize our default values as though they were written
in the storage area.
|
|
keys
|
keys ( self )
Returns a sequence of names of the preference values.
We override this so that we can control the order of
the values in other places, but so that users of
the class can treat us as a dictionary.
|
|
readConverter_boolean
|
readConverter_boolean (
self,
name,
value,
)
|
|
readConverter_color
|
readConverter_color (
self,
name,
value,
)
|
|
readConverter_enum
|
readConverter_enum (
self,
name,
value,
)
|
|
readConverter_float
|
readConverter_float (
self,
name,
value,
)
|
|
readConverter_font
|
readConverter_font (
self,
name,
value,
)
|
|
readConverter_integer
|
readConverter_integer (
self,
name,
value,
)
|
|
readConverter_password
|
readConverter_password (
self,
name,
value,
)
|
|
readConverter_string
|
readConverter_string (
self,
name,
value,
)
|
|
readConverter_text
|
readConverter_text (
self,
name,
value,
)
|
|
readValuesFromStorage
|
readValuesFromStorage ( self )
|
|
readValuesFromStorage_File
|
readValuesFromStorage_File ( self )
Exceptions
|
|
ValueError( 'Unknown preference value found in %s' % self._prefs_storage_name, var, val )
ValueError('Could not parse line "%s" in %s.' %( line, self._prefs_storage_name ) )
|
|
|
readValuesFromStorage_Registry
|
readValuesFromStorage_Registry ( self )
|
|
storageConverter_boolean
|
storageConverter_boolean (
self,
name,
value,
)
|
|
storageConverter_color
|
storageConverter_color (
self,
name,
value,
)
|
|
storageConverter_enum
|
storageConverter_enum (
self,
name,
value,
)
|
|
storageConverter_float
|
storageConverter_float (
self,
name,
value,
)
|
|
storageConverter_font
|
storageConverter_font (
self,
name,
value,
)
|
|
storageConverter_integer
|
storageConverter_integer (
self,
name,
value,
)
Define basic converters
|
|
storageConverter_password
|
storageConverter_password (
self,
name,
value,
)
|
|
storageConverter_string
|
storageConverter_string (
self,
name,
value,
)
|
|
storageConverter_text
|
storageConverter_text (
self,
name,
value,
)
|
|
valueToBoolean
|
valueToBoolean (
self,
name,
value,
)
|
|
valueToEnum
|
valueToEnum (
self,
name,
value,
)
Exceptions
|
|
ValueError( 'No enumerations defined for %s' % name )
ValueError('Enum value %s must be one of %s' %(value, str( values ) ) )
|
|
|
writeValuesToStorage
|
writeValuesToStorage ( self, value_names=() )
|
|
writeValuesToStorage_File
|
writeValuesToStorage_File ( self, value_names )
|
|
writeValuesToStorage_Registry
|
writeValuesToStorage_Registry ( self, value_names )
|
|