fix(signal_combobox): resolve the signal config from the displayed text

This commit is contained in:
wyzula_j authored and Jan Wyzula committed 2026-11-17 18:41:56 +01:00
1 parent 9e0cfc8518
commit 4288bc661b
2 files changed
+36 -3

No files matched your search

@@ -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):
@@ -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