Skip to content

Commit

Permalink
Initialisation of files for GUI
Browse files Browse the repository at this point in the history
  • Loading branch information
mmouchous-ledger committed Nov 10, 2023
1 parent c0d4bbf commit 44087fe
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 0 deletions.
1 change: 1 addition & 0 deletions pystages/gui/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import gui
37 changes: 37 additions & 0 deletions pystages/gui/__main__.py
Original file line number Diff line number Diff line change
@@ -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())
46 changes: 46 additions & 0 deletions pystages/gui/gui.py
Original file line number Diff line number Diff line change
@@ -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)
12 changes: 12 additions & 0 deletions pystages/gui/util.py
Original file line number Diff line number Diff line change
@@ -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:])

0 comments on commit 44087fe

Please sign in to comment.