mirror of
https://github.com/bec-project/bec_widgets.git
synced 2025-07-14 11:41:49 +02:00
fix(plot/image): monitors are now validated with current bec session
This commit is contained in:
@ -3,6 +3,15 @@ class EntryValidator:
|
|||||||
self.devices = devices
|
self.devices = devices
|
||||||
|
|
||||||
def validate_signal(self, name: str, entry: str = None) -> str:
|
def validate_signal(self, name: str, entry: str = None) -> str:
|
||||||
|
"""
|
||||||
|
Validate a signal entry for a given device. If the entry is not provided, the first signal entry will be used from the device hints.
|
||||||
|
Args:
|
||||||
|
name(str): Device name
|
||||||
|
entry(str): Signal entry
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
str: Signal entry
|
||||||
|
"""
|
||||||
if name not in self.devices:
|
if name not in self.devices:
|
||||||
raise ValueError(f"Device '{name}' not found in current BEC session")
|
raise ValueError(f"Device '{name}' not found in current BEC session")
|
||||||
|
|
||||||
@ -15,3 +24,17 @@ class EntryValidator:
|
|||||||
raise ValueError(f"Entry '{entry}' not found in device '{name}' signals")
|
raise ValueError(f"Entry '{entry}' not found in device '{name}' signals")
|
||||||
|
|
||||||
return entry
|
return entry
|
||||||
|
|
||||||
|
def validate_monitor(self, monitor: str) -> str:
|
||||||
|
"""
|
||||||
|
Validate a monitor entry for a given device.
|
||||||
|
Args:
|
||||||
|
monitor(str): Monitor entry
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
str: Monitor entry
|
||||||
|
"""
|
||||||
|
if monitor not in self.devices:
|
||||||
|
raise ValueError(f"Device '{monitor}' not found in current BEC session")
|
||||||
|
|
||||||
|
return monitor
|
||||||
|
@ -12,7 +12,7 @@ from qtpy.QtCore import Signal as pyqtSignal
|
|||||||
from qtpy.QtCore import Slot as pyqtSlot
|
from qtpy.QtCore import Slot as pyqtSlot
|
||||||
from qtpy.QtWidgets import QWidget
|
from qtpy.QtWidgets import QWidget
|
||||||
|
|
||||||
from bec_widgets.utils import BECConnector, ConnectionConfig
|
from bec_widgets.utils import BECConnector, ConnectionConfig, EntryValidator
|
||||||
|
|
||||||
from .plot_base import BECPlotBase, WidgetConfig
|
from .plot_base import BECPlotBase, WidgetConfig
|
||||||
|
|
||||||
@ -335,7 +335,9 @@ class BECImageShow(BECPlotBase):
|
|||||||
super().__init__(
|
super().__init__(
|
||||||
parent=parent, parent_figure=parent_figure, config=config, client=client, gui_id=gui_id
|
parent=parent, parent_figure=parent_figure, config=config, client=client, gui_id=gui_id
|
||||||
)
|
)
|
||||||
|
# Get bec shortcuts dev, scans, queue, scan_storage, dap
|
||||||
|
self.get_bec_shortcuts()
|
||||||
|
self.entry_validator = EntryValidator(self.dev)
|
||||||
self._images = defaultdict(dict)
|
self._images = defaultdict(dict)
|
||||||
self.apply_config(self.config)
|
self.apply_config(self.config)
|
||||||
self.processor = ImageProcessor()
|
self.processor = ImageProcessor()
|
||||||
@ -507,6 +509,8 @@ class BECImageShow(BECPlotBase):
|
|||||||
f"Monitor with ID '{monitor}' already exists in widget '{self.gui_id}'."
|
f"Monitor with ID '{monitor}' already exists in widget '{self.gui_id}'."
|
||||||
)
|
)
|
||||||
|
|
||||||
|
monitor = self.entry_validator.validate_monitor(monitor)
|
||||||
|
|
||||||
image_config = ImageItemConfig(
|
image_config = ImageItemConfig(
|
||||||
widget_class="BECImageItem",
|
widget_class="BECImageItem",
|
||||||
parent_id=self.gui_id,
|
parent_id=self.gui_id,
|
||||||
@ -785,6 +789,22 @@ class BECImageShow(BECPlotBase):
|
|||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
def _validate_monitor(self, monitor: str, validate_bec: bool = True):
|
||||||
|
"""
|
||||||
|
Validate the monitor name.
|
||||||
|
Args:
|
||||||
|
monitor(str): The name of the monitor.
|
||||||
|
validate_bec(bool): Whether to validate the monitor name with BEC.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
bool: True if the monitor name is valid, False otherwise.
|
||||||
|
"""
|
||||||
|
if not monitor or monitor == "":
|
||||||
|
return False
|
||||||
|
if validate_bec:
|
||||||
|
return monitor in self.dev
|
||||||
|
return True
|
||||||
|
|
||||||
def cleanup(self):
|
def cleanup(self):
|
||||||
"""
|
"""
|
||||||
Clean up the widget.
|
Clean up the widget.
|
||||||
|
@ -91,6 +91,7 @@ DEVICES = [
|
|||||||
FakeDevice("bpm4i"),
|
FakeDevice("bpm4i"),
|
||||||
FakeDevice("bpm3a"),
|
FakeDevice("bpm3a"),
|
||||||
FakeDevice("bpm3i"),
|
FakeDevice("bpm3i"),
|
||||||
|
FakeDevice("eiger"),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user