Config

class pathomx.config.ConfigManager(defaults={}, *args, **kwargs)[source]
add_handler(key, handler, mapper=(<function <lambda> at 0x7f5a73f6cd70>, <function <lambda> at 0x7f5a73f6cde8>))[source]

Add a handler (UI element) for a given config key.

The supplied handler should be a QWidget or QAction through which the user can change the config setting. An automatic getter, setter and change-event handler is attached which will keep the widget and config in sync. The attached handler will default to the correct value from the current config.

An optional mapper may also be provider to handler translation from the values shown in the UI and those saved/loaded from the config.

add_handlers(keyhandlers)[source]
get(key)[source]

Get config value for a given key from the config manager.

Returns the value that matches the supplied key. If the value is not set a default value will be returned as set by set_defaults.

Parameters:key (str) – The configuration key to return a config value for
Return type:Any supported (str, int, bool, list-of-supported-types)
getXMLConfig(root)[source]
remove_handler(key)[source]
replace(keyvalues, trigger_update=True)[source]

Completely reset the config with a set of key values.

Note that this does not wipe handlers or triggers (see reset), it simply replaces the values in the config entirely. It is the equivalent of unsetting all keys, followed by a set_many. Anything not in the supplied keyvalues will revert to default.

Parameters:
  • keyvalues (dict) – A dictionary of keys and values to set as defaults
  • trigger_update (bool) – Flag whether to trigger a config update (+recalculation) after all values are set.
reset()[source]

Reset the config manager to it’s initialised state.

This clears all values, unsets all defaults and removes all handlers, maps, and hooks.

set(key, value, trigger_handler=True, trigger_update=True)[source]

Set config value for a given key in the config manager.

Set key to value. The optional trigger_update determines whether event hooks will fire for this key (and so re-calculation). It is useful to suppress these when updating multiple values for example.

Parameters:
  • key (str) – The configuration key to set
  • value (Any supported (str, int, bool, list-of-supported-types)) – The value to set the configuration key to
Return type:

bool (success)

setXMLConfig(root)[source]
set_default(key, value, eventhook=1)[source]

Set the default value for a given key.

This will be returned if the value is not set in the current config. It is important to include defaults for all possible config values for backward compatibility with earlier versions of a plugin.

Parameters:
  • key (str) – The configuration key to set
  • value (Any supported (str, int, bool, list-of-supported-types)) – The value to set the configuration key to
  • eventhook (int RECALCULATE_ALL, RECALCULATE_VIEWS) – Attach either a full recalculation trigger (default), or a view-only recalculation trigger to these values.
set_defaults(keyvalues, eventhook=1)[source]

Set the default value for a set of keys.

These will be returned if the value is not set in the current config. It is important to include defaults for all possible config values for backward compatibility with earlier versions of a plugin.

Parameters:
  • keyvalues – A dictionary of keys and values to set as defaults
  • eventhook (int RECALCULATE_ALL, RECALCULATE_VIEWS) – Attach either a full recalculation trigger (default), or a view-only recalculation trigger to these values.
set_many(keyvalues, trigger_update=True)[source]

Set the value of multiple config settings simultaneously.

This postpones the triggering of the update signal until all values are set to prevent excess signals. The trigger_update option can be set to False to prevent any update at all.

Parameters:
  • keyvalues – A dictionary of keys and values to set.
  • trigger_update (bool) – Flag whether to trigger a config update (+recalculation) after all values are set.
updated
class pathomx.config.QSettingsManager(defaults={}, *args, **kwargs)[source]
reset()[source]

Reset the config manager to it’s initialised state.

This initialises QSettings, unsets all defaults and removes all handlers, maps, and hooks.

pathomx.config.build_dict_mapper(mdict)[source]

Build a map function pair for forward and reverse mapping from a specified dict

Mapping requires both a forward and reverse (get, set) mapping function. This function is used to automatically convert a supplied dict to a forward and reverse paired lambda.

Parameters:mdict (dict) – A dictionary of display values (keys) and stored values (values)
Return type:2-tuple of lambdas that perform forward and reverse map
pathomx.config.build_tuple_mapper(mlist)[source]

Build a map function pair for forward and reverse mapping from a specified list of tuples

Parameters:mlist (list-of-tuples) – A list of tuples of display values (keys) and stored values (values)
Return type:2-tuple of lambdas that perform forward and reverse map
pathomx.config.types_MethodType(fn, handler, handler_class)[source]