""" main.py — LabUI entry point. Run: python main.py Requirements: pip install PyQt6 pyqtgraph numpy pyserial """ 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, 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 pixel-sized font (our QSS uses px font-size, so pointSize() is -1 by design) — cosmetic console noise only, doesn't affect rendering. Everything else still prints normally.""" if "QFont::setPointSize" in message: return if msg_type == QtMsgType.QtWarningMsg: print(f"Warning: {message}", file=sys.stderr) elif msg_type == QtMsgType.QtCriticalMsg: print(f"Critical: {message}", file=sys.stderr) elif msg_type == QtMsgType.QtFatalMsg: print(f"Fatal: {message}", file=sys.stderr) else: print(message, file=sys.stderr) def main(): qInstallMessageHandler(_qt_message_handler) app = LabUIApplication(sys.argv) app.setApplicationName("LabUI") qss = os.path.join(os.path.dirname(os.path.abspath(__file__)), "ui", "style_dark.qss") if os.path.exists(qss): with open(qss) as f: 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()) if __name__ == "__main__": main()