Support for reading and writing settings files in .ini format.
This can be used to provide state persistence for UI elements of a plugin.
Examples:
Initialize a new config object, modify and then save it:
>>> filepath = os.path.join(os.path.dirname(os.path.abspath(__file__)), "res", "settings.ini")
>>> defaults = UserDefaults(filepath=filepath)
>>> defaults.Set('key', 'value')
>>> defaults.Save()
If filepath points to an existing file, it will use that file and initializing a new config object by reading from it.
If you later want to read in the config file:
>>> defaults.Read()
>>> print(defaults.Get('setting'))
value
>>> print(defaults.Get('does-not-exist', default='use default instead'))
use default instead
Parameters: |
|
---|
Retrieve a previously stored value from the config object.
Parameters: |
|
---|---|
Returns: | str on success, None or default on failure. this will always return a string even if the value was stored as another type previously. So the caller is responsible for the convertion to the wanted data type. |
Retrieve a previously stored integer value from the config object.
Parameters: |
|
---|---|
Returns: | int on success, None or ‘default’ on failure. |
Retrieve a previously stored float value from the config object.
Parameters: |
|
---|---|
Returns: | float on success, None or ‘default’ on failure. |
Retrieve a previously stored boolean value from the config object.
Parameters: |
|
---|---|
Returns: | bool on success, None or ‘default’ on failure. |
Store a value in the config object for later retrieval.
Parameters: |
|
---|---|
Returns: | True if successful, False otherwise. |
Read state from configuration file.
Returns: | True if successful. |
---|---|
Raises OSError: | if config file couldn’t be read. |
Save settings to a configuration file.
Parameters: |
|
---|---|
Returns: | True if successful, False otherwise. |