From 40096ef2e4290dac909513ccf6a6e03a02ca5494 Mon Sep 17 00:00:00 2001 From: David Perl Date: Tue, 20 Oct 2026 10:58:55 +0200 Subject: [PATCH] wip fix: don't restart on beam recovery --- src/aare/gui/panels/sample_queue_panel.py | 8 ++--- src/aare/gui/widgets/message_box.py | 36 +++-------------------- tests/unit/gui/test_message_box.py | 14 --------- 3 files changed, 8 insertions(+), 50 deletions(-) diff --git a/src/aare/gui/panels/sample_queue_panel.py b/src/aare/gui/panels/sample_queue_panel.py index b7b0ee00..1fa6a9b9 100644 --- a/src/aare/gui/panels/sample_queue_panel.py +++ b/src/aare/gui/panels/sample_queue_panel.py @@ -110,8 +110,8 @@ class SampleQueuePanel(QFrame): self.pause_on_conditions_cb.setChecked(True) self.pause_on_conditions_cb.setToolTip( "When on, automation refuses to start and pauses between samples if the beam, " - "experiment shutter, hutch doors or robot are not ready, auto-resuming when they " - "recover. Uncheck for testing to run straight through." + "experiment shutter, hutch doors or robot are not ready. Uncheck for testing " + "to run straight through." ) button_layout.addWidget(self.play_button) @@ -426,8 +426,8 @@ class SampleQueuePanel(QFrame): logger.warning(f"Automation paused; beamline not ready: {bad}") msg = "Automation paused — beamline not ready:\n- " + "\n- ".join(bad) - if conditions_auto_check(self, msg, self._conditions_ok): - logger.debug("Conditions recovered or user chose to continue; resuming automation") + if conditions_auto_check(self, msg): + logger.debug("User chose to continue; resuming automation") self.table_model.set_running(True) self._pause = False self.play_button.setText("⏸ Pause") diff --git a/src/aare/gui/widgets/message_box.py b/src/aare/gui/widgets/message_box.py index 87c38fac..ad90bed4 100644 --- a/src/aare/gui/widgets/message_box.py +++ b/src/aare/gui/widgets/message_box.py @@ -89,40 +89,12 @@ def reply_box(parent, title: str = "Warning", msg: str = "Warning."): ) -def timer_box( - parent, title: str = "Warning", msg: str = "Warning.", condition_func=None -) -> QMessageBox: +def continue_msg_box(parent, title: str = "Warning", msg: str = "Warning.") -> QMessageBox: box = QMessageBox(parent) box.setWindowTitle(title) box.setText(f"{msg} Do you wish to continue?") box.setStandardButtons(QMessageBox.StandardButton.Yes | QMessageBox.StandardButton.No) box.show() - - timer = QTimer(box) - timer.setInterval(300) - - def stop_timer(): - if timer.isActive(): - timer.stop() - - def check(): - if not box.isVisible(): - stop_timer() - return - try: - if condition_func and condition_func(): - # Auto-accept (as if user pressed Yes) - box.done(QMessageBox.StandardButton.Yes) - stop_timer() - except Exception: - # Never let errors in condition_func block UI - logger.exception("Error in condition_func") - - box.accepted.connect(stop_timer) - box.rejected.connect(stop_timer) - timer.timeout.connect(check) - - timer.start() return box @@ -163,10 +135,10 @@ def ring_current_auto_check(parent, ring_current, check_func) -> bool: if ring_current is None else f"Ring current is low {round(ring_current, 2)} mA." ) - return conditions_auto_check(parent, msg, check_func, title="Ring current too low") + return conditions_auto_check(parent, msg, title="Ring current too low") -def conditions_auto_check(parent, msg: str, check_func, title: str = "Beamline not ready") -> bool: +def conditions_auto_check(parent, msg: str, title: str = "Beamline not ready") -> bool: """Pause-and-wait dialog that auto-resumes when ``check_func()`` becomes True. Used to hold automation between samples until the beamline recovers. The @@ -174,7 +146,7 @@ def conditions_auto_check(parent, msg: str, check_func, title: str = "Beamline n can also click 'Yes' to continue now (override) or 'No' to stop automation. Returns True to resume, False to stop. """ - box = timer_box(parent, title=title, msg=msg, condition_func=check_func) + box = continue_msg_box(parent, title=title, msg=msg) loop = QEventLoop() def finish(_=None): diff --git a/tests/unit/gui/test_message_box.py b/tests/unit/gui/test_message_box.py index 5ed7923f..0d440b9e 100644 --- a/tests/unit/gui/test_message_box.py +++ b/tests/unit/gui/test_message_box.py @@ -8,7 +8,6 @@ from aare.gui.widgets.message_box import ( reply_box, ring_current_auto_check, ring_current_low_check, - timer_box, ) @@ -21,19 +20,6 @@ def test_reply_box(qtbot): mock_question.assert_called_once() -def test_timer_box_auto_accept(qtbot): - parent = None - condition_func = MagicMock(return_value=True) - - # We need to process events for timer to fire - box = timer_box(parent, condition_func=condition_func) - - # Wait until box is closed by check() - qtbot.waitUntil(lambda: not box.isVisible(), timeout=2000) - - assert box.result() == QMessageBox.StandardButton.Yes - - @pytest.mark.timeout(10) def test_ring_current_low_check_ok(qtbot): # Should return True immediately if current is high enough