Configuration and User Preferences

Tools for easy persistance of configuration and user preferences for tools.

Configurations are split into sections and keys; sections are conceptually for each tool (or other grouping of settings), and keys are for individual settings within that tool/section. In the current implementation, individual sections are saved within YAML files as a mapping.

Basic usage:

# Creating the config object; give it a unique name. Slashes will be
# used directly to specify sub-directories.
config = metatools.config.Config('your_company/' + __name__)

# Use a value within the config; treat it like a dict.
dialog = setup_gui(width=config.get('width', 800))

# Save the values later.
config['width'] = dialog.width()
config.save() # Only if there were changes to the values.

Quick use:

width = metatools.config.get('your_company/' + __name__, 'width') 
metatools.config.set('your_company/' + __name__, 'width', width)
class metatools.config.Config(name)[source]

Mapping which persists to disk via YAML serialization.

Use like a dictionary.

revert()[source]

Revert to saved state.

save(force=False)[source]

Persist the current contents.

Parameters:force (bool) – Always write, even if there were no changes.
delete()[source]

Clear and delete; same as clear() and save().

update(*args, **kwargs)[source]
metatools.config.get(section, name, *args)[source]
metatools.config.set(section, name, value)[source]
metatools.config.main()[source]
Read the Docs v: latest
Versions
latest
Downloads
PDF
HTML
Epub
On Read the Docs
Project Home
Builds

Free document hosting provided by Read the Docs.