forked from pnikrou/FIMsim
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
64 lines (52 loc) · 2.17 KB
/
Copy pathmain.py
File metadata and controls
64 lines (52 loc) · 2.17 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
"""Entry point for the Flood Model Preprocessing Tool (5-mode)."""
import sys
import os
# On Windows, add conda env's Library\bin to the DLL search path so that
# GDAL, PROJ, and other native libraries are found before any system copies.
if sys.platform == "win32":
_conda_bin = os.path.join(os.path.dirname(sys.executable), "Library", "bin")
if os.path.isdir(_conda_bin):
os.add_dll_directory(_conda_bin)
# Configure matplotlib for Qt6 BEFORE any figure is created.
# NenCarta (the ARC-Curve2Flood backend) depends on PyQt5, so both bindings are
# present in this environment. Pin matplotlib to PyQt6 so it can never bind to
# PyQt5 and break every preview canvas in the app.
import os as _os
_os.environ.setdefault("QT_API", "pyqt6")
import matplotlib
matplotlib.use("QtAgg")
from PyQt6.QtWidgets import QApplication
from PyQt6.QtCore import Qt
from gui.app import MainWindow
def main():
# Global exception hook: PyQt6 calls qFatal() (a hard abort — the macOS
# "python quit unexpectedly" dialog) when a Python exception escapes a Qt
# slot while sys.excepthook is still the default. Install our own hook so
# any such bug prints a traceback and appears in the log panel instead of
# killing the whole application.
import traceback
def _excepthook(exc_type, exc_value, exc_tb):
text = "".join(traceback.format_exception(exc_type, exc_value, exc_tb))
sys.stderr.write(text)
win = getattr(_excepthook, "window", None)
if win is not None:
try:
win._append_log("UNEXPECTED ERROR (work continues; please report):")
for line in text.rstrip().splitlines():
win._append_log(f" {line}")
except Exception:
pass
sys.excepthook = _excepthook
# High-DPI support
QApplication.setHighDpiScaleFactorRoundingPolicy(
Qt.HighDpiScaleFactorRoundingPolicy.PassThrough
)
app = QApplication(sys.argv)
app.setApplicationName("Flood Model Prep Tool")
app.setOrganizationName("YourLab")
window = MainWindow()
_excepthook.window = window
window.show()
sys.exit(app.exec())
if __name__ == "__main__":
main()