diff --git a/app/init.py b/app/init.py index 19714fd..12d6b66 100644 --- a/app/init.py +++ b/app/init.py @@ -2,8 +2,7 @@ import sys from PyQt6.QtWidgets import QApplication from .ui.main_window import MainWindow -from .utils.config import AppConfig -from cpdctrl.utility.config_file import ConfigFile +from .utility.config import AppConfig def run() -> int: @@ -15,11 +14,10 @@ def run() -> int: """ app: QApplication = QApplication(sys.argv) AppConfig.initialize() - cf = ConfigFile(AppConfig.MAIN_CFG) - print(cf.values) - cf.set("key", "value") window: MainWindow = MainWindow() window.show() - cf.save() - return sys.exit(app.exec()) + exitcode = app.exec() + print("Saving configuration") + AppConfig.finalize() + return sys.exit(exitcode) diff --git a/app/utility/config.py b/app/utility/config.py new file mode 100644 index 0000000..ec83f60 --- /dev/null +++ b/app/utility/config.py @@ -0,0 +1,36 @@ +from os import path, environ +from cpdctrl.utility.config_file import ConfigFile + + + +class AppConfig: + """ + Configuration File + """ + APP_NAME: str = "cpdctrl-gui" + CONFIG_DIR: str = path.expanduser("~/.config/cpdctrl") + MAIN_CFG: ConfigFile = None + @classmethod + def initialize(cls) -> None: + """ + Perform any necessary initializations here, e.g.: + - Loading settings from a file + """ + if 'XDG_CONFIG_HOME' in environ.keys(): + AppConfig.CONFIG_DIR = path.join(environ["XDG_CONFIG_HOME"], "cpdctrl") + AppConfig.MAIN_CFG_PATH = path.join(AppConfig.CONFIG_DIR, "cpdctrl-gui.yaml") + AppConfig.MAIN_CFG = ConfigFile(AppConfig.MAIN_CFG_PATH, { + "voltage_measurement_device_auto_reconnect": True, + "led_device_auto_reconnect": True, + "datadir": "~/data2", + }) + @classmethod + def finalize(cls) -> None: + """ + Write configuration to file + """ + AppConfig.MAIN_CFG.save() + + + + diff --git a/app/utils/config.py b/app/utils/config.py deleted file mode 100644 index eb628b0..0000000 --- a/app/utils/config.py +++ /dev/null @@ -1,25 +0,0 @@ -''' app/utils/config.py ''' - -from os import path, environ - - -class AppConfig: - """ - Configuration File - """ - APP_NAME: str = "cpdctrl-gui" - CONFIG_DIR: str = path.expanduser("~/.config/cpdctrl") - MAIN_CFG: str = "" - @classmethod - def initialize(cls) -> None: - """ - Perform any necessary initializations here, e.g.: - - Loading settings from a file - """ - if 'XDG_CONFIG_HOME' in environ.keys(): - AppConfig.CONFIG_DIR = path.join(environ["XDG_CONFIG_HOME"], "cpdctrl") - AppConfig.MAIN_CFG = path.join(AppConfig.CONFIG_DIR, "cpdctrl-gui.yaml") - - - -