apptools.preferences.i_preferences module

The interface for a node in a preferences hierarchy.

class apptools.preferences.i_preferences.IPreferences(adaptee, default=<class 'traits.adaptation.adaptation_error.AdaptationError'>)[source]

Bases: Interface

The interface for a node in a preferences hierarchy.

clear(path='')[source]

Remove all preference from the node at the specified path.

If the path is the empty string (the default) then remove the preferences in this node.

This does not affect any of the node’s children.

e.g. To clear the preferences out of a node directly:

preferences.clear()

Or to clear the preferences of a node at a given path:

preferences.clear('acme.ui')
flush()[source]

Force any changes in the node to the backing store.

This includes any changes to the node’s descendants.

get(path, default=None, inherit=False)[source]

Get the value of the preference at the specified path.

If no value exists for the path (or any part of the path does not exist) then return the default value.

Preference values are always returned as strings.

e.g:

preferences.set('acme.ui.bgcolor', 'blue')
preferences.get('acme.ui.bgcolor') -> 'blue'

preferences.set('acme.ui.width', 100)
preferences.get('acme.ui.width') -> '100'

preferences.set('acme.ui.visible', True)
preferences.get('acme.ui.visible') -> 'True'

If ‘inherit’ is True then we allow ‘inherited’ preference values.

e.g. If we are looking up:

'acme.ui.widget.bgcolor'

and it does not exist then we will also try:

'acme.ui.bgcolor'
'acme.bgcolor'
'bgcolor'

Raise a ‘ValueError’ exception if the path is the empty string.

keys(path='')[source]

Return the preference keys of the node at the specified path.

If the path is the empty string (the default) then return the preference keys of this node.

e.g:

keys = preferences.keys('acme.ui')
node(path='')[source]

Return the node at the specified path.

If the path is the empty string (the default) then return this node.

Any missing nodes are created automatically.

e.g:

node = preferences.node('acme.ui')
bgcolor = node.get('bgcolor')
node_exists(path='')[source]

Return True if the node at the specified path exists

If the path is the empty string (the default) then return True.

e.g:

exists = preferences.exists('acme.ui')
node_names(path='')[source]

Return the names of the children of the node at the specified path.

If the path is the empty string (the default) then return the names of the children of this node.

e.g:

names = preferences.node_names('acme.ui')
remove(path)[source]

Remove the preference at the specified path.

Does nothing if no value exists for the path (or any part of the path does not exist.

Raise a ‘ValueError’ exception if the path is the empty string.

e.g.:

preferences.remove('acme.ui.bgcolor')
set(path, value)[source]

Set the value of the preference at the specified path.

Any missing nodes are created automatically.

Primitive Python types can be set, but preferences are always stored and returned as strings.

e.g:

preferences.set('acme.ui.bgcolor', 'blue')
preferences.get('acme.ui.bgcolor') -> 'blue'

preferences.set('acme.ui.width', 100)
preferences.get('acme.ui.width') -> '100'

preferences.set('acme.ui.visible', True)
preferences.get('acme.ui.visible') -> 'True'

Raise a ‘ValueError’ exception if the path is the empty string.