67
main.py
67
main.py
@@ -4,76 +4,13 @@ from pathlib import Path
|
||||
|
||||
from PySide6.QtGui import QGuiApplication
|
||||
from PySide6.QtQml import QQmlApplicationEngine
|
||||
from platformdirs import *
|
||||
import toml
|
||||
|
||||
|
||||
# [pyqcrm]
|
||||
# program-name=""
|
||||
# version=
|
||||
|
||||
# [database]
|
||||
# server=""
|
||||
# port=
|
||||
# user=""
|
||||
# password=""
|
||||
# name=""
|
||||
# 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()
|
||||
|
||||
qml_file = Path(__file__).resolve().parent / "main.qml"
|
||||
engine.load(qml_file)
|
||||
if not engine.rootObjects():
|
||||
sys.exit(-1)
|
||||
sys.exit(app.exec())
|
||||
|
||||
Reference in New Issue
Block a user