From 850a6d57f603982737cc772b5746ea96a4816474 Mon Sep 17 00:00:00 2001 From: wyzula-jan Date: Tue, 24 Nov 2026 10:41:03 +0000 Subject: [PATCH] fix(scan_control): restore confirms a typed scan name like start --- .../widgets/control/scan_control/scan_control.py | 4 +++- tests/unit_tests/test_scan_control.py | 10 ++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/bec_widgets/widgets/control/scan_control/scan_control.py b/bec_widgets/widgets/control/scan_control/scan_control.py index d6e2422c..122f73a8 100644 --- a/bec_widgets/widgets/control/scan_control/scan_control.py +++ b/bec_widgets/widgets/control/scan_control/scan_control.py @@ -488,7 +488,9 @@ class ScanControl(BECWidget, QWidget): """ if not self.last_scan_button.isEnabled(): return - # A scan name that is typed but not confirmed yet must not be fetched. + # Like Start: confirm a typed scan name (or fall back to the selected scan) first, also + # when the click did not take the focus from the selector, e.g. with its popup open. + self.validate_scan_selection() current_scan = self.current_scan if not current_scan: # e.g. an empty selector after a filter change - nothing to restore diff --git a/tests/unit_tests/test_scan_control.py b/tests/unit_tests/test_scan_control.py index 06919c7a..95877f14 100644 --- a/tests/unit_tests/test_scan_control.py +++ b/tests/unit_tests/test_scan_control.py @@ -1079,6 +1079,16 @@ def test_run_scan_confirms_typed_scan_name(scan_control, qtbot): scans.grid_scan.assert_called_once_with() +@pytest.mark.parametrize("typed, fetched", [("grid_scan", "grid_scan"), ("grid_sca", "line_scan")]) +def test_restore_last_scan_parameters_confirms_typed_scan_name(scan_control, qtbot, typed, fetched): + _type_scan_name(qtbot, scan_control, typed) + with patch.object(scan_control, "submit_task") as submit: + scan_control.request_last_executed_scan_parameters() + + assert scan_control.current_scan == fetched + assert submit.call_args.args[2] == fetched # (fetch, generation, scan name) + + def test_run_scan_discards_unfinished_scan_name(scan_control, qtbot): combo = scan_control.comboBox_scan_selection _type_scan_name(qtbot, scan_control, "grid_sca")