mirror of
https://github.com/bec-project/bec_widgets.git
synced 2025-07-13 11:11:49 +02:00
fix(signal-combobox): bug fix in signal combobox that crashed upon switching from device to signal input
This commit is contained in:
@ -200,7 +200,13 @@ class DMMock:
|
|||||||
self.devices = DeviceContainer()
|
self.devices = DeviceContainer()
|
||||||
self.enabled_devices = [device for device in self.devices if device.enabled]
|
self.enabled_devices = [device for device in self.devices if device.enabled]
|
||||||
|
|
||||||
def add_devives(self, devices: list):
|
def add_devices(self, devices: list):
|
||||||
|
"""
|
||||||
|
Add devices to the DeviceContainer.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
devices (list): List of device instances to add.
|
||||||
|
"""
|
||||||
for device in devices:
|
for device in devices:
|
||||||
self.devices[device.name] = device
|
self.devices[device.name] = device
|
||||||
|
|
||||||
|
@ -112,9 +112,12 @@ class DeviceSignalInputBase(BECWidget):
|
|||||||
# See above convention for Signals and ComputedSignals
|
# See above convention for Signals and ComputedSignals
|
||||||
if isinstance(device, Signal):
|
if isinstance(device, Signal):
|
||||||
self._signals = [self._device]
|
self._signals = [self._device]
|
||||||
FilterIO.set_selection(widget=self, selection=[self._device])
|
self._hinted_signals = [self._device]
|
||||||
|
self._normal_signals = []
|
||||||
|
self._config_signals = []
|
||||||
|
FilterIO.set_selection(widget=self, selection=self._signals)
|
||||||
return
|
return
|
||||||
device_info = device._info["signals"]
|
device_info = device._info.get("signals", {})
|
||||||
|
|
||||||
def _update(kind: Kind):
|
def _update(kind: Kind):
|
||||||
return [
|
return [
|
||||||
|
@ -22,6 +22,8 @@ class DeviceComboBox(DeviceInputBase, QComboBox):
|
|||||||
config: Device input configuration.
|
config: Device input configuration.
|
||||||
gui_id: GUI ID.
|
gui_id: GUI ID.
|
||||||
device_filter: Device filter, name of the device class from BECDeviceFilter and BECReadoutPriority. Check DeviceInputBase for more details.
|
device_filter: Device filter, name of the device class from BECDeviceFilter and BECReadoutPriority. Check DeviceInputBase for more details.
|
||||||
|
readout_priority_filter: Readout priority filter, name of the readout priority class from BECDeviceFilter and BECReadoutPriority. Check DeviceInputBase for more details.
|
||||||
|
available_devices: List of available devices, if passed, it sets apply filters to false and device/readout priority filters will not be applied.
|
||||||
default: Default device name.
|
default: Default device name.
|
||||||
arg_name: Argument name, can be used for the other widgets which has to call some other function in bec using correct argument names.
|
arg_name: Argument name, can be used for the other widgets which has to call some other function in bec using correct argument names.
|
||||||
"""
|
"""
|
||||||
|
@ -24,7 +24,9 @@ class DeviceLineEdit(DeviceInputBase, QLineEdit):
|
|||||||
client: BEC client object.
|
client: BEC client object.
|
||||||
config: Device input configuration.
|
config: Device input configuration.
|
||||||
gui_id: GUI ID.
|
gui_id: GUI ID.
|
||||||
device_filter: Device filter, name of the device class from BECDeviceFilter and ReadoutPriority. Check DeviceInputBase for more details.
|
device_filter: Device filter, name of the device class from BECDeviceFilter and BECReadoutPriority. Check DeviceInputBase for more details.
|
||||||
|
readout_priority_filter: Readout priority filter, name of the readout priority class from BECDeviceFilter and BECReadoutPriority. Check DeviceInputBase for more details.
|
||||||
|
available_devices: List of available devices, if passed, it sets apply filters to false and device/readout priority filters will not be applied.
|
||||||
default: Default device name.
|
default: Default device name.
|
||||||
arg_name: Argument name, can be used for the other widgets which has to call some other function in bec using correct argument names.
|
arg_name: Argument name, can be used for the other widgets which has to call some other function in bec using correct argument names.
|
||||||
"""
|
"""
|
||||||
|
@ -30,7 +30,7 @@ def mocked_client(bec_dispatcher):
|
|||||||
# Mock the device_manager.devices attribute
|
# Mock the device_manager.devices attribute
|
||||||
client.connector = connector
|
client.connector = connector
|
||||||
client.device_manager = DMMock()
|
client.device_manager = DMMock()
|
||||||
client.device_manager.add_devives(DEVICES)
|
client.device_manager.add_devices(DEVICES)
|
||||||
|
|
||||||
def mock_mv(*args, relative=False):
|
def mock_mv(*args, relative=False):
|
||||||
# Extracting motor and value pairs
|
# Extracting motor and value pairs
|
||||||
|
@ -1,8 +1,10 @@
|
|||||||
from unittest import mock
|
from unittest import mock
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
from bec_lib.device import Signal
|
||||||
from qtpy.QtWidgets import QWidget
|
from qtpy.QtWidgets import QWidget
|
||||||
|
|
||||||
|
from bec_widgets.tests.utils import FakeDevice
|
||||||
from bec_widgets.utils.ophyd_kind_util import Kind
|
from bec_widgets.utils.ophyd_kind_util import Kind
|
||||||
from bec_widgets.widgets.control.device_input.base_classes.device_input_base import BECDeviceFilter
|
from bec_widgets.widgets.control.device_input.base_classes.device_input_base import BECDeviceFilter
|
||||||
from bec_widgets.widgets.control.device_input.base_classes.device_signal_input_base import (
|
from bec_widgets.widgets.control.device_input.base_classes.device_signal_input_base import (
|
||||||
@ -18,6 +20,10 @@ from .client_mocks import mocked_client
|
|||||||
from .conftest import create_widget
|
from .conftest import create_widget
|
||||||
|
|
||||||
|
|
||||||
|
class FakeSignal(Signal):
|
||||||
|
"""Fake signal to test the DeviceSignalInputBase."""
|
||||||
|
|
||||||
|
|
||||||
class DeviceInputWidget(DeviceSignalInputBase, QWidget):
|
class DeviceInputWidget(DeviceSignalInputBase, QWidget):
|
||||||
"""Thin wrapper around DeviceInputBase to make it a QWidget"""
|
"""Thin wrapper around DeviceInputBase to make it a QWidget"""
|
||||||
|
|
||||||
@ -107,6 +113,14 @@ def test_signal_combobox(qtbot, device_signal_combobox):
|
|||||||
assert device_signal_combobox.signals == ["readback", "setpoint", "velocity"]
|
assert device_signal_combobox.signals == ["readback", "setpoint", "velocity"]
|
||||||
qtbot.wait(100)
|
qtbot.wait(100)
|
||||||
assert container == ["samx"]
|
assert container == ["samx"]
|
||||||
|
# Set the type of class from the FakeDevice to Signal
|
||||||
|
fake_signal = FakeSignal(name="fake_signal")
|
||||||
|
device_signal_combobox.client.device_manager.add_devices([fake_signal])
|
||||||
|
device_signal_combobox.set_device("fake_signal")
|
||||||
|
assert device_signal_combobox.signals == ["fake_signal"]
|
||||||
|
assert device_signal_combobox._config_signals == []
|
||||||
|
assert device_signal_combobox._normal_signals == []
|
||||||
|
assert device_signal_combobox._hinted_signals == ["fake_signal"]
|
||||||
|
|
||||||
|
|
||||||
def test_signal_lineeidt(device_signal_line_edit):
|
def test_signal_lineeidt(device_signal_line_edit):
|
||||||
|
Reference in New Issue
Block a user