diff options
| author | Christian Kolset <ckolset@colostate.edu> | 2026-08-17 10:01:59 -0600 |
|---|---|---|
| committer | Christian Kolset <ckolset@colostate.edu> | 2026-08-17 10:01:59 -0600 |
| commit | e749cca30da2d02839aca736873e7e5ad45e191c (patch) | |
| tree | ca57d9ce2ff6a6f33193a59216be17b3b159c1af /main.py | |
| parent | 34c12b2b5b280206890cd03153b1c95116acc85e (diff) | |
Add .labui file association — open by double-click, cross-platform
Windows/Linux self-register via core/file_association.py (winreg /
XDG .desktop+mime), triggered from a new Settings button since there's
no installer to do it at install time. macOS gets it at build time via
labui.spec's new BUNDLE() step (CFBundleDocumentTypes in Info.plist) —
that step also makes mac builds a real .app bundle for the first time,
not just a bare onedir folder. main.py gains a LabUIApplication
subclass to catch the macOS QFileOpenEvent (buffered if it arrives
before MainWindow exists) plus argv[1] handling for Windows/Linux.
ProfileButton.load_path() extracted so both paths share the same
load-and-apply logic as the existing file-dialog flow.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Diffstat (limited to 'main.py')
| -rw-r--r-- | main.py | 33 |
1 files changed, 31 insertions, 2 deletions
@@ -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()) |
