wip fix: don't restart on beam recovery
CI / lint (push) Skipped
CI / test (3.12) (push) Skipped
CI / test (3.13) (push) Skipped
CI / test-with-beamline-plugins (pxi_bec) (push) Skipped
CI / test-with-beamline-plugins (pxii_bec) (push) Skipped
CI / test-with-beamline-plugins (pxiii_bec) (push) Skipped
CI / lint (push) Skipped
CI / test (3.12) (push) Skipped
CI / test (3.13) (push) Skipped
CI / test-with-beamline-plugins (pxi_bec) (push) Skipped
CI / test-with-beamline-plugins (pxii_bec) (push) Skipped
CI / test-with-beamline-plugins (pxiii_bec) (push) Skipped
This commit is contained in:
1 parent
c9d9d716ab
commit
40096ef2e4
3 files changed
+8
-50
No files matched your search
@@ -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")
|
||||
|
||||
@@ -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):
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in new issue
Block a user