Move config file

This commit is contained in:
CPD 2025-02-25 12:12:29 +01:00
parent 6e3678509f
commit 98f365b6af
3 changed files with 41 additions and 32 deletions

View File

@ -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)

36
app/utility/config.py Normal file
View File

@ -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()

View File

@ -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")