package#
the contents of the configwidgets package.
concept#
All widgets are build with the same concept:
subclass a QtWidget. The default behaviour is the same.
define a setup method.
This assigns a
QSettingsinstance,and a key, where the data is stored.
a default value is used when the key doesnt exists.
the
load_value()method load the value from the QSettings instance into the widget state.setup()calls this method.the
collect()method saves the current widget state into the QSettings instance. The method is connected to the “state changed” signal (i.e.editingFinished,toggled)the
set_value()method sets the parameter to state and QSettings.
The “only” change is the type of the value and the state-change signal.
show case#
The following ConfigCheckBox provides an example, the other classes are defined alike:
- class configwidgets.ConfigCheckBox(*args, **kwargs)
A subclass of
QCheckBox. Can be setup with a link to QSettings instance to maintain state between program restarts.- __init__(*args, **kwargs)
Initialize a ConfigCheckBox. Other than declaring default values as None the super constructor is called.
- Parameters:
text (str) – The text of the checkbox.
parent (QWidget, optional) – The parent widget of the checkbox. The default is None.
- setup(config: QSettings, name: str, default: bool = False)
Setup the link to a
QSettingsinstance for this checkbox.- Parameters:
config (QSettings) – The QSettings instance, that shall be connected.
name (str) – The QSettings key to store the synced value.
default (bool, optional) – The default value. The default is False.
- set_name(name: str)
set the QSetting-Key for this checkbox.
- set_default(default: bool)
set the default value for retrieving the value.
- load_value() bool
load the state from the QSettings instance to the widget state. If the key is not defined, the
defaultis used instead.- Raises:
ConfigNotSetupError – Raises an Error if the setup function wasnt called.
- set_value(val: bool) bool
set a value to the widget state and the QSettings Instance.
- Raises:
ConfigNotSetupError – Raises an Error if the setup function wasnt called.
- collect() bool
collect the widget state and store in QSettings Instance. Gets connected to the
toggled()signal.- Raises:
ConfigNotSetupError – Raises an Error if the setup function wasnt called.