diff --git a/Controll.py b/Controll.py index 66deb57..88a818c 100644 --- a/Controll.py +++ b/Controll.py @@ -12,24 +12,6 @@ class ControllerSignals(QObject): signals = ControllerSignals() -def make_on_start(ctrl, widget): - def _start(checked=False): - try: - ctrl.start() # startet Worker-Threads, blockiert nicht - widget.set_running(True) - except Exception as e: - print(f"Fehler beim Start {ctrl.dev.serial}: {e}") - return _start - -def make_on_stop(ctrl, widget): - def _stop(checked=False): - try: - ctrl.stop() - widget.set_running(False) - except Exception as e: - print(f"Fehler beim Stop {ctrl.dev.serial}: {e}") - return _stop - def main(): # 1) Geräte einsammeln (pysmu nur hier benutzen) sess = pysmu.Session() @@ -50,11 +32,23 @@ def main(): win = MainWindow() # Kleine Helfer, damit die ListItem-Buttons nur Controller.start/stop aufrufen - def make_on_start(ctrl): - return lambda _idx: ctrl.start() + def make_on_start(ctrl, widget): + def _start(checked=False): + try: + ctrl.start() # startet Worker-Threads, blockiert nicht + widget.set_running(True) + except Exception as e: + print(f"Fehler beim Start {ctrl.dev.serial}: {e}") + return _start - def make_on_stop(ctrl): - return lambda _idx: ctrl.stop() + def make_on_stop(ctrl, widget): + def _stop(checked=False): + try: + ctrl.stop() + widget.set_running(False) + except Exception as e: + print(f"Fehler beim Stop {ctrl.dev.serial}: {e}") + return _stop # 3) Liste befüllen (auf der INSTANZ, nicht auf der Klasse!) for i, serial in enumerate(serials): @@ -63,10 +57,10 @@ def main(): widget = win.add_list_item( text=serial, index=i, - on_start=make_on_start(ctrl, placeholder), # placeholder siehe unten - on_stop=make_on_stop(ctrl, placeholder), + on_start = make_on_start(ctrl, placeholder), # placeholder siehe unten + on_stop = make_on_stop(ctrl, placeholder), ) - + widget.btn_start.clicked.disconnect() widget.btn_stop.clicked.disconnect() widget.btn_start.clicked.connect(make_on_start(ctrl, widget))