From 44087fed4628af49f0d02e65ad8e9876f644a5a6 Mon Sep 17 00:00:00 2001 From: mmouchous-ledger Date: Fri, 10 Nov 2023 10:17:40 +0100 Subject: [PATCH] Initialisation of files for GUI --- pystages/gui/__init__.py | 1 + pystages/gui/__main__.py | 37 ++++++++++++++++++++++++++++++++ pystages/gui/gui.py | 46 ++++++++++++++++++++++++++++++++++++++++ pystages/gui/util.py | 12 +++++++++++ 4 files changed, 96 insertions(+) create mode 100644 pystages/gui/__init__.py create mode 100644 pystages/gui/__main__.py create mode 100644 pystages/gui/gui.py create mode 100644 pystages/gui/util.py diff --git a/pystages/gui/__init__.py b/pystages/gui/__init__.py new file mode 100644 index 0000000..17289c7 --- /dev/null +++ b/pystages/gui/__init__.py @@ -0,0 +1 @@ +from . import gui diff --git a/pystages/gui/__main__.py b/pystages/gui/__main__.py new file mode 100644 index 0000000..b5d4ecf --- /dev/null +++ b/pystages/gui/__main__.py @@ -0,0 +1,37 @@ +from PyQt6.QtWidgets import QApplication, QStyleFactory +import sys +from PyQt6.QtGui import QIcon, QPalette, QColor +from .util import resource_path +import sys +from .gui import StageWindow + +app = QApplication(sys.argv) + +app.setApplicationName("PyStages") +app.setWindowIcon(QIcon(resource_path(":/icons/logo.png"))) +app.setStyle(QStyleFactory.create("Fusion")) +palette = QPalette() +palette.setColor(QPalette.ColorRole.Window, QColor(25, 25, 25)) +palette.setColor(QPalette.ColorRole.WindowText, QColor(240, 240, 240)) +palette.setColor(QPalette.ColorRole.Base, QColor(40, 40, 40)) +palette.setColor(QPalette.ColorRole.AlternateBase, QColor(255, 0, 0)) +palette.setColor(QPalette.ColorRole.ToolTipBase, QColor(25, 25, 25)) +palette.setColor(QPalette.ColorRole.ToolTipText, QColor(255, 255, 255)) +palette.setColor(QPalette.ColorRole.Text, QColor(200, 200, 200)) +palette.setColor(QPalette.ColorRole.Button, QColor(40, 40, 40)) +palette.setColor( + QPalette.ColorGroup.Disabled, QPalette.ColorRole.Button, QColor(30, 30, 30) +) +palette.setColor(QPalette.ColorRole.ButtonText, QColor(200, 200, 200)) +palette.setColor( + QPalette.ColorGroup.Disabled, QPalette.ColorRole.ButtonText, QColor(100, 100, 100) +) +palette.setColor(QPalette.ColorRole.BrightText, QColor(255, 0, 0)) +palette.setColor(QPalette.ColorRole.Link, QColor(255, 0, 0)) +palette.setColor(QPalette.ColorRole.Highlight, QColor(40, 120, 233)) +palette.setColor(QPalette.ColorRole.HighlightedText, QColor(255, 255, 255)) +app.setPalette(palette) + +win = StageWindow() +win.show() +sys.exit(app.exec()) diff --git a/pystages/gui/gui.py b/pystages/gui/gui.py new file mode 100644 index 0000000..1651d85 --- /dev/null +++ b/pystages/gui/gui.py @@ -0,0 +1,46 @@ +#!/bin/python3 +from PyQt6.QtWidgets import QWidget, QHBoxLayout, QLabel, QComboBox, QPushButton +from ..cncrouter import CNCRouter +from ..corvus import Corvus +from ..smc100 import SMC100 +from ..stage import Stage +from enum import StrEnum + + +class StageType(StrEnum): + CNC = "CNC" + Corvus = "Corvus" + SMC = "SMC100" + + +class StageWindow(QWidget): + def connect(self, on_off): + print(on_off, selected := self.stage_selection.currentText()) + if on_off: + # Instanciate stage according to current stage selection + if selected == StageType.CNC: + self.stage = CNCRouter() + elif selected == StageType.Corvus: + self.stage = Corvus() + elif selected == StageType.SMC: + self.stage = SMC100() + + def __init__(self): + super().__init__() + + # Current stage + self.stage: Stage = None + + box = QHBoxLayout() + w = QLabel("Stage Selection") + box.addWidget(w) + self.stage_selection = w = QComboBox() + w.addItems([StageType.CNC, StageType.Corvus, StageType.SMC]) + + box.addWidget(w) + self.setLayout(box) + + self.connect_button = w = QPushButton("Connect") + w.setCheckable(True) + w.clicked.connect(self.connect) + box.addWidget(w) diff --git a/pystages/gui/util.py b/pystages/gui/util.py new file mode 100644 index 0000000..aef8c8d --- /dev/null +++ b/pystages/gui/util.py @@ -0,0 +1,12 @@ +import os + +__dirname = os.path.dirname(os.path.realpath(__file__)) + + +def resource_path(path: str) -> str: + """ + Transforms a .":/path/to/file" path to the relative path from the main script + """ + if not path.startswith(":/"): + return path + return os.path.join(__dirname, path[2:])