From e749cca30da2d02839aca736873e7e5ad45e191c Mon Sep 17 00:00:00 2001 From: Christian Kolset Date: Mon, 17 Aug 2026 10:01:59 -0600 Subject: Add .labui file association — open by double-click, cross-platform MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- main.py | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) (limited to 'main.py') 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()) -- cgit v1.2.3