mirror of
https://github.com/bec-project/bec_widgets.git
synced 2025-07-14 11:41:49 +02:00
refactor: DialogConfig implemented directly to the BECDeviceMonitor
This commit is contained in:
@ -3,7 +3,7 @@ import os
|
|||||||
from PyQt5 import uic
|
from PyQt5 import uic
|
||||||
from PyQt5.QtWidgets import QMainWindow, QApplication, QVBoxLayout
|
from PyQt5.QtWidgets import QMainWindow, QApplication, QVBoxLayout
|
||||||
|
|
||||||
from bec_widgets.widgets.monitor import BECDeviceMonitor, ConfigDialog
|
from bec_widgets.widgets.monitor import BECDeviceMonitor
|
||||||
|
|
||||||
config_1 = {
|
config_1 = {
|
||||||
"plot_settings": {
|
"plot_settings": {
|
||||||
@ -81,6 +81,7 @@ config_2 = {
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
|
|
||||||
config_scan_mode = config = {
|
config_scan_mode = config = {
|
||||||
"plot_settings": {
|
"plot_settings": {
|
||||||
"background_color": "white",
|
"background_color": "white",
|
||||||
@ -185,36 +186,27 @@ class ModularApp(QMainWindow):
|
|||||||
def _init_plots(self):
|
def _init_plots(self):
|
||||||
self.glw_1_layout = QVBoxLayout(self.glw_1) # Create a new QVBoxLayout
|
self.glw_1_layout = QVBoxLayout(self.glw_1) # Create a new QVBoxLayout
|
||||||
self.bec_device_monitor_1 = BECDeviceMonitor(parent=self, config=config_1)
|
self.bec_device_monitor_1 = BECDeviceMonitor(parent=self, config=config_1)
|
||||||
self.config_dialog_1 = ConfigDialog()
|
|
||||||
self.glw_1_layout.addWidget(self.bec_device_monitor_1) # Add BECDeviceMonitor to the layout
|
self.glw_1_layout.addWidget(self.bec_device_monitor_1) # Add BECDeviceMonitor to the layout
|
||||||
self.pushButton_setting_1.clicked.connect(
|
self.pushButton_setting_1.clicked.connect(
|
||||||
lambda: self.show_config_dialog(self.bec_device_monitor_1, self.config_dialog_1)
|
lambda: self.bec_device_monitor_1.show_config_dialog()
|
||||||
)
|
)
|
||||||
|
|
||||||
self.glw_2_layout = QVBoxLayout(self.glw_2) # Create a new QVBoxLayout
|
self.glw_2_layout = QVBoxLayout(self.glw_2) # Create a new QVBoxLayout
|
||||||
self.bec_device_monitor_2 = BECDeviceMonitor(parent=self, config=config_2)
|
self.bec_device_monitor_2 = BECDeviceMonitor(parent=self, config=config_2)
|
||||||
self.config_dialog_2 = ConfigDialog()
|
|
||||||
self.glw_2_layout.addWidget(self.bec_device_monitor_2) # Add BECDeviceMonitor to the layout
|
self.glw_2_layout.addWidget(self.bec_device_monitor_2) # Add BECDeviceMonitor to the layout
|
||||||
self.pushButton_setting_2.clicked.connect(
|
self.pushButton_setting_2.clicked.connect(
|
||||||
lambda: self.show_config_dialog(self.bec_device_monitor_2, self.config_dialog_2)
|
lambda: self.bec_device_monitor_2.show_config_dialog()
|
||||||
)
|
)
|
||||||
|
|
||||||
self.glw_3_layout = QVBoxLayout(self.glw_3) # Create a new QVBoxLayout
|
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.bec_device_monitor_3 = BECDeviceMonitor(parent=self, config=config_scan_mode)
|
||||||
self.config_dialog_3 = ConfigDialog()
|
|
||||||
self.glw_3_layout.addWidget(self.bec_device_monitor_3) # Add BECDeviceMonitor to the layout
|
self.glw_3_layout.addWidget(self.bec_device_monitor_3) # Add BECDeviceMonitor to the layout
|
||||||
self.pushButton_setting_3.clicked.connect(
|
self.pushButton_setting_3.clicked.connect(
|
||||||
lambda: self.show_config_dialog(self.bec_device_monitor_3, self.config_dialog_3)
|
lambda: self.bec_device_monitor_3.show_config_dialog()
|
||||||
)
|
)
|
||||||
|
|
||||||
def show_config_dialog(self, monitor, config_dialog):
|
def show_config_dialog(self, monitor):
|
||||||
config = monitor.get_config()
|
monitor.show_config_dialog()
|
||||||
|
|
||||||
config_dialog.load_config(config) # Load the configuration into the dialog
|
|
||||||
config_dialog.config_updated.connect(
|
|
||||||
monitor.update_config
|
|
||||||
) # Connect the signal to the monitor's slot
|
|
||||||
config_dialog.show() # Show the dialog
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
@ -25,8 +25,8 @@ Tab_Ui_Form, Tab_BaseClass = uic.loadUiType(os.path.join(current_path, "tab_temp
|
|||||||
class ConfigDialog(QWidget, Ui_Form):
|
class ConfigDialog(QWidget, Ui_Form):
|
||||||
config_updated = pyqtSignal(dict)
|
config_updated = pyqtSignal(dict)
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self, default_config=None):
|
||||||
super().__init__()
|
super(ConfigDialog, self).__init__()
|
||||||
self.setupUi(self)
|
self.setupUi(self)
|
||||||
|
|
||||||
self.signal_count = 1 # TODO decide if useful
|
self.signal_count = 1 # TODO decide if useful
|
||||||
@ -43,6 +43,9 @@ class ConfigDialog(QWidget, Ui_Form):
|
|||||||
|
|
||||||
self.add_new_plot() # add initial first plot tab
|
self.add_new_plot() # add initial first plot tab
|
||||||
|
|
||||||
|
if default_config is not None:
|
||||||
|
self.load_config(default_config)
|
||||||
|
|
||||||
def add_new_plot(self):
|
def add_new_plot(self):
|
||||||
# Set tabs
|
# Set tabs
|
||||||
new_tab_widget = QWidget()
|
new_tab_widget = QWidget()
|
||||||
|
@ -1,12 +1,14 @@
|
|||||||
|
import os
|
||||||
|
|
||||||
import pyqtgraph as pg
|
import pyqtgraph as pg
|
||||||
from bec_lib.core import MessageEndpoints
|
from bec_lib.core import MessageEndpoints
|
||||||
from PyQt5 import QtCore
|
from PyQt5 import QtCore
|
||||||
from PyQt5.QtCore import pyqtSignal, pyqtSlot
|
from PyQt5.QtCore import pyqtSignal, pyqtSlot
|
||||||
from PyQt5.QtWidgets import QApplication
|
from PyQt5.QtWidgets import QApplication, QTableWidgetItem, QWidget
|
||||||
from pyqtgraph import mkPen, mkBrush
|
from pyqtgraph import mkPen, mkBrush
|
||||||
|
from PyQt5 import uic
|
||||||
|
|
||||||
from bec_widgets.bec_dispatcher import bec_dispatcher
|
from bec_widgets.bec_dispatcher import bec_dispatcher
|
||||||
|
|
||||||
from bec_widgets.qt_utils import Crosshair, Colors
|
from bec_widgets.qt_utils import Crosshair, Colors
|
||||||
|
|
||||||
config_simple = {
|
config_simple = {
|
||||||
@ -231,6 +233,13 @@ class BECDeviceMonitor(pg.GraphicsLayoutWidget):
|
|||||||
def get_config(self):
|
def get_config(self):
|
||||||
return self.config
|
return self.config
|
||||||
|
|
||||||
|
def show_config_dialog(self):
|
||||||
|
from .config_dialog import ConfigDialog
|
||||||
|
|
||||||
|
dialog = ConfigDialog(default_config=self.config)
|
||||||
|
dialog.config_updated.connect(self.update_config)
|
||||||
|
dialog.show()
|
||||||
|
|
||||||
@pyqtSlot(dict)
|
@pyqtSlot(dict)
|
||||||
def update_config(self, config):
|
def update_config(self, config):
|
||||||
self.config = config
|
self.config = config
|
||||||
|
Reference in New Issue
Block a user