From 4288bc661bf0e0f9cebabd319514b29113229292 Mon Sep 17 00:00:00 2001 From: wyzula-jan Date: Wed, 11 Nov 2026 12:14:25 +0100 Subject: [PATCH] fix(signal_combobox): resolve the signal config from the displayed text --- .../signal_combobox/signal_combobox.py | 12 ++++++--- tests/unit_tests/test_device_signal_input.py | 27 +++++++++++++++++++ 2 files changed, 36 insertions(+), 3 deletions(-) diff --git a/bec_widgets/widgets/control/device_input/signal_combobox/signal_combobox.py b/bec_widgets/widgets/control/device_input/signal_combobox/signal_combobox.py index e02e378a..3240d939 100644 --- a/bec_widgets/widgets/control/device_input/signal_combobox/signal_combobox.py +++ b/bec_widgets/widgets/control/device_input/signal_combobox/signal_combobox.py @@ -505,12 +505,18 @@ class SignalComboBox(BECWidget, QComboBox): """Return the selected signal config if item-data storage is enabled. Returns: - Selected signal configuration dictionary, or None when item-data storage is disabled - or the current item has no configuration. + Selected signal configuration dictionary, or None when item-data storage is disabled, + the displayed text matches no signal, or its item has no configuration. """ if not self._store_signal_config: return None - signal_info = self.itemData(self.currentIndex()) + # Resolve by the displayed text: on editable comboboxes the current index + # does not follow programmatic or typed text changes, so it may belong to + # another signal. A text that matches no item has no config. + index = self._find_signal_index(self.currentText()) + if index < 0: + return None + signal_info = self.itemData(index) return signal_info if isinstance(signal_info, dict) else None def update_signals_from_signal_classes(self, ndim_filter: int | list[int] | None = None): diff --git a/tests/unit_tests/test_device_signal_input.py b/tests/unit_tests/test_device_signal_input.py index 2da69c5d..b8657ce3 100644 --- a/tests/unit_tests/test_device_signal_input.py +++ b/tests/unit_tests/test_device_signal_input.py @@ -400,6 +400,33 @@ def test_signal_combobox_get_signal_config(device_signal_combobox): assert device_signal_combobox.get_signal_config() == expected_config +def test_signal_combobox_get_signal_config_follows_the_displayed_signal(device_signal_combobox): + """On the editable combobox, setCurrentText does not move the current index; the + returned config must still be the one of the displayed signal.""" + combo = device_signal_combobox + combo.include_normal_signals = True + combo.include_hinted_signals = True + combo.include_config_signals = True + combo.set_device("samx") + combo.setCurrentText("velocity") + config = combo.get_signal_config() + assert config is not None and config.get("obj_name") == "samx_velocity" + + +def test_signal_combobox_get_signal_config_none_for_unknown_text(device_signal_combobox): + """A typed signal that is not in the list has no config, even though the current + index still points at the previously selected signal.""" + combo = device_signal_combobox + combo.include_normal_signals = True + combo.include_hinted_signals = True + combo.include_config_signals = True + combo.set_device("samx") + combo.setCurrentIndex(combo.findText("velocity")) + combo.setEditText("not_a_signal") + assert combo.currentIndex() == combo.findText("velocity") + assert combo.get_signal_config() is None + + def test_signal_combobox_get_signal_config_disabled(qtbot, mocked_client): combobox = create_widget( qtbot=qtbot, widget=SignalComboBox, client=mocked_client, store_signal_config=False