0
0
mirror of https://github.com/bec-project/bec_widgets.git synced 2025-07-14 11:41:49 +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> </widget>
</item> </item>
<item row="3" column="0" colspan="2"> <item row="3" column="0" colspan="2">
<widget class="QGraphicsView" name="glw_1"/> <widget class="BECDeviceMonitor" name="plot_1"/>
</item> </item>
<item row="1" column="3"> <item row="1" column="3">
<widget class="QPushButton" name="pushButton_setting_2"> <widget class="QPushButton" name="pushButton_setting_2">
@ -33,7 +33,7 @@
</widget> </widget>
</item> </item>
<item row="3" column="2" colspan="2"> <item row="3" column="2" colspan="2">
<widget class="QGraphicsView" name="glw_2"/> <widget class="BECDeviceMonitor" name="plot_2"/>
</item> </item>
<item row="1" column="4"> <item row="1" column="4">
<widget class="QLabel" name="label_2"> <widget class="QLabel" name="label_2">
@ -64,7 +64,7 @@
</widget> </widget>
</item> </item>
<item row="3" column="4" colspan="2"> <item row="3" column="4" colspan="2">
<widget class="QGraphicsView" name="glw_3"/> <widget class="BECDeviceMonitor" name="plot_3"/>
</item> </item>
</layout> </layout>
</widget> </widget>
@ -74,18 +74,19 @@
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>1433</width> <width>1433</width>
<height>37</height> <height>24</height>
</rect> </rect>
</property> </property>
<widget class="QMenu" name="menuSettings">
<property name="title">
<string>Settings</string>
</property>
</widget>
<addaction name="menuSettings"/>
</widget> </widget>
<widget class="QStatusBar" name="statusbar"/> <widget class="QStatusBar" name="statusbar"/>
</widget> </widget>
<customwidgets>
<customwidget>
<class>BECDeviceMonitor</class>
<extends>QGraphicsView</extends>
<header location="global">bec_widgets.widgets.h</header>
</customwidget>
</customwidgets>
<resources/> <resources/>
<connections/> <connections/>
</ui> </ui>

View File

@ -5,6 +5,7 @@ from PyQt5.QtWidgets import QMainWindow, QApplication, QVBoxLayout
from bec_widgets.widgets.monitor import BECDeviceMonitor from bec_widgets.widgets.monitor import BECDeviceMonitor
# some default configs for demonstration purposes
config_1 = { config_1 = {
"plot_settings": { "plot_settings": {
"background_color": "black", "background_color": "black",
@ -184,29 +185,15 @@ class ModularApp(QMainWindow):
self._init_plots() self._init_plots()
def _init_plots(self): def _init_plots(self):
self.glw_1_layout = QVBoxLayout(self.glw_1) # Create a new QVBoxLayout """Initialize plots and connect the buttons to the config dialogs"""
self.bec_device_monitor_1 = BECDeviceMonitor(parent=self, config=config_1) plots = [self.plot_1, self.plot_2, self.plot_3]
self.glw_1_layout.addWidget(self.bec_device_monitor_1) # Add BECDeviceMonitor to the layout configs = [config_1, config_2, config_scan_mode]
self.pushButton_setting_1.clicked.connect( buttons = [self.pushButton_setting_1, self.pushButton_setting_2, self.pushButton_setting_3]
lambda: self.bec_device_monitor_1.show_config_dialog()
)
self.glw_2_layout = QVBoxLayout(self.glw_2) # Create a new QVBoxLayout # hook plots, configs and buttons together
self.bec_device_monitor_2 = BECDeviceMonitor(parent=self, config=config_2) for plot, config, button in zip(plots, configs, buttons):
self.glw_2_layout.addWidget(self.bec_device_monitor_2) # Add BECDeviceMonitor to the layout plot.update_config(config)
self.pushButton_setting_2.clicked.connect( button.clicked.connect(plot.show_config_dialog)
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()
if __name__ == "__main__": 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() update_signal = pyqtSignal()
def __init__( 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 # Client and device manager from BEC
self.client = bec_dispatcher.client if client is None else client self.client = bec_dispatcher.client if client is None else client
@ -83,9 +83,10 @@ class BECDeviceMonitor(pg.GraphicsLayoutWidget):
) )
# Init UI # Init UI
self._init_config() if self.config is None:
# self._init_ui() #TODO could be removed print("No initial config found for BECDeviceMonitor")
# self._init_curves() else:
self.update_config(self.config)
def _init_config(self): def _init_config(self):
""" """
@ -222,7 +223,7 @@ class BECDeviceMonitor(pg.GraphicsLayoutWidget):
def hook_crosshair(self) -> None: def hook_crosshair(self) -> None:
"""Hook the crosshair to all plots.""" """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 = {} self.crosshairs = {}
for plot_name, plot in self.plots.items(): for plot_name, plot in self.plots.items():
crosshair = Crosshair(plot, precision=3) crosshair = Crosshair(plot, precision=3)
@ -255,6 +256,10 @@ class BECDeviceMonitor(pg.GraphicsLayoutWidget):
dialog.config_updated.connect(self.update_config) dialog.config_updated.connect(self.update_config)
dialog.show() dialog.show()
def update_client(self, client):
self.client = client
self.dev = self.client.device_manager.devices
@pyqtSlot(dict) @pyqtSlot(dict)
def update_config(self, config): def update_config(self, config):
self.config = config self.config = config