From afab283988a1acc008bc53ae5a56a8f67504da81 Mon Sep 17 00:00:00 2001
From: wyzula-jan <133381102+wyzula-jan@users.noreply.github.com>
Date: Fri, 27 Oct 2023 11:48:24 +0200
Subject: [PATCH] fix: device_monitor.py BECDeviceMonitor can be promoted in
the QtDesigner and then setup in the modular app
---
bec_widgets/examples/modular_app/modular.ui | 21 +++++++------
.../examples/modular_app/modular_app.py | 31 ++++++-------------
bec_widgets/widgets/__init__.py | 1 +
bec_widgets/widgets/monitor/device_monitor.py | 17 ++++++----
4 files changed, 32 insertions(+), 38 deletions(-)
diff --git a/bec_widgets/examples/modular_app/modular.ui b/bec_widgets/examples/modular_app/modular.ui
index 0dd3a49d..265c0fd2 100644
--- a/bec_widgets/examples/modular_app/modular.ui
+++ b/bec_widgets/examples/modular_app/modular.ui
@@ -23,7 +23,7 @@
-
-
+
-
@@ -33,7 +33,7 @@
-
-
+
-
@@ -64,7 +64,7 @@
-
-
+
@@ -74,18 +74,19 @@
0
0
1433
- 37
+ 24
-
-
+
+
+ BECDeviceMonitor
+ QGraphicsView
+
+
+
diff --git a/bec_widgets/examples/modular_app/modular_app.py b/bec_widgets/examples/modular_app/modular_app.py
index ec4ff48e..cacf90a1 100644
--- a/bec_widgets/examples/modular_app/modular_app.py
+++ b/bec_widgets/examples/modular_app/modular_app.py
@@ -5,6 +5,7 @@ from PyQt5.QtWidgets import QMainWindow, QApplication, QVBoxLayout
from bec_widgets.widgets.monitor import BECDeviceMonitor
+# some default configs for demonstration purposes
config_1 = {
"plot_settings": {
"background_color": "black",
@@ -184,29 +185,15 @@ class ModularApp(QMainWindow):
self._init_plots()
def _init_plots(self):
- self.glw_1_layout = QVBoxLayout(self.glw_1) # Create a new QVBoxLayout
- self.bec_device_monitor_1 = BECDeviceMonitor(parent=self, config=config_1)
- self.glw_1_layout.addWidget(self.bec_device_monitor_1) # Add BECDeviceMonitor to the layout
- self.pushButton_setting_1.clicked.connect(
- lambda: self.bec_device_monitor_1.show_config_dialog()
- )
+ """Initialize plots and connect the buttons to the config dialogs"""
+ plots = [self.plot_1, self.plot_2, self.plot_3]
+ configs = [config_1, config_2, config_scan_mode]
+ buttons = [self.pushButton_setting_1, self.pushButton_setting_2, self.pushButton_setting_3]
- self.glw_2_layout = QVBoxLayout(self.glw_2) # Create a new QVBoxLayout
- self.bec_device_monitor_2 = BECDeviceMonitor(parent=self, config=config_2)
- self.glw_2_layout.addWidget(self.bec_device_monitor_2) # Add BECDeviceMonitor to the layout
- self.pushButton_setting_2.clicked.connect(
- lambda: self.bec_device_monitor_2.show_config_dialog()
- )
-
- self.glw_3_layout = QVBoxLayout(self.glw_3) # Create a new QVBoxLayout
- self.bec_device_monitor_3 = BECDeviceMonitor(parent=self, config=config_scan_mode)
- self.glw_3_layout.addWidget(self.bec_device_monitor_3) # Add BECDeviceMonitor to the layout
- self.pushButton_setting_3.clicked.connect(
- lambda: self.bec_device_monitor_3.show_config_dialog()
- )
-
- def show_config_dialog(self, monitor):
- monitor.show_config_dialog()
+ # hook plots, configs and buttons together
+ for plot, config, button in zip(plots, configs, buttons):
+ plot.update_config(config)
+ button.clicked.connect(plot.show_config_dialog)
if __name__ == "__main__":
diff --git a/bec_widgets/widgets/__init__.py b/bec_widgets/widgets/__init__.py
index e69de29b..804bdf32 100644
--- a/bec_widgets/widgets/__init__.py
+++ b/bec_widgets/widgets/__init__.py
@@ -0,0 +1 @@
+from .monitor import BECDeviceMonitor
diff --git a/bec_widgets/widgets/monitor/device_monitor.py b/bec_widgets/widgets/monitor/device_monitor.py
index 1beb374f..806b31fa 100644
--- a/bec_widgets/widgets/monitor/device_monitor.py
+++ b/bec_widgets/widgets/monitor/device_monitor.py
@@ -49,9 +49,9 @@ class BECDeviceMonitor(pg.GraphicsLayoutWidget):
update_signal = pyqtSignal()
def __init__(
- self, config: dict = config_simple, client=None, enable_crosshair: bool = False, parent=None
+ self, parent=None, client=None, config: dict = None, enable_crosshair: bool = False
):
- super(BECDeviceMonitor, self).__init__(parent=None)
+ super(BECDeviceMonitor, self).__init__(parent=parent)
# Client and device manager from BEC
self.client = bec_dispatcher.client if client is None else client
@@ -83,9 +83,10 @@ class BECDeviceMonitor(pg.GraphicsLayoutWidget):
)
# Init UI
- self._init_config()
- # self._init_ui() #TODO could be removed
- # self._init_curves()
+ if self.config is None:
+ print("No initial config found for BECDeviceMonitor")
+ else:
+ self.update_config(self.config)
def _init_config(self):
"""
@@ -222,7 +223,7 @@ class BECDeviceMonitor(pg.GraphicsLayoutWidget):
def hook_crosshair(self) -> None:
"""Hook the crosshair to all plots."""
- # TODO can be extendet to hook crosshair signal for mouse move/clicked
+ # TODO can be extended to hook crosshair signal for mouse move/clicked
self.crosshairs = {}
for plot_name, plot in self.plots.items():
crosshair = Crosshair(plot, precision=3)
@@ -255,6 +256,10 @@ class BECDeviceMonitor(pg.GraphicsLayoutWidget):
dialog.config_updated.connect(self.update_config)
dialog.show()
+ def update_client(self, client):
+ self.client = client
+ self.dev = self.client.device_manager.devices
+
@pyqtSlot(dict)
def update_config(self, config):
self.config = config