From a7c15cccf149cd6d17a4d0a620dd5278805be68f Mon Sep 17 00:00:00 2001 From: Dawn Date: Wed, 19 Aug 2026 16:33:28 +0200 Subject: [PATCH] fix: combined view only when state is moving or when in robotsampleexchange --- src/aare/gui/main_window.py | 16 +++++++--------- tests/unit/gui/test_main_window.py | 16 +++++++++++----- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/src/aare/gui/main_window.py b/src/aare/gui/main_window.py index 488a0298..69226bf7 100644 --- a/src/aare/gui/main_window.py +++ b/src/aare/gui/main_window.py @@ -2784,15 +2784,13 @@ class MainWindow(QMainWindow): if self._remote_close_deadline_ts is not None: self._clear_remote_close_request() - # Busy (or the robot station) means something is physically moving: - # show the Beamline combined view so the motion can be watched, and - # return to the sample camera once it is done. Edge-triggered so a - # manual tab choice survives between transitions. Sample alignment is - # the exception: its busy moves ARE the alignment, and the user needs - # to keep watching the sample camera, not the beamline view. - moving = ( - bool(s.busy) or s.state == BeamlineStateEnum.RobotSampleExchange - ) and s.state != BeamlineStateEnum.SampleAlignment + # Only robot-scale motion flips to the Beamline combined view: state + # transitions (the server parks in Moving while driving motors) and + # the robot station. Busy alone no longer triggers it — Sample + # alignment, Beam location, Beamstop alignment, Flux measurement + # etc. run busy while the user watches the sample camera itself. + # Edge-triggered so a manual tab choice survives between transitions. + moving = s.state in (BeamlineStateEnum.Moving, BeamlineStateEnum.RobotSampleExchange) if moving and not self._watching_motion: self._watching_motion = True self.video_tab.setCurrentWidget(self.beamline_combined_panel) diff --git a/tests/unit/gui/test_main_window.py b/tests/unit/gui/test_main_window.py index 1f8a2019..1f8c2262 100644 --- a/tests/unit/gui/test_main_window.py +++ b/tests/unit/gui/test_main_window.py @@ -71,10 +71,10 @@ def test_main_window_init(qtbot, mock_ui_state, daq_status_factory): win.data_collection._emit_change_energy() assert sent and abs(sent[0] - 12400.0) < 1e-6 - # Motion watch: robot motion switches to the combined beamline view; - # alignment beginning switches straight back to the sample camera even - # while the busy flag is still set — busy moves during Sample - # alignment ARE the alignment, so it never re-triggers the switch. + # Motion watch: only a state transition (Moving) or the robot station + # switches to the combined beamline view. Busy alone never does — + # Sample alignment, Beam location etc. run busy while the user + # watches the sample camera itself. win.update_daq_status( daq_status_factory(state=BeamlineStateEnum.RobotSampleExchange, busy=True) ) @@ -85,10 +85,16 @@ def test_main_window_init(qtbot, mock_ui_state, daq_status_factory): ) assert not win._watching_motion assert win.video_tab.currentWidget() is win.sample_camera + win.update_daq_status(daq_status_factory(state=BeamlineStateEnum.BeamLocation, busy=True)) + assert not win._watching_motion + win.update_daq_status(daq_status_factory(state=BeamlineStateEnum.Moving, busy=True)) + assert win._watching_motion + assert win.video_tab.currentWidget() is win.beamline_combined_panel win.update_daq_status( - daq_status_factory(state=BeamlineStateEnum.SampleAlignment, busy=True) + daq_status_factory(state=BeamlineStateEnum.DataCollection, busy=False) ) assert not win._watching_motion + assert win.video_tab.currentWidget() is win.sample_camera def test_main_window_mount_view(qtbot, mock_ui_state):