summaryrefslogtreecommitdiff
path: root/main.py
diff options
context:
space:
mode:
Diffstat (limited to 'main.py')
-rw-r--r--main.py33
1 files changed, 31 insertions, 2 deletions
diff --git a/main.py b/main.py
index 26fcaaf..414d06f 100644
--- a/main.py
+++ b/main.py
@@ -12,10 +12,31 @@ import sys, os
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
from PyQt6.QtWidgets import QApplication
-from PyQt6.QtCore import qInstallMessageHandler, QtMsgType
+from PyQt6.QtCore import qInstallMessageHandler, QtMsgType, QEvent
from ui.main_window import MainWindow
+class LabUIApplication(QApplication):
+ """Catches the macOS "open with" launch event (QFileOpenEvent) for a
+ double-clicked .labui file — delivered via this event, not argv, and
+ can arrive before or after MainWindow exists, so it's buffered."""
+
+ def __init__(self, argv):
+ super().__init__(argv)
+ self.file_to_open: str | None = None
+ self.main_window = None
+
+ def event(self, e):
+ if e.type() == QEvent.Type.FileOpen:
+ path = e.file()
+ if self.main_window is not None:
+ self.main_window.load_profile_path(path)
+ else:
+ self.file_to_open = path
+ return True
+ return super().event(e)
+
+
def _qt_message_handler(msg_type, context, message):
"""Silence one specific, harmless Qt warning: the native windowsvista
style's combo-box/menu popup code calls QFont::setPointSize() on a
@@ -36,7 +57,7 @@ def _qt_message_handler(msg_type, context, message):
def main():
qInstallMessageHandler(_qt_message_handler)
- app = QApplication(sys.argv)
+ app = LabUIApplication(sys.argv)
app.setApplicationName("LabUI")
qss = os.path.join(os.path.dirname(os.path.abspath(__file__)), "ui", "style_dark.qss")
@@ -45,7 +66,15 @@ def main():
app.setStyleSheet(f.read())
win = MainWindow()
+ app.main_window = win
win.show()
+
+ # Opened via double-click / CLI argv (Windows, Linux) or the buffered
+ # macOS FileOpen event (see LabUIApplication.event above).
+ path = app.file_to_open or (sys.argv[1] if len(sys.argv) > 1 else None)
+ if path and path.lower().endswith(".labui") and os.path.isfile(path):
+ win.load_profile_path(path)
+
sys.exit(app.exec())