feat: replace modal user-confirm dialog with persistent flashing button
Both clients used a modal OK dialog for a Sud step's WAIT_USER confirmation (e.g. "Bitte Malz einfuellen und bestaetigen"). Replaced with a persistent "Confirm" control in the top toolbar/header instead: flashes yellow with the step's message while pending, and modally disables the rest of the GUI (main content plus Start/Pause/Stop/ New/Save/Load, and Connect) until it's clicked - forcing the pending step to be dealt with first. Disabled and blank otherwise. client/brewpi_gui.py: set_user_confirm_pending() drives a QTimer blink (same pattern as the existing "Cool down" indicator) and disables centralwidget + the relevant toolbar QActions individually, so the new button (a toolbar sibling) stays enabled; Start/Pause/Stop are restored via update_sud_actions() rather than a blanket re-enable. web/app.js: setUserConfirmPending() toggles a 'confirm-pending' class (CSS @keyframes flash, matching the file's existing animation-by-class convention) and a 'modally-disabled' class on #layout; also wired into ws.onclose so a dropped connection doesn't leave the page stuck modally disabled on a confirm that'll never resolve. Also fixes a message-ordering race in both clients (found testing the web version on an iPad, connecting fresh while a step was already WAIT_USER): a step's UserMessage is set once when the step starts, well before State later flips to WAIT_USER, so an already-connected client sees them at genuinely different times - but a client connecting fresh gets both bundled into one replayed snapshot, where State's key can sort before UserMessage's. Processing State first checked the pending guard before that same message had set the text, silently failing it and leaving the button looking merely disabled. Both onSudChanged()/ on_sud_changed() now force UserMessage (and, in the web client, Json) to process before State/Step regardless of the bundled dict's key order, same pattern already used for the pre-existing Json-before-Step case. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01M2ierBoxW3v7nUbDw3M2pE
This commit is contained in:
+77
-21
@@ -422,7 +422,7 @@ class Window(QtWidgets.QMainWindow, Ui_MainWindow):
|
||||
self.sud_empty = True
|
||||
self.sud_state = None
|
||||
self.sud_user_message = None
|
||||
self._confirm_box = None
|
||||
self.user_confirm_pending = False
|
||||
# Global, not Sud-specific - from the 'System' channel's one-time
|
||||
# startup message. warp_factor defaults to 1.0 (no scaling) until
|
||||
# that arrives, or for a server that doesn't send it at all.
|
||||
@@ -545,6 +545,24 @@ class Window(QtWidgets.QMainWindow, Ui_MainWindow):
|
||||
self.cooling_blink_timer = QtCore.QTimer(self)
|
||||
self.cooling_blink_timer.timeout.connect(self.on_cooling_blink)
|
||||
|
||||
# Persistent user-confirm control (a Sud step's WAIT_USER, e.g.
|
||||
# "Bitte Malz einfuellen und bestaetigen") - lives in the top
|
||||
# toolbar rather than a transient dialog, so it's visible
|
||||
# regardless of which tab is active. Flashes yellow with the
|
||||
# step's message while pending (same blink-timer pattern as
|
||||
# status_label_cooling above); disabled and blank otherwise.
|
||||
# set_user_confirm_pending() also disables the rest of the GUI
|
||||
# while pending, forcing this button to be dealt with first.
|
||||
self.toolBar.addSeparator()
|
||||
self.label_user_confirm = QtWidgets.QLabel()
|
||||
self.toolBar.addWidget(self.label_user_confirm)
|
||||
self.btn_user_confirm = QtWidgets.QPushButton("Confirm")
|
||||
self.btn_user_confirm.setEnabled(False)
|
||||
self.btn_user_confirm.clicked.connect(self.on_action_user_confirm)
|
||||
self.toolBar.addWidget(self.btn_user_confirm)
|
||||
self.user_confirm_blink_timer = QtCore.QTimer(self)
|
||||
self.user_confirm_blink_timer.timeout.connect(self.on_user_confirm_blink)
|
||||
|
||||
self.update_sud_actions()
|
||||
self.btn_connect.clicked.connect(self.on_btn_connect_clicked)
|
||||
self.actionStart.triggered.connect(self.on_action_sud_start)
|
||||
@@ -727,7 +745,7 @@ class Window(QtWidgets.QMainWindow, Ui_MainWindow):
|
||||
self.sud_empty = True
|
||||
self.sud_state = None
|
||||
self.sud_user_message = None
|
||||
self._close_confirm_dialog()
|
||||
self.set_user_confirm_pending(False)
|
||||
for w in (self.Slider_temp_soll, self.doubleSpinBox_heatrate_soll,
|
||||
self.Slider_pwr_soll, self.Slider_speed_soll):
|
||||
w.setEnabled(True)
|
||||
@@ -860,24 +878,47 @@ class Window(QtWidgets.QMainWindow, Ui_MainWindow):
|
||||
def on_action_sud_stop(self):
|
||||
self.msg_sud.send({'Stop': True})
|
||||
|
||||
def show_user_message(self, message):
|
||||
if self._confirm_box is not None:
|
||||
def set_user_confirm_pending(self, pending, message=''):
|
||||
if pending == self.user_confirm_pending:
|
||||
return
|
||||
dlg = QtWidgets.QDialog(self)
|
||||
dlg.setWindowTitle("Sud")
|
||||
dlg.setWindowModality(QtCore.Qt.NonModal)
|
||||
layout = QtWidgets.QVBoxLayout(dlg)
|
||||
layout.addWidget(QtWidgets.QLabel(message))
|
||||
btn = QtWidgets.QPushButton("OK")
|
||||
btn.clicked.connect(lambda: self.msg_sud.send({'Confirm': True}))
|
||||
layout.addWidget(btn)
|
||||
self._confirm_box = dlg
|
||||
dlg.show()
|
||||
self.user_confirm_pending = pending
|
||||
if pending:
|
||||
self.label_user_confirm.setText(message)
|
||||
self.btn_user_confirm.setEnabled(True)
|
||||
self.btn_user_confirm.setStyleSheet("background-color: yellow; font-weight: bold;")
|
||||
self.user_confirm_blink_timer.start(500)
|
||||
# Modally disabled: nothing else in the GUI should be usable
|
||||
# until the pending step is actually confirmed - centralwidget
|
||||
# covers every tab's content; the toolbar/menu actions are
|
||||
# disabled individually (rather than disabling self.toolBar
|
||||
# itself) so btn_user_confirm, a sibling widget on the same
|
||||
# toolbar, stays enabled.
|
||||
self.centralwidget.setEnabled(False)
|
||||
for action in (self.actionStart, self.actionPause, self.actionStop,
|
||||
self.actionSudNew, self.actionSudSave, self.actionSudLoad):
|
||||
action.setEnabled(False)
|
||||
else:
|
||||
self.user_confirm_blink_timer.stop()
|
||||
self.btn_user_confirm.setStyleSheet("")
|
||||
self.btn_user_confirm.setEnabled(False)
|
||||
self.label_user_confirm.setText('')
|
||||
self.centralwidget.setEnabled(True)
|
||||
self.actionSudNew.setEnabled(True)
|
||||
self.actionSudSave.setEnabled(True)
|
||||
self.actionSudLoad.setEnabled(True)
|
||||
# Start/Pause/Stop depend on sud_state/sud_empty, not just
|
||||
# "was disabled for confirm" - let the usual logic pick the
|
||||
# right one back up rather than assuming all three should
|
||||
# simply return to enabled.
|
||||
self.update_sud_actions()
|
||||
|
||||
def _close_confirm_dialog(self):
|
||||
if self._confirm_box is not None:
|
||||
self._confirm_box.close()
|
||||
self._confirm_box = None
|
||||
def on_user_confirm_blink(self):
|
||||
yellow = self.btn_user_confirm.styleSheet() == ""
|
||||
self.btn_user_confirm.setStyleSheet(
|
||||
"background-color: yellow; font-weight: bold;" if yellow else "")
|
||||
|
||||
def on_action_user_confirm(self):
|
||||
self.msg_sud.send({'Confirm': True})
|
||||
|
||||
def on_action_sud_new(self):
|
||||
# Sends an empty schedule via the same Load path Load Sud uses, with
|
||||
@@ -1013,7 +1054,22 @@ class Window(QtWidgets.QMainWindow, Ui_MainWindow):
|
||||
# Receiving anything at all on this channel means a Sud is loaded
|
||||
# server-side - the schedule it's running may still be coming.
|
||||
self.sud_loaded = True
|
||||
for key in msg:
|
||||
# UserMessage must be processed before State: a step's user_message
|
||||
# is set once, when the step starts (components/sud.py's
|
||||
# _advance()), well before state later flips to WAIT_USER
|
||||
# (_finish_step()) - so UserMessage's key was inserted into the
|
||||
# server's global_state earlier in its lifetime and would precede
|
||||
# State there. A client connecting fresh while a step is already
|
||||
# WAIT_USER gets both bundled into this same replay dict; processing
|
||||
# State first would check self.sud_user_message before this very
|
||||
# message has set it, silently failing set_user_confirm_pending()'s
|
||||
# guard and leaving the Confirm button looking merely disabled
|
||||
# instead of pending - see web/app.js's onSudChanged() for the twin
|
||||
# fix (same server, same race).
|
||||
ordered_keys = ['UserMessage'] + [k for k in msg if k != 'UserMessage']
|
||||
for key in ordered_keys:
|
||||
if key not in msg:
|
||||
continue
|
||||
if "Json" in key:
|
||||
if self.sud_save_path:
|
||||
with open(self.sud_save_path, 'w') as f:
|
||||
@@ -1078,9 +1134,9 @@ class Window(QtWidgets.QMainWindow, Ui_MainWindow):
|
||||
self.forecast_plot.show_computing(self.sud_name)
|
||||
|
||||
if self.sud_state == SUD_WAIT_USER_STATE and prev_state != SUD_WAIT_USER_STATE and self.sud_user_message:
|
||||
self.show_user_message(self.sud_user_message)
|
||||
self.set_user_confirm_pending(True, self.sud_user_message)
|
||||
elif prev_state == SUD_WAIT_USER_STATE and self.sud_state != SUD_WAIT_USER_STATE:
|
||||
self._close_confirm_dialog()
|
||||
self.set_user_confirm_pending(False)
|
||||
self._update_step_plates()
|
||||
elif "UserMessage" in key:
|
||||
self.sud_user_message = msg['UserMessage']
|
||||
|
||||
Reference in New Issue
Block a user