Skip to main content

QConfig

QConfig is a useful tool for PyQt GUI developers, as it makes it easier to save and load the state of the GUI through configuration files. This tool simplifies the process of preserving the current state of the GUI, and provides a range of helpful methods for managing configuration, making it a convenient and efficient solution.

How to install

QConfig is available on pypi and can be installed via pip.

pip install qtconfig

Introduction

The concept behind the package is a QConfig container that takes responsibility for a dictionary of data. Each key in the dictionary gets a Hook assigned, which maps the value to its widget.

For datasets with keys that do not match the widget names, a QConfigDynamicLoader can be created, mapping each value to its widget, and then passed to the QConfig constructor. It is also able to receive a list of keys instead and look for the closest matching widget name.

Features

  • Load all the values a QConfig is responsible for from their hooked widgets
  • Populate all the widgets with the values a QConfigs' data holds
  • Add callbacks to the widgets a QConfig holds
  • Remove specific / all callbacks a QConfig holds
  • Trigger a "save on change" for all widgets a QConfig holds
  • Dynamically map config keys to non matching widget object names
  • Suppress expected errors while trying to build QConfigDynamicLoader or QConfig
  • Load or read datasets recursively to allow for nested configs
  • Convert str from config into QDate objects

Why should you use it?

Preserving the state of a GUI in files such as json, yaml or xml yourself can be tedious and results in a lot of boilerplate code. Each widget needs to be connected to the data that holds its value and vice versa, you need to add callbacks to all widgets to invoke a save (unless you want to use a save button or timer) and it takes alot of time, increases the amount of code and increases the risk of getting something wrong. QConfig uses a more sophisticated method of handling the configs for you and allows you to focus on your GUI design rather than worrying about preserving its state.

Usage

QConfig is very lightweight and intuitive to use, more-so when the configs keys already match the widget names.

With matching key - widget pairs

The most straightforward way to use QConfig is to ensure that your configuration keys match the widget names in your GUI. Assuming we have the following structure:

user_data: dict[str, Any] = {"user_name": "Jake", "age": 18, "of_age": True, "IQ": 10}
widgets: list[QWidget] = [user_name_widget, age_widget, of_age_checkbox, iq_spinbox]

Assuming that each widget.objectName() matches the key it is hooked to in the configs, you can create a QConfig just like this:

user_data_qconfig = QConfig(user_data, widgets, recursive=False)

With QConfigDynamicLoader

The QConfigDynamicLoader allows you to dynamically hook a dataset to the widgets even if the keys dont match, by guiding the loader to the widget to search for. Taking the above example:

user_data: dict[str, any] = {"user_name": "Jake", "age": 18, "of_age": True, "IQ": 10}
widgets: list[QWidget] = [user_name_widget, age_widget, of_age_checkbox, iq_spinbox]

Assuming the objectName() properties of user_name_widget and age_widget were actually "user" and "age" instead, we could create a QConfigDynamicLoader to account for this:

loader = QConfigDynamicLoader({"user_name": "user", "age_widget": "age"}, show_build=True)
user_data_qconfig = QConfig(user_data, widgets, loader, recursive=False)

A QConfigDynamicLoader is also able to automatically complement keys by close matches, either keys missing in the data or passed as a list. If part of your keys already match with the widget names, they do not need to be added to the loader, the QConfig will find them before accessing the loader.

Features

Upon initialisation, it will build hooks that connect each key to its respective widget. Now we can use the qconfig object to...

...populate the hooked widgets with the values in the data

user_data_qconfig.load_data()

...save the values in the widgets in its key in the data

user_data_qconfig.get_data()

...connect callback methods to each widget's change event. With this method when a value in a widget is changed, all the settings will be written to the data right upon change

user_data_qconfig.connect_callback(user_data_qconfig.save_data)

...disconnect the callbacks, remove a specified callback by passing one, otherwise all callbacks are disconnected

user_data_qconfig.disconnect_callback(exclude=["user_name"])

Metadata

Release files for qtconfig 0.0.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for qtconfig 0.0.5
File Size Uploaded
qtconfig-0.0.5.tar.gz 16.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for qtconfig 0.0.5
File Interpreter ABI Platform
qtconfig-0.0.5-py3-none-any.whl Python 3 none any Details

Total release size: 31.0 kB

Release files / qtconfig-0.0.5.tar.gz

Download URL qtconfig-0.0.5.tar.gz
Size 16.2 kB
Tags Source
SHA-256 checksum
How to use checksums
2c55b77df1ea9438716caae92b82c537e33044d9bc0df162392bc05df3b1ad8c
BLAKE2b-256 checksum
How to use checksums
5b5f6e066a5f8d378afb748674834d105e1082128a3b1da747e5db2a3831fe83
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.2

Release files / qtconfig-0.0.5-py3-none-any.whl

Download URL qtconfig-0.0.5-py3-none-any.whl
Size 14.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d25691246d59b74b2299d4f9eb1641a410af923ab0c15fdacabed8f24363d7f7
BLAKE2b-256 checksum
How to use checksums
b0dcbb3bec71d248fcef146eed852cfd2846e7ec08930775091d6946c9ce379b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.2

Release history Release notifications | RSS feed

This release

0.0.5 This release

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page