This commit is contained in:
Vincent Hanewinkel 2025-08-14 22:08:27 +02:00
parent a7f76344dc
commit aa1596cc43
2 changed files with 13 additions and 19 deletions

View File

@ -33,28 +33,22 @@ def main():
win = MainWindow()
# Kleine Helfer, damit die ListItem-Buttons nur Controller.start/stop aufrufen
def on_start(ctrl, widget, checked=False):
try:
ctrl.start() # darf nicht blockieren!
widget.set_running(True)
except Exception as e:
print("Start-Fehler:", e)
def on_start(ctrl, widget):
ctrl.start()
widget.set_running(True)
def on_stop(ctrl, widget, checked=False):
try:
ctrl.stop()
widget.set_running(False)
except Exception as e:
print("Stop-Fehler:", e)
def on_stop(ctrl, widget):
ctrl.stop()
widget.set_running(False)
# 3) Liste befüllen (auf der INSTANZ, nicht auf der Klasse!)
for i, serial in enumerate(serials):
ctrl = controllers[serial]
widget = win.add_list_item(serial, i)
# Wichtig: partial gibt eine Callback-Funktion mit fester Signatur zurück;
# PyQt darf noch ein 'checked' anhängen -> unsere Slots akzeptieren es.
widget.btn_start.clicked.connect(partial(on_start, ctrl, widget))
widget.btn_stop.clicked.connect(partial(on_stop, ctrl, widget))
w = win.add_list_item(serial, i)
# WICHTIG: die Lambda fängt 'checked' ab (erster Parameter), wir ignorieren ihn.
w.btn_start.clicked.connect(lambda checked=False, c=ctrl, ww=w: on_start(c, ww))
w.btn_stop.clicked.connect (lambda checked=False, c=ctrl, ww=w: on_stop(c, ww))
# 4) Start

4
GUI.py
View File

@ -27,8 +27,8 @@ class ListItemWidget(QWidget):
layout.setContentsMargins(5, 2, 5, 2)
def set_running(self, running: bool):
self.btn_start.setEnabled(not running if isinstance(running, bool) else True) # robust
self.btn_stop.setEnabled(bool(running))
self.btn_start.setEnabled(not running)
self.btn_stop.setEnabled(running)
class MainWindow(QWidget):
def __init__(self):