try fix
This commit is contained in:
parent
a7f76344dc
commit
aa1596cc43
22
Controll.py
22
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!
|
||||
def on_start(ctrl, widget):
|
||||
ctrl.start()
|
||||
widget.set_running(True)
|
||||
except Exception as e:
|
||||
print("Start-Fehler:", e)
|
||||
|
||||
def on_stop(ctrl, widget, checked=False):
|
||||
try:
|
||||
def on_stop(ctrl, widget):
|
||||
ctrl.stop()
|
||||
widget.set_running(False)
|
||||
except Exception as e:
|
||||
print("Stop-Fehler:", e)
|
||||
|
||||
# 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
4
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):
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user