-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrun_app.py
More file actions
71 lines (59 loc) · 2.01 KB
/
Copy pathrun_app.py
File metadata and controls
71 lines (59 loc) · 2.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/usr/bin/env python3
from __future__ import annotations
import importlib
import sys
import traceback
from PySide6.QtWidgets import QApplication, QMessageBox
from interface.startup_splash import StartupSplash
def _load_app(result: dict[str, object]) -> None:
"""Load the application module on the Qt thread for startup tests."""
try:
result["module"] = importlib.import_module("interface.app")
except Exception as exc:
result["error"] = exc
def _show_startup_error(exc: Exception) -> None:
"""Log a startup failure and show its details before exiting."""
details = traceback.format_exc()
print(details, file=sys.stderr, end="")
try:
dialog = QMessageBox()
dialog.setIcon(QMessageBox.Critical)
dialog.setWindowTitle("DrunkenBot-IDE could not start")
dialog.setText(f"DrunkenBot-IDE could not start: {exc}")
dialog.setDetailedText(details)
dialog.exec()
except Exception as dialog_exc:
print(f"Unable to display startup error dialog: {dialog_exc}", file=sys.stderr)
def main() -> None:
app = QApplication(sys.argv)
splash = StartupSplash()
splash.show()
app.processEvents()
splash.append_log("Preparing application components...")
try:
result: dict[str, object] = {}
_load_app(result)
if "error" in result:
raise result["error"] # type: ignore[misc]
module = result["module"]
except Exception as exc:
try:
splash.append_log(f"Unable to load application: {exc}")
except Exception:
pass
_show_startup_error(exc)
return
try:
module.main(app=app, splash=splash) # type: ignore[union-attr]
except Exception as exc:
try:
splash.append_log(f"Unable to start application: {exc}")
except Exception:
pass
_show_startup_error(exc)
return
if app.property("startup_aborted"):
return
sys.exit(app.exec())
if __name__ == "__main__":
main()