summaryrefslogtreecommitdiff
path: root/main.py
blob: 26fcaaf64d9010f68d73cff82a5e4f2d51fa0948 (plain)
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
"""
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
from ui.main_window import MainWindow


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 = QApplication(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()
    win.show()
    sys.exit(app.exec())


if __name__ == "__main__":
    main()