From f49f34cd27572ec2662f412f84452b66dce7fd0b Mon Sep 17 00:00:00 2001 From: Dawn Date: Tue, 29 Sep 2026 11:19:24 +0200 Subject: [PATCH] fix(gui): skip mount auto-centering during queue automation Automation centers each sample itself and frees the hw lock between samples; waiting for idle made the GUI fire center_loop in that gap, which could steal the lock from the next /scan/auto and stop the queue. Co-Authored-By: Claude Opus 5.5 (1M context) --- src/aare/gui/main_window.py | 3 +++ .../gui/panels/data_collection_settings.py | 14 +++++++++++++- .../unit/gui/test_data_collection_settings.py | 19 +++++++++++++++++++ 3 files changed, 35 insertions(+), 1 deletion(-) diff --git a/src/aare/gui/main_window.py b/src/aare/gui/main_window.py index 67fecf58..daa6d885 100644 --- a/src/aare/gui/main_window.py +++ b/src/aare/gui/main_window.py @@ -745,6 +745,9 @@ class MainWindow(QMainWindow): self.automation_progress_panel.set_running ) self.job_list_panel.automation_running_changed.connect(self._on_automation_running_changed) + self.job_list_panel.automation_running_changed.connect( + self.data_collection.set_automation_running + ) self.automation_progress_panel.set_samples_in_queue( len(self.job_list_panel.table_model.samples) diff --git a/src/aare/gui/panels/data_collection_settings.py b/src/aare/gui/panels/data_collection_settings.py index 6929d5de..184b1030 100644 --- a/src/aare/gui/panels/data_collection_settings.py +++ b/src/aare/gui/panels/data_collection_settings.py @@ -197,6 +197,7 @@ class DataCollectionSettings(QFrame): self._status_seen = False # Set on mount, fired once the hw lock frees (see _track_sample). self._center_after_mount_pending = False + self._automation_running = False self._tab_bar.currentChanged.connect(self._stack.setCurrentIndex) self._tab_bar.currentChanged.connect(self._on_tab_changed) @@ -258,7 +259,9 @@ class DataCollectionSettings(QFrame): self._sample_id = db_id self._tab_bar.setCurrentIndex(0) self._center_after_mount_pending = ( - self._status_seen and self.auto_center_after_mount.isChecked() + self._status_seen + and self.auto_center_after_mount.isChecked() + and not self._automation_running ) self._status_seen = True # The server publishes the new sample while the mount still holds the @@ -270,6 +273,15 @@ class DataCollectionSettings(QFrame): # main_window) instead of a second signal path. self.find_tip.click() + @Slot(bool) + def set_automation_running(self, running: bool): + # Queue automation centers each sample itself and frees the hw lock + # between samples; a GUI centering in that gap could steal the lock + # from the next /scan/auto and stop the queue. + self._automation_running = running + if running: + self._center_after_mount_pending = False + @Slot(int) def _on_tab_changed(self, idx: int): self.bounding_box.setVisible(idx == 0) diff --git a/tests/unit/gui/test_data_collection_settings.py b/tests/unit/gui/test_data_collection_settings.py index 0a7990bd..307c228d 100644 --- a/tests/unit/gui/test_data_collection_settings.py +++ b/tests/unit/gui/test_data_collection_settings.py @@ -376,6 +376,25 @@ def test_auto_center_waits_for_mount_to_release_hw_lock(settings_panel): assert len(clicks) == 1 +def test_auto_center_skipped_during_queue_automation(settings_panel): + # Automation centers itself and frees the lock between samples; a GUI + # centering there could steal the lock from the next /scan/auto. + clicks = [] + settings_panel.find_tip.clicked.connect(lambda: clicks.append(1)) + settings_panel.auto_center_after_mount.setChecked(True) + settings_panel._track_sample(1) + + settings_panel.set_automation_running(True) + settings_panel._track_sample(2, busy=True) + settings_panel._track_sample(2, busy=False) + assert not clicks + + settings_panel.set_automation_running(False) + settings_panel._track_sample(3, busy=True) + settings_panel._track_sample(3, busy=False) + assert len(clicks) == 1 + + # --------------------------------------------------------------------------- # Pending color while typing (movestate property, committed on Enter/focus-out) # ---------------------------------------------------------------------------