From aa1596cc4310ad112a270a4f6a4b4290a5c79f5b Mon Sep 17 00:00:00 2001 From: Vincent Hanewinkel Date: Thu, 14 Aug 2025 22:08:27 +0200 Subject: [PATCH] try fix --- Controll.py | 28 +++++++++++----------------- GUI.py | 4 ++-- 2 files changed, 13 insertions(+), 19 deletions(-) diff --git a/Controll.py b/Controll.py index dc1b64f..844a260 100644 --- a/Controll.py +++ b/Controll.py @@ -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 diff --git a/GUI.py b/GUI.py index c0d0883..ec2e3c7 100644 --- a/GUI.py +++ b/GUI.py @@ -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):