bec-widgets 0.46.5__py3-none-any.whl → 0.46.7__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- bec_widgets/cli/client_utils.py +11 -0
- bec_widgets/utils/entry_validator.py +23 -0
- bec_widgets/widgets/plots/image.py +22 -2
- {bec_widgets-0.46.5.dist-info → bec_widgets-0.46.7.dist-info}/METADATA +1 -1
- {bec_widgets-0.46.5.dist-info → bec_widgets-0.46.7.dist-info}/RECORD +10 -9
- tests/unit_tests/client_mocks.py +1 -0
- tests/unit_tests/test_client_utils.py +29 -0
- {bec_widgets-0.46.5.dist-info → bec_widgets-0.46.7.dist-info}/LICENSE +0 -0
- {bec_widgets-0.46.5.dist-info → bec_widgets-0.46.7.dist-info}/WHEEL +0 -0
- {bec_widgets-0.46.5.dist-info → bec_widgets-0.46.7.dist-info}/top_level.txt +0 -0
bec_widgets/cli/client_utils.py
CHANGED
@@ -36,6 +36,17 @@ def rpc_call(func):
|
|
36
36
|
|
37
37
|
@wraps(func)
|
38
38
|
def wrapper(self, *args, **kwargs):
|
39
|
+
# we could rely on a strict type check here, but this is more flexible
|
40
|
+
# moreover, it would anyway crash for objects...
|
41
|
+
out = []
|
42
|
+
for arg in args:
|
43
|
+
if hasattr(arg, "name"):
|
44
|
+
arg = arg.name
|
45
|
+
out.append(arg)
|
46
|
+
args = tuple(out)
|
47
|
+
for key, val in kwargs.items():
|
48
|
+
if hasattr(val, "name"):
|
49
|
+
kwargs[key] = val.name
|
39
50
|
if not self.gui_is_alive():
|
40
51
|
raise RuntimeError("GUI is not alive")
|
41
52
|
return self._run_rpc(func.__name__, *args, **kwargs)
|
@@ -3,6 +3,15 @@ class EntryValidator:
|
|
3
3
|
self.devices = devices
|
4
4
|
|
5
5
|
def validate_signal(self, name: str, entry: str = None) -> str:
|
6
|
+
"""
|
7
|
+
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.
|
8
|
+
Args:
|
9
|
+
name(str): Device name
|
10
|
+
entry(str): Signal entry
|
11
|
+
|
12
|
+
Returns:
|
13
|
+
str: Signal entry
|
14
|
+
"""
|
6
15
|
if name not in self.devices:
|
7
16
|
raise ValueError(f"Device '{name}' not found in current BEC session")
|
8
17
|
|
@@ -15,3 +24,17 @@ class EntryValidator:
|
|
15
24
|
raise ValueError(f"Entry '{entry}' not found in device '{name}' signals")
|
16
25
|
|
17
26
|
return entry
|
27
|
+
|
28
|
+
def validate_monitor(self, monitor: str) -> str:
|
29
|
+
"""
|
30
|
+
Validate a monitor entry for a given device.
|
31
|
+
Args:
|
32
|
+
monitor(str): Monitor entry
|
33
|
+
|
34
|
+
Returns:
|
35
|
+
str: Monitor entry
|
36
|
+
"""
|
37
|
+
if monitor not in self.devices:
|
38
|
+
raise ValueError(f"Device '{monitor}' not found in current BEC session")
|
39
|
+
|
40
|
+
return monitor
|
@@ -12,7 +12,7 @@ from qtpy.QtCore import Signal as pyqtSignal
|
|
12
12
|
from qtpy.QtCore import Slot as pyqtSlot
|
13
13
|
from qtpy.QtWidgets import QWidget
|
14
14
|
|
15
|
-
from bec_widgets.utils import BECConnector, ConnectionConfig
|
15
|
+
from bec_widgets.utils import BECConnector, ConnectionConfig, EntryValidator
|
16
16
|
|
17
17
|
from .plot_base import BECPlotBase, WidgetConfig
|
18
18
|
|
@@ -335,7 +335,9 @@ class BECImageShow(BECPlotBase):
|
|
335
335
|
super().__init__(
|
336
336
|
parent=parent, parent_figure=parent_figure, config=config, client=client, gui_id=gui_id
|
337
337
|
)
|
338
|
-
|
338
|
+
# Get bec shortcuts dev, scans, queue, scan_storage, dap
|
339
|
+
self.get_bec_shortcuts()
|
340
|
+
self.entry_validator = EntryValidator(self.dev)
|
339
341
|
self._images = defaultdict(dict)
|
340
342
|
self.apply_config(self.config)
|
341
343
|
self.processor = ImageProcessor()
|
@@ -507,6 +509,8 @@ class BECImageShow(BECPlotBase):
|
|
507
509
|
f"Monitor with ID '{monitor}' already exists in widget '{self.gui_id}'."
|
508
510
|
)
|
509
511
|
|
512
|
+
monitor = self.entry_validator.validate_monitor(monitor)
|
513
|
+
|
510
514
|
image_config = ImageItemConfig(
|
511
515
|
widget_class="BECImageItem",
|
512
516
|
parent_id=self.gui_id,
|
@@ -785,6 +789,22 @@ class BECImageShow(BECPlotBase):
|
|
785
789
|
return True
|
786
790
|
return False
|
787
791
|
|
792
|
+
def _validate_monitor(self, monitor: str, validate_bec: bool = True):
|
793
|
+
"""
|
794
|
+
Validate the monitor name.
|
795
|
+
Args:
|
796
|
+
monitor(str): The name of the monitor.
|
797
|
+
validate_bec(bool): Whether to validate the monitor name with BEC.
|
798
|
+
|
799
|
+
Returns:
|
800
|
+
bool: True if the monitor name is valid, False otherwise.
|
801
|
+
"""
|
802
|
+
if not monitor or monitor == "":
|
803
|
+
return False
|
804
|
+
if validate_bec:
|
805
|
+
return monitor in self.dev
|
806
|
+
return True
|
807
|
+
|
788
808
|
def cleanup(self):
|
789
809
|
"""
|
790
810
|
Clean up the widget.
|
@@ -1,7 +1,7 @@
|
|
1
1
|
bec_widgets/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
2
2
|
bec_widgets/cli/__init__.py,sha256=yFyAmDteCcndbReunhnrfDib6JujQ7-BKWeVvuU0Ylw,30
|
3
3
|
bec_widgets/cli/client.py,sha256=4QedDVBgkCOnRQFYQcAabyAsl5UQ0aRwwLwk1OR5M1k,37882
|
4
|
-
bec_widgets/cli/client_utils.py,sha256=
|
4
|
+
bec_widgets/cli/client_utils.py,sha256=zsFHcE75IWoPKh5NCawUVbE20_o_7ggPWkj7_49-Bns,10939
|
5
5
|
bec_widgets/cli/generate_cli.py,sha256=JLqUlUgfz_f_4KHPRUAN-Xli-K7uNOc8-F-LkAC7Scw,4004
|
6
6
|
bec_widgets/cli/server.py,sha256=OMWnl99RrSTKK1EVEyu3MFjkJ54bWfh_fpg38b-bres,4760
|
7
7
|
bec_widgets/examples/__init__.py,sha256=WWQ0cu7m8sA4Ehy-DWdTIqSISjaHsbxhsNmNrMnhDZU,202
|
@@ -32,7 +32,7 @@ bec_widgets/utils/bec_table.py,sha256=Xy5qM343K8EvEpB4g_129b63yo1wdEvEY3wqxB_p_I
|
|
32
32
|
bec_widgets/utils/colors.py,sha256=JsLxzkxbw-I8GIuvnIKyiM83n0edhyMG2Fa4Ffm62ww,2392
|
33
33
|
bec_widgets/utils/crosshair.py,sha256=5gG4G6jjtp6Bd1Y5EySHP2EkmtR4mYdxLCgVtx9fokE,9406
|
34
34
|
bec_widgets/utils/ctrl_c.py,sha256=NMJlPDZcuqMUGykyhuZY5Ibed4yRI1K_uh16z2MmlXQ,1198
|
35
|
-
bec_widgets/utils/entry_validator.py,sha256=
|
35
|
+
bec_widgets/utils/entry_validator.py,sha256=88OpJqaldMjiaEk7F9rRcwPuCOTLCzXmAlSEL-_7iXU,1296
|
36
36
|
bec_widgets/utils/rpc_decorator.py,sha256=pIvtqySQLnuS7l2Ti_UAe4WX7CRivZnsE5ZdKAihxh0,479
|
37
37
|
bec_widgets/utils/validator_delegate.py,sha256=Emj1WF6W8Ke1ruBWUfmHdVJpmOSPezuOt4zvQTay_44,442
|
38
38
|
bec_widgets/utils/widget_io.py,sha256=JKl508VnqQSxcaHqKaoBQ1TWSOm3pXhxQGx7iF_pRA0,10875
|
@@ -58,7 +58,7 @@ bec_widgets/widgets/motor_control/motor_control_table.ui,sha256=t6aRKiSmutMfp0Ay
|
|
58
58
|
bec_widgets/widgets/motor_map/__init__.py,sha256=K3c-3A_LbxK0UJ0_bV3opL-wGLTwBLendsJXsg8GAqE,32
|
59
59
|
bec_widgets/widgets/motor_map/motor_map.py,sha256=vJlLWa0BXv5KMZ7UVT0q3I1I5CXgsDiXoM_ptsAsG3c,21860
|
60
60
|
bec_widgets/widgets/plots/__init__.py,sha256=kGQTORTr-2M9vmVCK-T7AFre4bY5LVVzGxcIzT81-ZU,237
|
61
|
-
bec_widgets/widgets/plots/image.py,sha256=
|
61
|
+
bec_widgets/widgets/plots/image.py,sha256=jgKl9BVu9FGqCHkij4gbV12pYugTwyQVhd-Y_TXEvbE,33005
|
62
62
|
bec_widgets/widgets/plots/motor_map.py,sha256=Uitx080FEyCDCTYHfBt0Ah-98QD4J5nSNZ628lu7EOg,15386
|
63
63
|
bec_widgets/widgets/plots/plot_base.py,sha256=xuNA4S5lwWiYXHT60XklWX09KiwqbrRiDr4J_iDXkes,8447
|
64
64
|
bec_widgets/widgets/plots/waveform.py,sha256=aUaWPg5NL0HoGqEs3Yo5nXEg_qy31C5ZwaOAwIoiqcs,28528
|
@@ -68,13 +68,14 @@ bec_widgets/widgets/toolbar/__init__.py,sha256=d-TP4_cr_VbpwreMM4ePnfZ5YXsEPQ45i
|
|
68
68
|
bec_widgets/widgets/toolbar/toolbar.py,sha256=sxz7rbc8XNPS6n2WMObF4-2PqdYfPxVtsOZEGV6mqa0,5124
|
69
69
|
tests/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
70
70
|
tests/unit_tests/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
71
|
-
tests/unit_tests/client_mocks.py,sha256=
|
71
|
+
tests/unit_tests/client_mocks.py,sha256=LNUgI9Ccv5Ol7_pmybIhoVqZZem1RPIsTDk7ZTARNls,4128
|
72
72
|
tests/unit_tests/conftest.py,sha256=roLbKZ1thm2Bd-5zEtL-eRBB5TTs36sAqXTUdHYYqSw,433
|
73
73
|
tests/unit_tests/test_bec_connector.py,sha256=f2XXGGw3NoZLIUrDuZuEWwF_ttOYmmquCgUrV5XkIOY,1951
|
74
74
|
tests/unit_tests/test_bec_dispatcher.py,sha256=MtNyfC7-Y4na-Fwf1ny9raHBqE45eSnQNWSqqAx79FU,1857
|
75
75
|
tests/unit_tests/test_bec_figure.py,sha256=T4k-E1D3sjTTDTFZGdTFDQv0EYNQ_R-QbWOM7pQwFw4,7926
|
76
76
|
tests/unit_tests/test_bec_monitor.py,sha256=mN7gBY7oXY6j65zzihpy8r-FvwVoCQlie3F6SoVq0mo,7042
|
77
77
|
tests/unit_tests/test_bec_motor_map.py,sha256=IXSfitUGxOPqmngwVNPK5nwi2QDcXWjBkGNb0dBZDxQ,4611
|
78
|
+
tests/unit_tests/test_client_utils.py,sha256=fIApd5WgnJuyIzV-hdSABn6T-aOel2Wr2xuUX4Z651A,774
|
78
79
|
tests/unit_tests/test_config_dialog.py,sha256=5uNGcpvrx8qDdMwFCTXr8HMzFZF4rFi-ZHoDpMxGMf8,6955
|
79
80
|
tests/unit_tests/test_crosshair.py,sha256=d7fX-ymboZPALNqqiAj86PZ96llmGZ_3jf0yjVP0S94,5039
|
80
81
|
tests/unit_tests/test_editor.py,sha256=TED5k1xFJHRZ4KDAg2VxSRu_hMJnra-lbAmVwsDicsM,6784
|
@@ -91,8 +92,8 @@ tests/unit_tests/test_widget_io.py,sha256=FeL3ZYSBQnRt6jxj8VGYw1cmcicRQyHKleahw7
|
|
91
92
|
tests/unit_tests/test_yaml_dialog.py,sha256=HNrqferkdg02-9ieOhhI2mr2Qvt7GrYgXmQ061YCTbg,5794
|
92
93
|
tests/unit_tests/test_msgs/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
93
94
|
tests/unit_tests/test_msgs/available_scans_message.py,sha256=m_z97hIrjHXXMa2Ex-UvsPmTxOYXfjxyJaGkIY6StTY,46532
|
94
|
-
bec_widgets-0.46.
|
95
|
-
bec_widgets-0.46.
|
96
|
-
bec_widgets-0.46.
|
97
|
-
bec_widgets-0.46.
|
98
|
-
bec_widgets-0.46.
|
95
|
+
bec_widgets-0.46.7.dist-info/LICENSE,sha256=YRKe85CBRyP7UpEAWwU8_qSIyuy5-l_9C-HKg5Qm8MQ,1511
|
96
|
+
bec_widgets-0.46.7.dist-info/METADATA,sha256=6bFYin3A53Lg5KDhLSLl80UEGsyHQCD8qC_yZw-P9ZE,3714
|
97
|
+
bec_widgets-0.46.7.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
|
98
|
+
bec_widgets-0.46.7.dist-info/top_level.txt,sha256=EXCwhJYmXmd1DjYYL3hrGsddX-97IwYSiIHrf27FFVk,18
|
99
|
+
bec_widgets-0.46.7.dist-info/RECORD,,
|
tests/unit_tests/client_mocks.py
CHANGED
@@ -0,0 +1,29 @@
|
|
1
|
+
from unittest import mock
|
2
|
+
|
3
|
+
import pytest
|
4
|
+
|
5
|
+
from bec_widgets.cli.client import BECFigure
|
6
|
+
|
7
|
+
from .client_mocks import FakeDevice
|
8
|
+
|
9
|
+
|
10
|
+
@pytest.fixture
|
11
|
+
def cli_figure():
|
12
|
+
fig = BECFigure(gui_id="test")
|
13
|
+
with mock.patch.object(fig, "_run_rpc") as mock_rpc_call:
|
14
|
+
with mock.patch.object(fig, "gui_is_alive", return_value=True):
|
15
|
+
yield fig, mock_rpc_call
|
16
|
+
|
17
|
+
|
18
|
+
def test_rpc_call_plot(cli_figure):
|
19
|
+
fig, mock_rpc_call = cli_figure
|
20
|
+
fig.plot("samx", "bpm4i")
|
21
|
+
mock_rpc_call.assert_called_with("plot", "samx", "bpm4i")
|
22
|
+
|
23
|
+
|
24
|
+
def test_rpc_call_accepts_device_as_input(cli_figure):
|
25
|
+
dev1 = FakeDevice("samx")
|
26
|
+
dev2 = FakeDevice("bpm4i")
|
27
|
+
fig, mock_rpc_call = cli_figure
|
28
|
+
fig.plot(dev1, dev2)
|
29
|
+
mock_rpc_call.assert_called_with("plot", "samx", "bpm4i")
|
File without changes
|
File without changes
|
File without changes
|