diff --git a/pystages/gui/gui.py b/pystages/gui/gui.py index d21e514..ac09444 100644 --- a/pystages/gui/gui.py +++ b/pystages/gui/gui.py @@ -1,5 +1,13 @@ #!/bin/python3 -from PyQt6.QtWidgets import QWidget, QHBoxLayout, QLabel, QComboBox, QPushButton +from PyQt6.QtWidgets import ( + QWidget, + QHBoxLayout, + QVBoxLayout, + QLabel, + QComboBox, + QPushButton, +) +from PyQt6.QtCore import QObject, QTimer from ..cncrouter import CNCRouter from ..corvus import Corvus from ..smc100 import SMC100 @@ -24,6 +32,11 @@ def connect(self, on_off): self.stage = Corvus() elif selected == StageType.SMC: self.stage = SMC100() + self.position_timer.start(100) + else: + del self.stage + self.stage = None + self.position_timer.stop() def __init__(self): super().__init__() @@ -31,16 +44,31 @@ def __init__(self): # Current stage self.stage: Stage = None + # This flag is used to limit the communication + # with the stage by not making updates of the position + self.in_motion = False + + vbox = QVBoxLayout() + self.setLayout(vbox) + box = QHBoxLayout() + vbox.addLayout(box) 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) + self.position_label = w = QLabel("Pos") + vbox.addWidget(w) + self.position_timer = QTimer() + self.position_timer.timeout.connect(self.update_position) + + def update_position(self): + if self.stage is None or self.in_motion: + return + position = self.stage.position + self.position_label.setText(",".join([f"{i:.02f}" for i in position.data]))