0
0
mirror of https://github.com/bec-project/bec_widgets.git synced 2025-07-14 03:31:50 +02:00

fix: device_monitor.py BECDeviceMonitor can be promoted in the QtDesigner and then setup in the modular app

This commit is contained in:
wyzula-jan
2023-10-27 11:48:24 +02:00
committed by wyzula_j
parent 644a97aee8
commit afab283988
4 changed files with 32 additions and 38 deletions

View File

@ -23,7 +23,7 @@
</widget>
</item>
<item row="3" column="0" colspan="2">
<widget class="QGraphicsView" name="glw_1"/>
<widget class="BECDeviceMonitor" name="plot_1"/>
</item>
<item row="1" column="3">
<widget class="QPushButton" name="pushButton_setting_2">
@ -33,7 +33,7 @@
</widget>
</item>
<item row="3" column="2" colspan="2">
<widget class="QGraphicsView" name="glw_2"/>
<widget class="BECDeviceMonitor" name="plot_2"/>
</item>
<item row="1" column="4">
<widget class="QLabel" name="label_2">
@ -64,7 +64,7 @@
</widget>
</item>
<item row="3" column="4" colspan="2">
<widget class="QGraphicsView" name="glw_3"/>
<widget class="BECDeviceMonitor" name="plot_3"/>
</item>
</layout>
</widget>
@ -74,18 +74,19 @@
<x>0</x>
<y>0</y>
<width>1433</width>
<height>37</height>
<height>24</height>
</rect>
</property>
<widget class="QMenu" name="menuSettings">
<property name="title">
<string>Settings</string>
</property>
</widget>
<addaction name="menuSettings"/>
</widget>
<widget class="QStatusBar" name="statusbar"/>
</widget>
<customwidgets>
<customwidget>
<class>BECDeviceMonitor</class>
<extends>QGraphicsView</extends>
<header location="global">bec_widgets.widgets.h</header>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>

View File

@ -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__":

View File

@ -0,0 +1 @@
from .monitor import BECDeviceMonitor

View File

@ -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