try fix
This commit is contained in:
parent
a7f76344dc
commit
aa1596cc43
28
Controll.py
28
Controll.py
@ -33,28 +33,22 @@ def main():
|
|||||||
win = MainWindow()
|
win = MainWindow()
|
||||||
|
|
||||||
# Kleine Helfer, damit die ListItem-Buttons nur Controller.start/stop aufrufen
|
# Kleine Helfer, damit die ListItem-Buttons nur Controller.start/stop aufrufen
|
||||||
def on_start(ctrl, widget, checked=False):
|
def on_start(ctrl, widget):
|
||||||
try:
|
ctrl.start()
|
||||||
ctrl.start() # darf nicht blockieren!
|
widget.set_running(True)
|
||||||
widget.set_running(True)
|
|
||||||
except Exception as e:
|
|
||||||
print("Start-Fehler:", e)
|
|
||||||
|
|
||||||
def on_stop(ctrl, widget, checked=False):
|
def on_stop(ctrl, widget):
|
||||||
try:
|
ctrl.stop()
|
||||||
ctrl.stop()
|
widget.set_running(False)
|
||||||
widget.set_running(False)
|
|
||||||
except Exception as e:
|
|
||||||
print("Stop-Fehler:", e)
|
|
||||||
|
|
||||||
# 3) Liste befüllen (auf der INSTANZ, nicht auf der Klasse!)
|
# 3) Liste befüllen (auf der INSTANZ, nicht auf der Klasse!)
|
||||||
for i, serial in enumerate(serials):
|
for i, serial in enumerate(serials):
|
||||||
ctrl = controllers[serial]
|
ctrl = controllers[serial]
|
||||||
widget = win.add_list_item(serial, i)
|
w = 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.
|
# WICHTIG: die Lambda fängt 'checked' ab (erster Parameter), wir ignorieren ihn.
|
||||||
widget.btn_start.clicked.connect(partial(on_start, ctrl, widget))
|
w.btn_start.clicked.connect(lambda checked=False, c=ctrl, ww=w: on_start(c, ww))
|
||||||
widget.btn_stop.clicked.connect(partial(on_stop, ctrl, widget))
|
w.btn_stop.clicked.connect (lambda checked=False, c=ctrl, ww=w: on_stop(c, ww))
|
||||||
|
|
||||||
|
|
||||||
# 4) Start
|
# 4) Start
|
||||||
|
|||||||
4
GUI.py
4
GUI.py
@ -27,8 +27,8 @@ class ListItemWidget(QWidget):
|
|||||||
layout.setContentsMargins(5, 2, 5, 2)
|
layout.setContentsMargins(5, 2, 5, 2)
|
||||||
|
|
||||||
def set_running(self, running: bool):
|
def set_running(self, running: bool):
|
||||||
self.btn_start.setEnabled(not running if isinstance(running, bool) else True) # robust
|
self.btn_start.setEnabled(not running)
|
||||||
self.btn_stop.setEnabled(bool(running))
|
self.btn_stop.setEnabled(running)
|
||||||
|
|
||||||
class MainWindow(QWidget):
|
class MainWindow(QWidget):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user