neue Ordnerstruktur + GUI erweitert
This commit is contained in:
59
main.py
59
main.py
@@ -1,11 +1,9 @@
|
||||
# This Python file uses the following encoding: utf-8
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
from PySide6.QtGui import QGuiApplication
|
||||
from PySide6.QtQml import QQmlApplicationEngine
|
||||
from platformdirs import *
|
||||
import toml
|
||||
from lib.ConfigLoader import ConfigLoader
|
||||
|
||||
|
||||
# [pyqcrm]
|
||||
@@ -21,58 +19,27 @@ import toml
|
||||
# type=""
|
||||
|
||||
|
||||
class ConfigLoader:
|
||||
__config = None
|
||||
|
||||
def __init__(self):
|
||||
self.config_dir = user_config_dir() + '/pyqcrm' #user_config_dir = Funktion platformdirs
|
||||
config_dir = Path(self.config_dir)
|
||||
|
||||
config_dir.mkdir(0o027, True, True)
|
||||
self.__configLoad()
|
||||
|
||||
def __configLoad(self):
|
||||
|
||||
try:
|
||||
with open (self.config_dir + '/pyqcrm.toml', 'r') as f:
|
||||
self.__config = toml.load(f)
|
||||
except FileNotFoundError:
|
||||
print("Konnte die Konfiguration nicht laden.")
|
||||
|
||||
|
||||
def getConfig(self):
|
||||
|
||||
return self.__config
|
||||
|
||||
def createConfig(self):
|
||||
|
||||
with open(self.config_dir + '/pyqcrm.toml', "w") as datei:
|
||||
datei.write("[pyqcrm]")
|
||||
|
||||
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
app = QGuiApplication(sys.argv)
|
||||
engine = QQmlApplicationEngine()
|
||||
|
||||
# qml_file = Path(__file__).resolve().parent / "main.qml"
|
||||
# engine.load(qml_file)
|
||||
|
||||
config = ConfigLoader()
|
||||
|
||||
|
||||
if config.getConfig():
|
||||
try:
|
||||
print (config.getConfig()['database']['server'])
|
||||
qml_file = Path(__file__).resolve().parent / "main.qml"
|
||||
engine.load(qml_file)
|
||||
except:
|
||||
print("Ausnahme")
|
||||
qml_file = Path(__file__).resolve().parent / "Programmeinstellungen.qml"
|
||||
engine.load(qml_file)
|
||||
else:
|
||||
config.createConfig()
|
||||
# if config.getConfig():
|
||||
try:
|
||||
print (config.getConfig()['database']['server'])
|
||||
qml_file = Path(__file__).resolve().parent / "gui/main.qml"
|
||||
engine.load(qml_file)
|
||||
except:
|
||||
print("Ausnahme")
|
||||
qml_file = Path(__file__).resolve().parent / "gui/Programmeinstellungen.qml"
|
||||
engine.rootContext().setContextProperty("config", config)
|
||||
engine.load(qml_file)
|
||||
# else:
|
||||
# config.createConfig()
|
||||
|
||||
if not engine.rootObjects():
|
||||
sys.exit(-1)
|
||||
|
||||
Reference in New Issue
Block a user