mirror of
https://github.com/bec-project/bec_widgets.git
synced 2025-07-14 11:41:49 +02:00
feat: config_dialog.py interactive editor of plot settings
This commit is contained in:
85
bec_widgets/examples/modular_app/___init__.py
Normal file
85
bec_widgets/examples/modular_app/___init__.py
Normal file
@ -0,0 +1,85 @@
|
||||
from PyQt5.QtWidgets import (
|
||||
QApplication,
|
||||
QMainWindow,
|
||||
QVBoxLayout,
|
||||
QWidget,
|
||||
QTabWidget,
|
||||
QPushButton,
|
||||
QDialog,
|
||||
QListView,
|
||||
QStandardItemModel,
|
||||
QStandardItem,
|
||||
)
|
||||
from bec_widgets.widgets.device_monitor import BECDeviceMonitor
|
||||
from bec_widgets.bec_dispatcher import bec_dispatcher
|
||||
|
||||
|
||||
class ConfigDialog(QDialog):
|
||||
def __init__(self, parent=None):
|
||||
super().__init__(parent)
|
||||
self.setWindowTitle("Configuration")
|
||||
self.layout = QVBoxLayout(self)
|
||||
self.listView = QListView(self)
|
||||
self.layout.addWidget(self.listView)
|
||||
self.okButton = QPushButton("OK", self)
|
||||
self.layout.addWidget(self.okButton)
|
||||
self.okButton.clicked.connect(self.accept)
|
||||
|
||||
def populate_device_list(self, device_names):
|
||||
model = QStandardItemModel()
|
||||
for device_name in device_names:
|
||||
item = QStandardItem(device_name)
|
||||
item.setCheckable(True)
|
||||
model.appendRow(item)
|
||||
self.listView.setModel(model)
|
||||
|
||||
|
||||
class PlotTabWidget(QTabWidget):
|
||||
def __init__(self, parent=None):
|
||||
super().__init__(parent)
|
||||
self.addTabButton = QPushButton("Add Tab", self)
|
||||
self.addTabButton.clicked.connect(self.add_new_tab)
|
||||
self.setCornerWidget(self.addTabButton)
|
||||
|
||||
def add_new_tab(self):
|
||||
config_dialog = ConfigDialog(self)
|
||||
config_dialog.populate_device_list(bec_dispatcher.client.device_manager.devices.keys())
|
||||
if config_dialog.exec_():
|
||||
selected_devices = [
|
||||
config_dialog.listView.model().item(i).text()
|
||||
for i in range(config_dialog.listView.model().rowCount())
|
||||
if config_dialog.listView.model().item(i).checkState()
|
||||
]
|
||||
# Assuming device_config is a function that generates a config based on selected devices
|
||||
config = device_config(selected_devices)
|
||||
bec_device_monitor = BECDeviceMonitor(parent=self, config=config)
|
||||
self.addTab(bec_device_monitor, f"Tab {self.count() + 1}")
|
||||
|
||||
|
||||
class ModularApp(QMainWindow):
|
||||
def __init__(self, client=None, parent=None):
|
||||
super(ModularApp, self).__init__(parent)
|
||||
self.client = bec_dispatcher.client if client is None else client
|
||||
self.init_ui()
|
||||
|
||||
def init_ui(self):
|
||||
self.tabWidget = PlotTabWidget(self)
|
||||
self.setCentralWidget(self.tabWidget)
|
||||
|
||||
|
||||
def device_config(selected_devices):
|
||||
# Generate a configuration based on the selected devices
|
||||
# This is a placeholder and should be replaced with your actual logic
|
||||
pass
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
client = bec_dispatcher.client
|
||||
client.start()
|
||||
|
||||
app = QApplication([])
|
||||
modularApp = ModularApp(client=client)
|
||||
|
||||
window = modularApp
|
||||
window.show()
|
||||
app.exec_()
|
@ -1,7 +1,9 @@
|
||||
import os
|
||||
|
||||
from PyQt5 import uic
|
||||
from PyQt5.QtWidgets import QMainWindow, QApplication, QVBoxLayout
|
||||
from bec_widgets.widgets.device_monitor import BECDeviceMonitor
|
||||
|
||||
from bec_widgets.widgets.monitor.device_monitor import BECDeviceMonitor
|
||||
|
||||
config_1 = {
|
||||
"plot_settings": {
|
||||
|
0
bec_widgets/widgets/monitor/__init__.py
Normal file
0
bec_widgets/widgets/monitor/__init__.py
Normal file
108
bec_widgets/widgets/monitor/config_dialog.py
Normal file
108
bec_widgets/widgets/monitor/config_dialog.py
Normal file
@ -0,0 +1,108 @@
|
||||
from PyQt5 import uic
|
||||
from PyQt5.QtWidgets import (
|
||||
QApplication,
|
||||
QWidget,
|
||||
QVBoxLayout,
|
||||
QLineEdit,
|
||||
QLabel,
|
||||
QGroupBox,
|
||||
QHBoxLayout,
|
||||
QPushButton,
|
||||
QTableWidgetItem,
|
||||
)
|
||||
|
||||
Ui_Form, BaseClass = uic.loadUiType("config_dialog.ui")
|
||||
Tab_Ui_Form, Tab_BaseClass = uic.loadUiType("tab_template.ui")
|
||||
|
||||
|
||||
class MainApp(QWidget, Ui_Form):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.setupUi(self)
|
||||
|
||||
self.signal_count = 1 # TODO decide if useful
|
||||
|
||||
self.tab_ui_objects = [] # Create a list to hold the Tab_Ui_Form objects
|
||||
|
||||
# Connect the buttons
|
||||
self.pushButton_add_new_plot.clicked.connect(self.add_new_plot)
|
||||
self.pushButton_ok.clicked.connect(self.get_configuration)
|
||||
|
||||
self.add_new_plot() # add initial first plot tab
|
||||
|
||||
def add_new_plot(self):
|
||||
# Set tabs
|
||||
new_tab_widget = QWidget()
|
||||
new_tab = Tab_Ui_Form()
|
||||
new_tab.setupUi(new_tab_widget)
|
||||
|
||||
# Tab Signals
|
||||
new_tab.pushButton_y_new.clicked.connect(
|
||||
lambda: self.add_new_signal(new_tab.tableWidget_y_signals)
|
||||
)
|
||||
new_tab_name = f"Plot {self.tabWidget_plots.count() + 1}"
|
||||
self.tabWidget_plots.addTab(
|
||||
new_tab_widget, new_tab_name
|
||||
) # Add the new QWidget as a new tab
|
||||
self.tab_ui_objects.append(new_tab) # Append the Tab_Ui_Form object to the list
|
||||
|
||||
def add_new_signal(self, tableWidget_y_signals):
|
||||
row_position = tableWidget_y_signals.rowCount()
|
||||
tableWidget_y_signals.insertRow(row_position)
|
||||
tableWidget_y_signals.setItem(row_position, 0, QTableWidgetItem(""))
|
||||
tableWidget_y_signals.setItem(row_position, 1, QTableWidgetItem(""))
|
||||
|
||||
def get_configuration(self):
|
||||
config = {
|
||||
"plot_settings": {
|
||||
"background_color": "black",
|
||||
"num_columns": self.spinBox.value(),
|
||||
"colormap": self.comboBox_2.currentText(),
|
||||
"scan_types": self.comboBox.currentText() == "Enabled",
|
||||
},
|
||||
"plot_data": [],
|
||||
}
|
||||
|
||||
for index in range(self.tabWidget_plots.count()):
|
||||
tab = self.tabWidget_plots.widget(index)
|
||||
ui_object = self.tab_ui_objects[index]
|
||||
table = ui_object.tableWidget_y_signals
|
||||
signals = [
|
||||
{
|
||||
"name": self.safe_text(table.item(row, 0)),
|
||||
"entry": self.safe_text(table.item(row, 1)),
|
||||
}
|
||||
for row in range(table.rowCount())
|
||||
]
|
||||
|
||||
plot_config = {
|
||||
"plot_name": self.safe_text(ui_object.lineEdit_plot_title),
|
||||
"x": {
|
||||
"label": self.safe_text(ui_object.lineEdit_x_label),
|
||||
"signals": [
|
||||
{
|
||||
"name": self.safe_text(ui_object.lineEdit_x_name),
|
||||
"entry": self.safe_text(ui_object.lineEdit_x_entry),
|
||||
}
|
||||
],
|
||||
},
|
||||
"y": {
|
||||
"label": self.safe_text(ui_object.lineEdit_y_label),
|
||||
"signals": signals,
|
||||
},
|
||||
}
|
||||
config["plot_data"].append(plot_config)
|
||||
|
||||
print(config)
|
||||
return config
|
||||
|
||||
@staticmethod
|
||||
def safe_text(line_edit):
|
||||
return "" if line_edit is None else line_edit.text()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
app = QApplication([])
|
||||
main_app = MainApp()
|
||||
main_app.show()
|
||||
app.exec_()
|
160
bec_widgets/widgets/monitor/config_dialog.ui
Normal file
160
bec_widgets/widgets/monitor/config_dialog.ui
Normal file
@ -0,0 +1,160 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>Form</class>
|
||||
<widget class="QWidget" name="Form">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>558</width>
|
||||
<height>769</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Plot Configuration</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<widget class="QGroupBox" name="groupBox_plot_setting">
|
||||
<property name="title">
|
||||
<string>Plot Layout Settings</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="0" column="1">
|
||||
<widget class="QSpinBox" name="spinBox"/>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="text">
|
||||
<string>Scan Types</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="3">
|
||||
<widget class="QLabel" name="label_3">
|
||||
<property name="text">
|
||||
<string>Default Color Palette</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="3" rowspan="3">
|
||||
<widget class="QComboBox" name="comboBox_2">
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>magma</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>viridis</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>reds</string>
|
||||
</property>
|
||||
</item>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>Number of Columns</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="2" rowspan="4">
|
||||
<widget class="Line" name="line">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<widget class="QComboBox" name="comboBox">
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Disabled</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Enabled</string>
|
||||
</property>
|
||||
</item>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="0" colspan="2">
|
||||
<widget class="QPushButton" name="pushButton_add_new_plot">
|
||||
<property name="text">
|
||||
<string>Add New Plot</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QGroupBox" name="groupBox_config">
|
||||
<property name="title">
|
||||
<string>Configuration</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QPushButton" name="pushButton">
|
||||
<property name="text">
|
||||
<string>Import</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="pushButton_2">
|
||||
<property name="text">
|
||||
<string>Export</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QTabWidget" name="tabWidget_plots">
|
||||
<property name="currentIndex">
|
||||
<number>-1</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="confirm_layout">
|
||||
<item>
|
||||
<widget class="QPushButton" name="pushButton_cancel">
|
||||
<property name="text">
|
||||
<string>Cancel</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="pushButton_apply">
|
||||
<property name="text">
|
||||
<string>Apply</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="pushButton_ok">
|
||||
<property name="text">
|
||||
<string>OK</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
169
bec_widgets/widgets/monitor/tab_template.ui
Normal file
169
bec_widgets/widgets/monitor/tab_template.ui
Normal file
@ -0,0 +1,169 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>Form</class>
|
||||
<widget class="QWidget" name="Form">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>506</width>
|
||||
<height>592</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Form</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<item>
|
||||
<widget class="QGroupBox" name="groupBox_general">
|
||||
<property name="title">
|
||||
<string>General</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="label_5">
|
||||
<property name="text">
|
||||
<string>X Label</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0" colspan="5">
|
||||
<widget class="Line" name="line_2">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="4">
|
||||
<widget class="QLineEdit" name="lineEdit_y_label"/>
|
||||
</item>
|
||||
<item row="2" column="3">
|
||||
<widget class="QLabel" name="label_11">
|
||||
<property name="text">
|
||||
<string>Y Label</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1" colspan="4">
|
||||
<widget class="QLineEdit" name="lineEdit_plot_title"/>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<widget class="QLineEdit" name="lineEdit_x_label"/>
|
||||
</item>
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label_4">
|
||||
<property name="text">
|
||||
<string>Plot Title</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="2">
|
||||
<widget class="Line" name="line_3">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QGroupBox" name="groupBox_x_axis">
|
||||
<property name="title">
|
||||
<string>X Axis</string>
|
||||
</property>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_6">
|
||||
<property name="text">
|
||||
<string>Name:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="lineEdit_x_name"/>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="Line" name="line">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="label_7">
|
||||
<property name="text">
|
||||
<string>Entry:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="lineEdit_x_entry"/>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QTableWidget" name="tableWidget_y_signals">
|
||||
<row>
|
||||
<property name="text">
|
||||
<string>1</string>
|
||||
</property>
|
||||
</row>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>Name</string>
|
||||
</property>
|
||||
</column>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>Entries</string>
|
||||
</property>
|
||||
</column>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>Color</string>
|
||||
</property>
|
||||
</column>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||
<item>
|
||||
<widget class="QPushButton" name="pushButton_remove_current_plot">
|
||||
<property name="text">
|
||||
<string>Remove Current Plot</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer_3">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="pushButton_y_new">
|
||||
<property name="text">
|
||||
<string>Add New Signal</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
Reference in New Issue
Block a user