Some code organisation and recovery procedure fix
This commit is contained in:
37
main.py
37
main.py
@@ -26,32 +26,31 @@ from lib.DB.AddressModel import AddressModel
|
||||
# name=""
|
||||
# type=""
|
||||
|
||||
bad_config = False
|
||||
am = None
|
||||
bm = None
|
||||
user = None
|
||||
|
||||
def initializeProgram(conf_ok):
|
||||
if conf_ok:
|
||||
global am, bad_config, bm, user
|
||||
def initializeProgram():
|
||||
# print(f"In {__file__} file, initializeProgram()")
|
||||
global am, bad_config, bm, user
|
||||
if not bad_config:
|
||||
dbconf = config.getConfig()['database']
|
||||
DbManager(dbconf)
|
||||
bad_config = False
|
||||
bm = BusinessModel()
|
||||
user = UserManager()
|
||||
am = AddressModel()
|
||||
publishContext()
|
||||
else:
|
||||
# TODO: show message and exit program
|
||||
print("Kein Zugriff auf die Datenbank")
|
||||
bad_config = False
|
||||
bm = BusinessModel()
|
||||
user = UserManager()
|
||||
am = AddressModel()
|
||||
|
||||
publishContext()
|
||||
|
||||
def publishContext():
|
||||
global engine
|
||||
# print(f"In {__file__} file, publishContext()")
|
||||
global engine, am, bad_config, bm, user
|
||||
engine.rootContext().setContextProperty("loggedin_user", user)
|
||||
engine.rootContext().setContextProperty("bm", bm)
|
||||
engine.rootContext().setContextProperty("am", am)
|
||||
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
#QResource.registerResource("rc_qml.py")
|
||||
app = QGuiApplication(sys.argv)
|
||||
@@ -59,12 +58,6 @@ if __name__ == "__main__":
|
||||
|
||||
engine.addImportPath("qrc:/");
|
||||
|
||||
|
||||
|
||||
bad_config = False
|
||||
|
||||
|
||||
|
||||
# qml_file = Path(__file__).resolve().parent / "Gui/main.qml"
|
||||
|
||||
qml_file = "qrc:/Gui/main.qml"
|
||||
@@ -72,16 +65,16 @@ if __name__ == "__main__":
|
||||
config = ConfigLoader()
|
||||
|
||||
|
||||
|
||||
if not config.getConfig():
|
||||
bad_config = True
|
||||
config.configurationReady.connect(initializeProgram)
|
||||
|
||||
else:
|
||||
initializeProgram()
|
||||
|
||||
|
||||
engine.rootContext().setContextProperty("bad_config", bad_config) # print(f"Fehler: {i}")
|
||||
engine.rootContext().setContextProperty("config", config)
|
||||
|
||||
engine.load(qml_file)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user