bec-widgets 0.46.4__py3-none-any.whl → 0.46.6__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.
@@ -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)
@@ -82,8 +93,9 @@ def update_script(figure: BECFigure, msg):
82
93
  print(f"Scan {scan_number} is running")
83
94
  dev_x = scan_report_devices[0]
84
95
  dev_y = scan_report_devices[1]
96
+ dev_z = get_selected_device(monitored_devices, figure.selected_device)
85
97
  figure.clear_all()
86
- plt = figure.plot(dev_x, dev_y, label=f"Scan {scan_number}")
98
+ plt = figure.plot(dev_x, dev_y, dev_z, label=f"Scan {scan_number}")
87
99
  plt.set(title=f"Scan {scan_number}", x_label=dev_x, y_label=dev_y)
88
100
  elif scan_report_devices:
89
101
  dev_x = scan_report_devices[0]
File without changes
@@ -0,0 +1,102 @@
1
+ import os
2
+
3
+ import numpy as np
4
+ import pyqtgraph as pg
5
+ from pyqtgraph.Qt import uic
6
+ from qtconsole.inprocess import QtInProcessKernelManager
7
+ from qtconsole.rich_jupyter_widget import RichJupyterWidget
8
+ from qtpy.QtWidgets import QApplication, QVBoxLayout, QWidget
9
+
10
+ from bec_widgets.utils import BECDispatcher
11
+ from bec_widgets.widgets import BECFigure
12
+
13
+
14
+ class JupyterConsoleWidget(RichJupyterWidget): # pragma: no cover:
15
+ def __init__(self):
16
+ super().__init__()
17
+
18
+ self.kernel_manager = QtInProcessKernelManager()
19
+ self.kernel_manager.start_kernel(show_banner=False)
20
+ self.kernel_client = self.kernel_manager.client()
21
+ self.kernel_client.start_channels()
22
+
23
+ self.kernel_manager.kernel.shell.push({"np": np, "pg": pg})
24
+ # self.set_console_font_size(70)
25
+
26
+ def shutdown_kernel(self):
27
+ self.kernel_client.stop_channels()
28
+ self.kernel_manager.shutdown_kernel()
29
+
30
+
31
+ class JupyterConsoleWindow(QWidget): # pragma: no cover:
32
+ """A widget that contains a Jupyter console linked to BEC Widgets with full API access (contains Qt and pyqtgraph API)."""
33
+
34
+ def __init__(self, parent=None):
35
+ super().__init__(parent)
36
+
37
+ current_path = os.path.dirname(__file__)
38
+ uic.loadUi(os.path.join(current_path, "jupyter_console_window.ui"), self)
39
+
40
+ self._init_ui()
41
+
42
+ self.splitter.setSizes([200, 100])
43
+ self.safe_close = False
44
+ # self.figure.clean_signal.connect(self.confirm_close)
45
+
46
+ # console push
47
+ self.console.kernel_manager.kernel.shell.push(
48
+ {
49
+ "fig": self.figure,
50
+ "w1": self.w1,
51
+ "w2": self.w2,
52
+ "w3": self.w3,
53
+ "bec": self.figure.client,
54
+ "scans": self.figure.client.scans,
55
+ "dev": self.figure.client.device_manager.devices,
56
+ }
57
+ )
58
+
59
+ def _init_ui(self):
60
+ # Plotting window
61
+ self.glw_1_layout = QVBoxLayout(self.glw) # Create a new QVBoxLayout
62
+ self.figure = BECFigure(parent=self, gui_id="remote") # Create a new BECDeviceMonitor
63
+ self.glw_1_layout.addWidget(self.figure) # Add BECDeviceMonitor to the layout
64
+
65
+ # add stuff to figure
66
+ self._init_figure()
67
+
68
+ self.console_layout = QVBoxLayout(self.widget_console)
69
+ self.console = JupyterConsoleWidget()
70
+ self.console_layout.addWidget(self.console)
71
+ self.console.set_default_style("linux")
72
+
73
+ def _init_figure(self):
74
+ self.figure.plot("samx", "bpm4d")
75
+ self.figure.motor_map("samx", "samy")
76
+ self.figure.image("eiger", color_map="viridis", vrange=(0, 100))
77
+
78
+ self.figure.change_layout(2, 2)
79
+
80
+ self.w1 = self.figure[0, 0]
81
+ self.w2 = self.figure[0, 1]
82
+ self.w3 = self.figure[1, 0]
83
+
84
+ # curves for w1
85
+ self.w1.add_curve_scan("samx", "samy", "bpm4i", pen_style="dash")
86
+ self.w1.add_curve_scan("samx", "samy", "bpm3a", pen_style="dash")
87
+ self.c1 = self.w1.get_config()
88
+
89
+
90
+ if __name__ == "__main__": # pragma: no cover
91
+ import sys
92
+
93
+ bec_dispatcher = BECDispatcher()
94
+ client = bec_dispatcher.client
95
+ client.start()
96
+
97
+ app = QApplication(sys.argv)
98
+ app.setApplicationName("Jupyter Console")
99
+ win = JupyterConsoleWindow()
100
+ win.show()
101
+
102
+ sys.exit(app.exec_())
@@ -227,7 +227,7 @@ class BECFigure(BECConnector, pg.GraphicsLayoutWidget):
227
227
  y_entry=y_entry,
228
228
  z_entry=z_entry,
229
229
  color=color,
230
- color_map=color_map_z,
230
+ color_map_z=color_map_z,
231
231
  label=label,
232
232
  validate=validate,
233
233
  )
@@ -313,7 +313,7 @@ class BECFigure(BECConnector, pg.GraphicsLayoutWidget):
313
313
  y_entry=y_entry,
314
314
  z_entry=z_entry,
315
315
  color=color,
316
- color_map=color_map_z,
316
+ color_map_z=color_map_z,
317
317
  label=label,
318
318
  validate=validate,
319
319
  )
@@ -787,8 +787,8 @@ class BECFigure(BECConnector, pg.GraphicsLayoutWidget):
787
787
 
788
788
  def clear_all(self):
789
789
  """Clear all widgets from the figure and reset to default state"""
790
- for widget in self._widgets.values():
791
- widget.cleanup()
790
+ # for widget in self._widgets.values():
791
+ # widget.cleanup()
792
792
  self.clear()
793
793
  self._widgets = defaultdict(dict)
794
794
  self.grid = []
@@ -796,103 +796,3 @@ class BECFigure(BECConnector, pg.GraphicsLayoutWidget):
796
796
  self.config = FigureConfig(
797
797
  widget_class=self.__class__.__name__, gui_id=self.gui_id, theme=theme
798
798
  )
799
-
800
-
801
- ##################################################
802
- ##################################################
803
- # Debug window
804
- ##################################################
805
- ##################################################
806
-
807
- from qtconsole.inprocess import QtInProcessKernelManager
808
- from qtconsole.rich_jupyter_widget import RichJupyterWidget
809
-
810
-
811
- class JupyterConsoleWidget(RichJupyterWidget): # pragma: no cover:
812
- def __init__(self):
813
- super().__init__()
814
-
815
- self.kernel_manager = QtInProcessKernelManager()
816
- self.kernel_manager.start_kernel(show_banner=False)
817
- self.kernel_client = self.kernel_manager.client()
818
- self.kernel_client.start_channels()
819
-
820
- self.kernel_manager.kernel.shell.push({"np": np, "pg": pg})
821
- # self.set_console_font_size(70)
822
-
823
- def shutdown_kernel(self):
824
- self.kernel_client.stop_channels()
825
- self.kernel_manager.shutdown_kernel()
826
-
827
-
828
- class DebugWindow(QWidget): # pragma: no cover:
829
- """Debug window for BEC widgets"""
830
-
831
- def __init__(self, parent=None):
832
- super().__init__(parent)
833
-
834
- current_path = os.path.dirname(__file__)
835
- uic.loadUi(os.path.join(current_path, "figure_debug_minimal.ui"), self)
836
-
837
- self._init_ui()
838
-
839
- self.splitter.setSizes([200, 100])
840
- self.safe_close = False
841
- # self.figure.clean_signal.connect(self.confirm_close)
842
-
843
- # console push
844
- self.console.kernel_manager.kernel.shell.push(
845
- {
846
- "fig": self.figure,
847
- "w1": self.w1,
848
- "w2": self.w2,
849
- "w3": self.w3,
850
- "bec": self.figure.client,
851
- "scans": self.figure.client.scans,
852
- "dev": self.figure.client.device_manager.devices,
853
- }
854
- )
855
-
856
- def _init_ui(self):
857
- # Plotting window
858
- self.glw_1_layout = QVBoxLayout(self.glw) # Create a new QVBoxLayout
859
- self.figure = BECFigure(parent=self, gui_id="remote") # Create a new BECDeviceMonitor
860
- self.glw_1_layout.addWidget(self.figure) # Add BECDeviceMonitor to the layout
861
-
862
- # add stuff to figure
863
- self._init_figure()
864
-
865
- self.console_layout = QVBoxLayout(self.widget_console)
866
- self.console = JupyterConsoleWidget()
867
- self.console_layout.addWidget(self.console)
868
- self.console.set_default_style("linux")
869
-
870
- def _init_figure(self):
871
- self.figure.plot("samx", "bpm4d")
872
- self.figure.motor_map("samx", "samy")
873
- self.figure.image("eiger", color_map="viridis", vrange=(0, 100))
874
-
875
- self.figure.change_layout(2, 2)
876
-
877
- self.w1 = self.figure[0, 0]
878
- self.w2 = self.figure[0, 1]
879
- self.w3 = self.figure[1, 0]
880
-
881
- # curves for w1
882
- self.w1.add_curve_scan("samx", "samy", "bpm4i", pen_style="dash")
883
- self.w1.add_curve_scan("samx", "samy", "bpm3a", pen_style="dash")
884
- self.c1 = self.w1.get_config()
885
-
886
-
887
- if __name__ == "__main__": # pragma: no cover
888
- import sys
889
-
890
- bec_dispatcher = BECDispatcher()
891
- client = bec_dispatcher.client
892
- client.start()
893
-
894
- app = QApplication(sys.argv)
895
- win = DebugWindow()
896
- win.show()
897
-
898
- sys.exit(app.exec_())
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: bec-widgets
3
- Version: 0.46.4
3
+ Version: 0.46.6
4
4
  Summary: BEC Widgets
5
5
  Home-page: https://gitlab.psi.ch/bec/bec-widgets
6
6
  Project-URL: Bug Tracker, https://gitlab.psi.ch/bec/bec-widgets/issues
@@ -1,13 +1,16 @@
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=KpC9rSwXO3gQMTTxtuvnFPSOq3IvLw-sryqxVGt7Xqw,10437
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
8
8
  bec_widgets/examples/eiger_plot/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
9
9
  bec_widgets/examples/eiger_plot/eiger_plot.py,sha256=Uxl2Usf8jEzaX7AT8zVqa1x8ZIEgI1HmazSlb-tRFWE,10359
10
10
  bec_widgets/examples/eiger_plot/eiger_plot.ui,sha256=grHfnO3OG_lelJhdRsnA0badCvRdDunPrIMIyNQ5N-w,5809
11
+ bec_widgets/examples/jupyter_console/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
12
+ bec_widgets/examples/jupyter_console/jupyter_console_window.py,sha256=MW9PCM4-UileXxMMDV2LxUsdxdTf2zPavhA4QxqoBxk,3323
13
+ bec_widgets/examples/jupyter_console/jupyter_console_window.ui,sha256=GodXBvBvs5QAUsHbo3pcxR4o51Tvce4DTqpTluk3hOs,742
11
14
  bec_widgets/examples/mca_readout/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
12
15
  bec_widgets/examples/mca_readout/mca_plot.py,sha256=do7mSK_nzHtojRiMi8JoN_Rckg9yfjYYWz2S_Nl3xbE,5079
13
16
  bec_widgets/examples/mca_readout/mca_sim.py,sha256=yiX_3sOgDZIbAYA4D2BGmOgLMBWbQMOej0hSP4cQd0o,754
@@ -40,8 +43,7 @@ bec_widgets/widgets/__init__.py,sha256=GptryTiWJ4yWZZVBG_03guISJabSOzVpOMRkgW0Ld
40
43
  bec_widgets/widgets/editor/__init__.py,sha256=5mBdFYi_IpygCz81kbLEZUWhd1b6oqiO3nASejuV_ug,30
41
44
  bec_widgets/widgets/editor/editor.py,sha256=pIIYLPqqqhXqT11Xj10cyGEiy-ieNGE4ZujN5lf0e68,15110
42
45
  bec_widgets/widgets/figure/__init__.py,sha256=3hGx_KOV7QHCYAV06aNuUgKq4QIYCjUTad-DrwkUaBM,44
43
- bec_widgets/widgets/figure/figure.py,sha256=wG4nSl_SPezpKuLKFLTF-Ucmm9zsFru6X9g--9ivE7M,32487
44
- bec_widgets/widgets/figure/figure_debug_minimal.ui,sha256=GodXBvBvs5QAUsHbo3pcxR4o51Tvce4DTqpTluk3hOs,742
46
+ bec_widgets/widgets/figure/figure.py,sha256=jqCGT7Abri74Da_4lEbUyDh4-CltiGLuM-2nu82ibDQ,29335
45
47
  bec_widgets/widgets/monitor/__init__.py,sha256=afXuZcBOxNAuYdCkIQXX5J60R5A3Q_86lNEW2vpFtPI,32
46
48
  bec_widgets/widgets/monitor/config_dialog.py,sha256=Z1a4WRIVlfEGdwC-QG25kba2EHCZWi5J843tBVZlWiI,20275
47
49
  bec_widgets/widgets/monitor/config_dialog.ui,sha256=ISMcF7CLTAMXhfZh2Yv5yezzAjMtb9fxY1pmX4B_jCg,5932
@@ -73,6 +75,7 @@ tests/unit_tests/test_bec_dispatcher.py,sha256=MtNyfC7-Y4na-Fwf1ny9raHBqE45eSnQN
73
75
  tests/unit_tests/test_bec_figure.py,sha256=T4k-E1D3sjTTDTFZGdTFDQv0EYNQ_R-QbWOM7pQwFw4,7926
74
76
  tests/unit_tests/test_bec_monitor.py,sha256=mN7gBY7oXY6j65zzihpy8r-FvwVoCQlie3F6SoVq0mo,7042
75
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
76
79
  tests/unit_tests/test_config_dialog.py,sha256=5uNGcpvrx8qDdMwFCTXr8HMzFZF4rFi-ZHoDpMxGMf8,6955
77
80
  tests/unit_tests/test_crosshair.py,sha256=d7fX-ymboZPALNqqiAj86PZ96llmGZ_3jf0yjVP0S94,5039
78
81
  tests/unit_tests/test_editor.py,sha256=TED5k1xFJHRZ4KDAg2VxSRu_hMJnra-lbAmVwsDicsM,6784
@@ -89,8 +92,8 @@ tests/unit_tests/test_widget_io.py,sha256=FeL3ZYSBQnRt6jxj8VGYw1cmcicRQyHKleahw7
89
92
  tests/unit_tests/test_yaml_dialog.py,sha256=HNrqferkdg02-9ieOhhI2mr2Qvt7GrYgXmQ061YCTbg,5794
90
93
  tests/unit_tests/test_msgs/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
91
94
  tests/unit_tests/test_msgs/available_scans_message.py,sha256=m_z97hIrjHXXMa2Ex-UvsPmTxOYXfjxyJaGkIY6StTY,46532
92
- bec_widgets-0.46.4.dist-info/LICENSE,sha256=YRKe85CBRyP7UpEAWwU8_qSIyuy5-l_9C-HKg5Qm8MQ,1511
93
- bec_widgets-0.46.4.dist-info/METADATA,sha256=uahRMbNnY6SHjDVtXPrrsxICHZdsTayTZLeyUUu1u9w,3714
94
- bec_widgets-0.46.4.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
95
- bec_widgets-0.46.4.dist-info/top_level.txt,sha256=EXCwhJYmXmd1DjYYL3hrGsddX-97IwYSiIHrf27FFVk,18
96
- bec_widgets-0.46.4.dist-info/RECORD,,
95
+ bec_widgets-0.46.6.dist-info/LICENSE,sha256=YRKe85CBRyP7UpEAWwU8_qSIyuy5-l_9C-HKg5Qm8MQ,1511
96
+ bec_widgets-0.46.6.dist-info/METADATA,sha256=b8I7vt8YPo-TpWiWV8Jh1-YABgTVjf-JD-UKyYWyZW8,3714
97
+ bec_widgets-0.46.6.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
98
+ bec_widgets-0.46.6.dist-info/top_level.txt,sha256=EXCwhJYmXmd1DjYYL3hrGsddX-97IwYSiIHrf27FFVk,18
99
+ bec_widgets-0.46.6.dist-info/RECORD,,
@@ -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")