Move config file
This commit is contained in:
parent
6e3678509f
commit
98f365b6af
12
app/init.py
12
app/init.py
@ -2,8 +2,7 @@
|
|||||||
import sys
|
import sys
|
||||||
from PyQt6.QtWidgets import QApplication
|
from PyQt6.QtWidgets import QApplication
|
||||||
from .ui.main_window import MainWindow
|
from .ui.main_window import MainWindow
|
||||||
from .utils.config import AppConfig
|
from .utility.config import AppConfig
|
||||||
from cpdctrl.utility.config_file import ConfigFile
|
|
||||||
|
|
||||||
|
|
||||||
def run() -> int:
|
def run() -> int:
|
||||||
@ -15,11 +14,10 @@ def run() -> int:
|
|||||||
"""
|
"""
|
||||||
app: QApplication = QApplication(sys.argv)
|
app: QApplication = QApplication(sys.argv)
|
||||||
AppConfig.initialize()
|
AppConfig.initialize()
|
||||||
cf = ConfigFile(AppConfig.MAIN_CFG)
|
|
||||||
print(cf.values)
|
|
||||||
cf.set("key", "value")
|
|
||||||
|
|
||||||
window: MainWindow = MainWindow()
|
window: MainWindow = MainWindow()
|
||||||
window.show()
|
window.show()
|
||||||
cf.save()
|
exitcode = app.exec()
|
||||||
return sys.exit(app.exec())
|
print("Saving configuration")
|
||||||
|
AppConfig.finalize()
|
||||||
|
return sys.exit(exitcode)
|
||||||
|
36
app/utility/config.py
Normal file
36
app/utility/config.py
Normal 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()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -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")
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user