Skip to main content

A package for managing application config through yaml files. Provides dynamically generated wxpython dialog.

Project description

wxconfig

A library for managing application settings stored in a yaml file. Provides a dynamically generated wxpython dialog box for enabling the user to modify settings. Supports settings metadata including setting label and help text which can be displayed in the dynamically generated dialog.

Usage

  1. Define your application settings in a yaml file:
[config.yaml]
app_function_1:
  setting_theme_1:
    setting_1: A text value
    setting_2: True
    setting_3: 22.2
  setting_theme_2:
    setting_1: A text value
    setting_2: True
    setting_3: 22.2
  1. If you require your settings dialog to contain nicely formatted labels and tooltips, define these in a separate yaml file:
[configmeta.yaml]
app_function_1:
  setting_theme_1:
    setting_1:
      __label: Setting 1
      __helptext: This is the tooltip for setting 1
    setting_2:
      __label: Setting 2
      __helptext: This is the tooltip for setting 2
  1. In your application, load your config. Also load your metadata if required:
import wxconfig as cfg

cfg.Config().load("config.yaml", meta="configmeta.yaml")
  1. You can access your applications config from anywhere in your application. Config is a singleton, and retains its state throughout the applications instance. Config values can be set and retrieved using dot notation to represent their path as defined in the config file:
import wxconfig as cfg

# Get a config value
conf_val = cfg.Config().get('app_function_1.setting_theme_1.setting_1')

# Set a congig value
cfg.Config().set('app_function_1.setting_theme_1.setting_1', 'A new text value')
  1. Any altered settings can be saved back to the config file:
import wxconfig as cfg

cfg.Config().save()
  1. Your application can open a setting dialog box that allows the user to change the applications settings. Any settings that you do not want the user to change can be excluded:
import wxconfig as cfg

# Display the dialog. Exclude all settings under setting_theme_2
settings_dialog = cfg.SettingsDialog(parent=None, exclude=['setting_theme_2'])
res = settings_dialog.ShowModal()
  1. If the user cancels the dialog, any changed settings are discarded, and the return value is wx.ID_CANCEL. If the user selects update, the settings are saved, and the return value is wx.ID_OK. All changed settings can be accessed through the setting dialogs changed_settings property, which contains a dict of settings paths and new values:
import wx
import wxconfig as cfg

# Display the dialog. Exclude all settings under setting_theme_2
settings_dialog = cfg.SettingsDialog(parent=None, exclude=['setting_theme_2'])
res = settings_dialog.ShowModal()

if res == wx.ID_OK:
    for changed_setting in settings_dialog.changed_settings:
        # Application logic to handle changed config values goes here
        # ...
        print(f"Setting {changed_setting} has changed to {settings_dialog.changed_settings[changed_setting]}")
  1. If you would like the settings dialogs position, size and style to be restored the next time the user opens it, then this can be stored in the config file. Create a config section named settings_window with the initial values. These will be changed if the user repositions or resizes the settings dialog. Keep the style value as is or change to a different wxpython window style:
[config.yaml]
settings_window:
  x: 354
  y: 299
  width: 727
  height: 419
  style: 524352

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

wxconfig-1.5.tar.gz (10.4 kB view details)

Uploaded Source

Built Distribution

wxconfig-1.5-py3-none-any.whl (10.5 kB view details)

Uploaded Python 3

File details

Details for the file wxconfig-1.5.tar.gz.

File metadata

  • Download URL: wxconfig-1.5.tar.gz
  • Upload date:
  • Size: 10.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.0 CPython/3.8.6

File hashes

Hashes for wxconfig-1.5.tar.gz
Algorithm Hash digest
SHA256 db92711b6b37dac17bf80faa4bb385b2c372c3a33dbff09d23bae81706b20882
MD5 4d29ca776fb22f96ec78f4ebd598718d
BLAKE2b-256 f59d18e6cd93cde141082c87b4415cab59241847d0f04af30fe8e5f504052989

See more details on using hashes here.

File details

Details for the file wxconfig-1.5-py3-none-any.whl.

File metadata

  • Download URL: wxconfig-1.5-py3-none-any.whl
  • Upload date:
  • Size: 10.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.0 CPython/3.8.6

File hashes

Hashes for wxconfig-1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 346d75741decd1db789c8f2e736a27dd344227852b2e9f7550c8a2da7db4da0e
MD5 8153cc6e48c53455a5d79ef3dacdfc35
BLAKE2b-256 68cfd1a05926cd3d7b72cee48963e33d6ffa768841e62a0c5c3d717cbd5db409

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page