mirror of
https://github.com/bec-project/bec_widgets.git
synced 2025-07-13 19:21:50 +02:00
refactor(device input): refactor to SafeProperty and SafeSlot
This commit is contained in:
@ -6,10 +6,10 @@ from bec_lib.device import ComputedSignal, Device, Positioner, ReadoutPriority
|
|||||||
from bec_lib.device import Signal as BECSignal
|
from bec_lib.device import Signal as BECSignal
|
||||||
from bec_lib.logger import bec_logger
|
from bec_lib.logger import bec_logger
|
||||||
from pydantic import field_validator
|
from pydantic import field_validator
|
||||||
from qtpy.QtCore import Property, Signal, Slot
|
|
||||||
|
|
||||||
from bec_widgets.utils import ConnectionConfig
|
from bec_widgets.utils import ConnectionConfig
|
||||||
from bec_widgets.utils.bec_widget import BECWidget
|
from bec_widgets.utils.bec_widget import BECWidget
|
||||||
|
from bec_widgets.utils.error_popups import SafeProperty, SafeSlot
|
||||||
from bec_widgets.utils.filter_io import FilterIO
|
from bec_widgets.utils.filter_io import FilterIO
|
||||||
from bec_widgets.utils.widget_io import WidgetIO
|
from bec_widgets.utils.widget_io import WidgetIO
|
||||||
|
|
||||||
@ -100,7 +100,7 @@ class DeviceInputBase(BECWidget):
|
|||||||
|
|
||||||
### QtSlots ###
|
### QtSlots ###
|
||||||
|
|
||||||
@Slot(str)
|
@SafeSlot(str)
|
||||||
def set_device(self, device: str):
|
def set_device(self, device: str):
|
||||||
"""
|
"""
|
||||||
Set the device.
|
Set the device.
|
||||||
@ -114,7 +114,7 @@ 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()
|
@SafeSlot()
|
||||||
def update_devices_from_filters(self):
|
def update_devices_from_filters(self):
|
||||||
"""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,
|
||||||
@ -133,7 +133,7 @@ class DeviceInputBase(BECWidget):
|
|||||||
self.devices = [device.name for device in devs]
|
self.devices = [device.name for device in devs]
|
||||||
self.set_device(current_device)
|
self.set_device(current_device)
|
||||||
|
|
||||||
@Slot(list)
|
@SafeSlot(list)
|
||||||
def set_available_devices(self, devices: list[str]):
|
def set_available_devices(self, devices: list[str]):
|
||||||
"""
|
"""
|
||||||
Set the devices. If a device in the list is not valid, it will not be considered.
|
Set the devices. If a device in the list is not valid, it will not be considered.
|
||||||
@ -146,7 +146,7 @@ class DeviceInputBase(BECWidget):
|
|||||||
|
|
||||||
### QtProperties ###
|
### QtProperties ###
|
||||||
|
|
||||||
@Property(
|
@SafeProperty(
|
||||||
"QStringList",
|
"QStringList",
|
||||||
doc="List of devices. If updated, it will disable the apply filters property.",
|
doc="List of devices. If updated, it will disable the apply filters property.",
|
||||||
)
|
)
|
||||||
@ -165,7 +165,7 @@ class DeviceInputBase(BECWidget):
|
|||||||
self.config.devices = value
|
self.config.devices = value
|
||||||
FilterIO.set_selection(widget=self, selection=value)
|
FilterIO.set_selection(widget=self, selection=value)
|
||||||
|
|
||||||
@Property(str)
|
@SafeProperty(str)
|
||||||
def default(self):
|
def default(self):
|
||||||
"""Get the default device name. If set through this property, it will update only if the device is within the filtered selection."""
|
"""Get the default device name. If set through this property, it will update only if the device is within the filtered selection."""
|
||||||
return self.config.default
|
return self.config.default
|
||||||
@ -177,7 +177,7 @@ class DeviceInputBase(BECWidget):
|
|||||||
self.config.default = value
|
self.config.default = value
|
||||||
WidgetIO.set_value(widget=self, value=value)
|
WidgetIO.set_value(widget=self, value=value)
|
||||||
|
|
||||||
@Property(bool)
|
@SafeProperty(bool)
|
||||||
def apply_filter(self):
|
def apply_filter(self):
|
||||||
"""Apply the filters on the devices."""
|
"""Apply the filters on the devices."""
|
||||||
return self.config.apply_filter
|
return self.config.apply_filter
|
||||||
@ -187,7 +187,7 @@ class DeviceInputBase(BECWidget):
|
|||||||
self.config.apply_filter = value
|
self.config.apply_filter = value
|
||||||
self.update_devices_from_filters()
|
self.update_devices_from_filters()
|
||||||
|
|
||||||
@Property(bool)
|
@SafeProperty(bool)
|
||||||
def filter_to_device(self):
|
def filter_to_device(self):
|
||||||
"""Include devices in filters."""
|
"""Include devices in filters."""
|
||||||
return BECDeviceFilter.DEVICE in self.device_filter
|
return BECDeviceFilter.DEVICE in self.device_filter
|
||||||
@ -200,7 +200,7 @@ class DeviceInputBase(BECWidget):
|
|||||||
self._device_filter.remove(BECDeviceFilter.DEVICE)
|
self._device_filter.remove(BECDeviceFilter.DEVICE)
|
||||||
self.update_devices_from_filters()
|
self.update_devices_from_filters()
|
||||||
|
|
||||||
@Property(bool)
|
@SafeProperty(bool)
|
||||||
def filter_to_positioner(self):
|
def filter_to_positioner(self):
|
||||||
"""Include devices of type Positioner in filters."""
|
"""Include devices of type Positioner in filters."""
|
||||||
return BECDeviceFilter.POSITIONER in self.device_filter
|
return BECDeviceFilter.POSITIONER in self.device_filter
|
||||||
@ -213,7 +213,7 @@ class DeviceInputBase(BECWidget):
|
|||||||
self._device_filter.remove(BECDeviceFilter.POSITIONER)
|
self._device_filter.remove(BECDeviceFilter.POSITIONER)
|
||||||
self.update_devices_from_filters()
|
self.update_devices_from_filters()
|
||||||
|
|
||||||
@Property(bool)
|
@SafeProperty(bool)
|
||||||
def filter_to_signal(self):
|
def filter_to_signal(self):
|
||||||
"""Include devices of type Signal in filters."""
|
"""Include devices of type Signal in filters."""
|
||||||
return BECDeviceFilter.SIGNAL in self.device_filter
|
return BECDeviceFilter.SIGNAL in self.device_filter
|
||||||
@ -226,7 +226,7 @@ class DeviceInputBase(BECWidget):
|
|||||||
self._device_filter.remove(BECDeviceFilter.SIGNAL)
|
self._device_filter.remove(BECDeviceFilter.SIGNAL)
|
||||||
self.update_devices_from_filters()
|
self.update_devices_from_filters()
|
||||||
|
|
||||||
@Property(bool)
|
@SafeProperty(bool)
|
||||||
def filter_to_computed_signal(self):
|
def filter_to_computed_signal(self):
|
||||||
"""Include devices of type ComputedSignal in filters."""
|
"""Include devices of type ComputedSignal in filters."""
|
||||||
return BECDeviceFilter.COMPUTED_SIGNAL in self.device_filter
|
return BECDeviceFilter.COMPUTED_SIGNAL in self.device_filter
|
||||||
@ -239,7 +239,7 @@ class DeviceInputBase(BECWidget):
|
|||||||
self._device_filter.remove(BECDeviceFilter.COMPUTED_SIGNAL)
|
self._device_filter.remove(BECDeviceFilter.COMPUTED_SIGNAL)
|
||||||
self.update_devices_from_filters()
|
self.update_devices_from_filters()
|
||||||
|
|
||||||
@Property(bool)
|
@SafeProperty(bool)
|
||||||
def readout_monitored(self):
|
def readout_monitored(self):
|
||||||
"""Include devices with readout priority Monitored in filters."""
|
"""Include devices with readout priority Monitored in filters."""
|
||||||
return ReadoutPriority.MONITORED in self.readout_filter
|
return ReadoutPriority.MONITORED in self.readout_filter
|
||||||
@ -252,7 +252,7 @@ class DeviceInputBase(BECWidget):
|
|||||||
self._readout_filter.remove(ReadoutPriority.MONITORED)
|
self._readout_filter.remove(ReadoutPriority.MONITORED)
|
||||||
self.update_devices_from_filters()
|
self.update_devices_from_filters()
|
||||||
|
|
||||||
@Property(bool)
|
@SafeProperty(bool)
|
||||||
def readout_baseline(self):
|
def readout_baseline(self):
|
||||||
"""Include devices with readout priority Baseline in filters."""
|
"""Include devices with readout priority Baseline in filters."""
|
||||||
return ReadoutPriority.BASELINE in self.readout_filter
|
return ReadoutPriority.BASELINE in self.readout_filter
|
||||||
@ -265,7 +265,7 @@ class DeviceInputBase(BECWidget):
|
|||||||
self._readout_filter.remove(ReadoutPriority.BASELINE)
|
self._readout_filter.remove(ReadoutPriority.BASELINE)
|
||||||
self.update_devices_from_filters()
|
self.update_devices_from_filters()
|
||||||
|
|
||||||
@Property(bool)
|
@SafeProperty(bool)
|
||||||
def readout_async(self):
|
def readout_async(self):
|
||||||
"""Include devices with readout priority Async in filters."""
|
"""Include devices with readout priority Async in filters."""
|
||||||
return ReadoutPriority.ASYNC in self.readout_filter
|
return ReadoutPriority.ASYNC in self.readout_filter
|
||||||
@ -278,7 +278,7 @@ class DeviceInputBase(BECWidget):
|
|||||||
self._readout_filter.remove(ReadoutPriority.ASYNC)
|
self._readout_filter.remove(ReadoutPriority.ASYNC)
|
||||||
self.update_devices_from_filters()
|
self.update_devices_from_filters()
|
||||||
|
|
||||||
@Property(bool)
|
@SafeProperty(bool)
|
||||||
def readout_continuous(self):
|
def readout_continuous(self):
|
||||||
"""Include devices with readout priority continuous in filters."""
|
"""Include devices with readout priority continuous in filters."""
|
||||||
return ReadoutPriority.CONTINUOUS in self.readout_filter
|
return ReadoutPriority.CONTINUOUS in self.readout_filter
|
||||||
@ -291,7 +291,7 @@ class DeviceInputBase(BECWidget):
|
|||||||
self._readout_filter.remove(ReadoutPriority.CONTINUOUS)
|
self._readout_filter.remove(ReadoutPriority.CONTINUOUS)
|
||||||
self.update_devices_from_filters()
|
self.update_devices_from_filters()
|
||||||
|
|
||||||
@Property(bool)
|
@SafeProperty(bool)
|
||||||
def readout_on_request(self):
|
def readout_on_request(self):
|
||||||
"""Include devices with readout priority OnRequest in filters."""
|
"""Include devices with readout priority OnRequest in filters."""
|
||||||
return ReadoutPriority.ON_REQUEST in self.readout_filter
|
return ReadoutPriority.ON_REQUEST in self.readout_filter
|
||||||
|
Reference in New Issue
Block a user