mirror of
https://github.com/bec-project/bec_widgets.git
synced 2025-07-14 03:31:50 +02:00
refactor: allow to set selection in DeviceInput; automatic update of selection on device config update; cleanup
This commit is contained in:
@ -2,6 +2,7 @@ from __future__ import annotations
|
|||||||
|
|
||||||
import enum
|
import enum
|
||||||
|
|
||||||
|
from bec_lib.callback_handler import EventType
|
||||||
from bec_lib.device import ComputedSignal, Device, Positioner, ReadoutPriority, Signal
|
from bec_lib.device import ComputedSignal, Device, Positioner, ReadoutPriority, Signal
|
||||||
from bec_lib.logger import bec_logger
|
from bec_lib.logger import bec_logger
|
||||||
from qtpy.QtCore import Property, Slot
|
from qtpy.QtCore import Property, Slot
|
||||||
@ -71,6 +72,9 @@ class DeviceInputBase(BECWidget):
|
|||||||
self._device_filter = []
|
self._device_filter = []
|
||||||
self._readout_filter = []
|
self._readout_filter = []
|
||||||
self._devices = []
|
self._devices = []
|
||||||
|
self.bec_dispatcher.client.callbacks.register(
|
||||||
|
EventType.DEVICE_UPDATE, self.update_devices_from_filters
|
||||||
|
)
|
||||||
|
|
||||||
### QtSlots ###
|
### QtSlots ###
|
||||||
|
|
||||||
@ -88,8 +92,11 @@ class DeviceInputBase(BECWidget):
|
|||||||
else:
|
else:
|
||||||
logger.warning(f"Device {device} is not in the filtered selection.")
|
logger.warning(f"Device {device} is not in the filtered selection.")
|
||||||
|
|
||||||
|
@Slot(dict, dict)
|
||||||
@Slot()
|
@Slot()
|
||||||
def update_devices_from_filters(self):
|
def update_devices_from_filters(
|
||||||
|
self, content: dict | None = None, metadata: dict | None = None
|
||||||
|
):
|
||||||
"""Update the devices based on the current filter selection
|
"""Update the devices based on the current filter selection
|
||||||
in self.device_filter and self.readout_filter. If apply_filter is False,
|
in self.device_filter and self.readout_filter. If apply_filter is False,
|
||||||
it will not apply the filters, store the filter settings and return.
|
it will not apply the filters, store the filter settings and return.
|
||||||
@ -133,16 +140,9 @@ class DeviceInputBase(BECWidget):
|
|||||||
|
|
||||||
@devices.setter
|
@devices.setter
|
||||||
def devices(self, value: list):
|
def devices(self, value: list):
|
||||||
valid_dev = []
|
self._devices = value
|
||||||
all_dev_names = [dev.name for dev in self.dev.enabled_devices]
|
self.config.devices = value
|
||||||
for dev in value:
|
FilterIO.set_selection(widget=self, selection=value)
|
||||||
if dev in all_dev_names:
|
|
||||||
valid_dev.append(dev)
|
|
||||||
self._devices = valid_dev
|
|
||||||
self.config.devices = valid_dev
|
|
||||||
|
|
||||||
FilterIO.set_selection(widget=self, selection=valid_dev)
|
|
||||||
# QTimer.singleShot(200, lambda: FilterIO.set_selection(widget=self, selection=valid_dev))
|
|
||||||
|
|
||||||
@Property(str)
|
@Property(str)
|
||||||
def default(self):
|
def default(self):
|
||||||
@ -151,13 +151,8 @@ class DeviceInputBase(BECWidget):
|
|||||||
|
|
||||||
@default.setter
|
@default.setter
|
||||||
def default(self, value: str):
|
def default(self, value: str):
|
||||||
def set_default():
|
if self.validate_device(value) is False:
|
||||||
if self.validate_device(value) is False:
|
return
|
||||||
return
|
|
||||||
self.set_device(value)
|
|
||||||
|
|
||||||
set_default()
|
|
||||||
# QTimer.singleShot(200, set_default)
|
|
||||||
|
|
||||||
@Property(bool)
|
@Property(bool)
|
||||||
def apply_filter(self):
|
def apply_filter(self):
|
||||||
@ -166,12 +161,8 @@ class DeviceInputBase(BECWidget):
|
|||||||
|
|
||||||
@apply_filter.setter
|
@apply_filter.setter
|
||||||
def apply_filter(self, value: bool):
|
def apply_filter(self, value: bool):
|
||||||
def apply_filters():
|
self.config.apply_filter = value
|
||||||
self.config.apply_filter = value
|
self.update_devices_from_filters()
|
||||||
self.update_devices_from_filters()
|
|
||||||
|
|
||||||
apply_filters()
|
|
||||||
# QTimer.singleShot(200, apply_filters)
|
|
||||||
|
|
||||||
@Property(bool)
|
@Property(bool)
|
||||||
def filter_to_device(self):
|
def filter_to_device(self):
|
||||||
@ -180,15 +171,11 @@ class DeviceInputBase(BECWidget):
|
|||||||
|
|
||||||
@filter_to_device.setter
|
@filter_to_device.setter
|
||||||
def filter_to_device(self, value: bool):
|
def filter_to_device(self, value: bool):
|
||||||
def set_filter():
|
if value is True and BECDeviceFilter.DEVICE not in self.device_filter:
|
||||||
if value is True and BECDeviceFilter.DEVICE not in self.device_filter:
|
self._device_filter.append(BECDeviceFilter.DEVICE)
|
||||||
self._device_filter.append(BECDeviceFilter.DEVICE)
|
if value is False and BECDeviceFilter.DEVICE in self.device_filter:
|
||||||
if value is False and BECDeviceFilter.DEVICE in self.device_filter:
|
self._device_filter.remove(BECDeviceFilter.DEVICE)
|
||||||
self._device_filter.remove(BECDeviceFilter.DEVICE)
|
self.update_devices_from_filters()
|
||||||
self.update_devices_from_filters()
|
|
||||||
|
|
||||||
set_filter()
|
|
||||||
# QTimer.singleShot(200, set_filter)
|
|
||||||
|
|
||||||
@Property(bool)
|
@Property(bool)
|
||||||
def filter_to_positioner(self):
|
def filter_to_positioner(self):
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
from bec_lib.callback_handler import EventType
|
||||||
from bec_lib.device import Signal
|
from bec_lib.device import Signal
|
||||||
from bec_lib.logger import bec_logger
|
from bec_lib.logger import bec_logger
|
||||||
from ophyd import Kind
|
from ophyd import Kind
|
||||||
@ -50,6 +51,9 @@ class DeviceSignalInputBase(BECWidget):
|
|||||||
self._hinted_signals = []
|
self._hinted_signals = []
|
||||||
self._normal_signals = []
|
self._normal_signals = []
|
||||||
self._config_signals = []
|
self._config_signals = []
|
||||||
|
self.bec_dispatcher.client.callbacks.register(
|
||||||
|
EventType.DEVICE_UPDATE, self.update_signals_from_filters
|
||||||
|
)
|
||||||
|
|
||||||
### Qt Slots ###
|
### Qt Slots ###
|
||||||
|
|
||||||
@ -83,8 +87,11 @@ class DeviceSignalInputBase(BECWidget):
|
|||||||
self._device = device
|
self._device = device
|
||||||
self.update_signals_from_filters()
|
self.update_signals_from_filters()
|
||||||
|
|
||||||
|
@Slot(dict, dict)
|
||||||
@Slot()
|
@Slot()
|
||||||
def update_signals_from_filters(self):
|
def update_signals_from_filters(
|
||||||
|
self, content: dict | None = None, metadata: dict | None = None
|
||||||
|
):
|
||||||
"""Update the filters for the device signals based on list in self.signal_filter.
|
"""Update the filters for the device signals based on list in self.signal_filter.
|
||||||
In addition, store the hinted, normal and config signals in separate lists to allow
|
In addition, store the hinted, normal and config signals in separate lists to allow
|
||||||
customisation within QLineEdit.
|
customisation within QLineEdit.
|
||||||
|
Reference in New Issue
Block a user