0
0
mirror of https://github.com/bec-project/bec_widgets.git synced 2025-07-14 11:41:49 +02:00

feature: DialogConfig ability to add different scan configuration

This commit is contained in:
wyzula-jan
2023-10-20 16:27:26 +02:00
committed by wyzula_j
parent f1d7abeb25
commit 7db9e0ef16
4 changed files with 149 additions and 49 deletions

View File

@ -82,7 +82,7 @@ config_2 = {
], ],
} }
config_scan_mode = config = { config_scan_mode = {
"plot_settings": { "plot_settings": {
"background_color": "white", "background_color": "white",
"num_columns": 3, "num_columns": 3,

View File

@ -14,6 +14,7 @@ from PyQt5.QtWidgets import (
QPushButton, QPushButton,
QTableWidgetItem, QTableWidgetItem,
QTableWidget, QTableWidget,
QTabWidget,
) )
@ -31,50 +32,110 @@ class ConfigDialog(QWidget, Ui_Form):
self.signal_count = 1 # TODO decide if useful self.signal_count = 1 # TODO decide if useful
self.tab_ui_objects = [] # Create a list to hold the Tab_Ui_Form objects self.tab_ui_objects = {} # [] # Create a list to hold the Tab_Ui_Form objects
# Connect the buttons inside the dialog # Connect the buttons inside the dialog
self.pushButton_add_new_plot.clicked.connect(self.add_new_plot) # self.pushButton_add_new_plot.clicked.connect(self.add_new_plot) # TODO move to tabs
# Connect the Ok/Apply/Cancel buttons # Connect the Ok/Apply/Cancel buttons
self.pushButton_ok.clicked.connect(self.apply_and_close) self.pushButton_ok.clicked.connect(self.apply_and_close)
self.pushButton_apply.clicked.connect(self.apply_config) self.pushButton_apply.clicked.connect(self.apply_config)
self.pushButton_cancel.clicked.connect(self.close) self.pushButton_cancel.clicked.connect(self.close)
# Scan types
self.pushButton_new_scan_type.clicked.connect(self.add_new_scan_type)
self.add_new_plot() # add initial first plot tab self.add_new_plot() # add initial first plot tab
if default_config is not None: if default_config is not None:
self.load_config(default_config) self.load_config(default_config)
def add_new_scan_type(self):
scan_type_name = self.lineEdit_scan_type.text()
if not scan_type_name:
return
new_scan_tab = QWidget()
new_scan_tab_layout = QVBoxLayout(new_scan_tab)
new_tabWidget_plots = QTabWidget()
new_tabWidget_plots.setObjectName("tabWidget_plots")
new_scan_tab_layout.addWidget(new_tabWidget_plots)
self.tabWidget_scan_types.addTab(new_scan_tab, scan_type_name)
# self.tab_ui_objects[scan_type_name] = []
# Store tab structure in the dict
self.tab_ui_objects[scan_type_name] = {"tab_widget": new_scan_tab, "plots": []}
# Set the newly created scan tab as the current tab
self.tabWidget_scan_types.setCurrentWidget(new_scan_tab)
# Generate the first plot tab
self.add_new_plot()
def add_new_plot(self): def add_new_plot(self):
# Set tabs # Get the currently selected scan tab
new_tab_widget = QWidget() current_scan_type_index = self.tabWidget_scan_types.currentIndex()
new_tab = Tab_Ui_Form() if current_scan_type_index == -1:
new_tab.setupUi(new_tab_widget) return # Exit if no scan tab is selected
# Connect tab buttons # Get the tab widget of the currently selected scan tab
self.hook_tab_buttons(new_tab) current_scan_tab_widget = self.tabWidget_scan_types.widget(current_scan_type_index)
# Tab header name # Get the QTabWidget object from the current scan tab widget
new_tab_name = f"Plot {self.tabWidget_plots.count() + 1}" current_tabWidget_plots = current_scan_tab_widget.findChild(QTabWidget, "tabWidget_plots")
if current_tabWidget_plots is None:
return # Exit if the QTabWidget object is not found
# Add new tab # Create a new plot tab
self.tabWidget_plots.addTab( new_plot_tab = QWidget()
new_tab_widget, new_tab_name new_plot_tab_ui = Tab_Ui_Form()
) # Add the new QWidget as a new tab new_plot_tab_ui.setupUi(new_plot_tab)
self.tab_ui_objects.append(new_tab) # Append the Tab_Ui_Form object to the list
# Hook the buttons in the new plot tab
self.hook_tab_buttons(new_plot_tab_ui)
# Add this new plot tab to the currently selected scan tab's tab widget
current_tabWidget_plots.addTab(new_plot_tab, f"Plot {current_tabWidget_plots.count() + 1}")
# Store tab structure in the dict
scan_type_name = self.tabWidget_scan_types.tabText(current_scan_type_index)
if scan_type_name not in self.tab_ui_objects:
self.tab_ui_objects[scan_type_name] = {
"tab_widget": current_scan_tab_widget,
"plots": [],
}
self.tab_ui_objects[scan_type_name]["plots"].append(new_plot_tab_ui)
# Connect tab buttons # TODO decide what has to be hooked
# self.hook_tab_buttons(new_plot_tab_ui)
def hook_tab_buttons(self, tab_ui_object): def hook_tab_buttons(self, tab_ui_object):
tab_ui_object.pushButton_y_new.clicked.connect( tab_ui_object.pushButton_y_new.clicked.connect(
lambda: self.add_new_signal(tab_ui_object.tableWidget_y_signals) lambda: self.add_new_signal(tab_ui_object.tableWidget_y_signals)
) )
tab_ui_object.pushButton_remove_current_plot.clicked.connect(self.remove_current_plot) tab_ui_object.pushButton_remove_current_plot.clicked.connect(
lambda: self.remove_current_plot(tab_ui_object)
)
tab_ui_object.pushButton_add_new_plot.clicked.connect(self.add_new_plot)
def remove_current_plot(self): def remove_current_plot(self, tab_ui_object):
current_index = self.tabWidget_plots.currentIndex() current_scan_type_index = self.tabWidget_scan_types.currentIndex()
if current_scan_type_index == -1:
return # Exit if no scan tab is selected
# Get the tab widget of the currently selected scan tab
current_scan_tab_widget = self.tab_ui_objects[
self.tabWidget_scan_types.tabText(current_scan_type_index)
]["tab_widget"].findChild(QTabWidget, "tabWidget_plots")
current_index = current_scan_tab_widget.currentIndex()
if current_index != -1: # Ensure there is a tab to remove if current_index != -1: # Ensure there is a tab to remove
self.tabWidget_plots.removeTab(current_index) current_scan_tab_widget.removeTab(current_index)
del self.tab_ui_objects[current_index] del self.tab_ui_objects[self.tabWidget_scan_types.tabText(current_scan_type_index)][
"plots"
][current_index]
def add_new_signal(self, tableWidget_y_signals): def add_new_signal(self, tableWidget_y_signals):
row_position = tableWidget_y_signals.rowCount() row_position = tableWidget_y_signals.rowCount()

View File

@ -31,9 +31,6 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="0" column="1">
<widget class="QSpinBox" name="spinBox_n_column"/>
</item>
<item row="1" column="0"> <item row="1" column="0">
<widget class="QLabel" name="label_6"> <widget class="QLabel" name="label_6">
<property name="text"> <property name="text">
@ -41,6 +38,13 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="3" column="0">
<widget class="QPushButton" name="pushButton_new_scan_type">
<property name="text">
<string>New Scan Type</string>
</property>
</widget>
</item>
<item row="1" column="1"> <item row="1" column="1">
<widget class="QComboBox" name="comboBox_scanTypes"> <widget class="QComboBox" name="comboBox_scanTypes">
<item> <item>
@ -55,12 +59,11 @@
</item> </item>
</widget> </widget>
</item> </item>
<item row="2" column="0" colspan="2"> <item row="0" column="1">
<widget class="QPushButton" name="pushButton_add_new_plot"> <widget class="QSpinBox" name="spinBox_n_column"/>
<property name="text"> </item>
<string>Add New Plot</string> <item row="3" column="1">
</property> <widget class="QLineEdit" name="lineEdit_scan_type"/>
</widget>
</item> </item>
</layout> </layout>
</item> </item>
@ -154,10 +157,30 @@
</layout> </layout>
</item> </item>
<item> <item>
<widget class="QTabWidget" name="tabWidget_plots"> <widget class="QTabWidget" name="tabWidget_scan_types">
<property name="currentIndex"> <property name="tabPosition">
<number>-1</number> <enum>QTabWidget::West</enum>
</property> </property>
<property name="tabShape">
<enum>QTabWidget::Rounded</enum>
</property>
<property name="currentIndex">
<number>0</number>
</property>
<widget class="QWidget" name="tab_1">
<attribute name="title">
<string>Device Monitor</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_5">
<item>
<widget class="QTabWidget" name="tabWidget_plots">
<property name="currentIndex">
<number>-1</number>
</property>
</widget>
</item>
</layout>
</widget>
</widget> </widget>
</item> </item>
<item> <item>

View File

@ -106,22 +106,31 @@
</widget> </widget>
</item> </item>
<item> <item>
<widget class="BECTable" name="tableWidget_y_signals"> <widget class="QGroupBox" name="groupBox_y_signals">
<column> <property name="title">
<property name="text"> <string>Y Signals</string>
<string>Name</string> </property>
</property> <layout class="QVBoxLayout" name="verticalLayout_3">
</column> <item>
<column> <widget class="BECTable" name="tableWidget_y_signals">
<property name="text"> <column>
<string>Entries</string> <property name="text">
</property> <string>Name</string>
</column> </property>
<column> </column>
<property name="text"> <column>
<string>Color</string> <property name="text">
</property> <string>Entries</string>
</column> </property>
</column>
<column>
<property name="text">
<string>Color</string>
</property>
</column>
</widget>
</item>
</layout>
</widget> </widget>
</item> </item>
<item> <item>
@ -133,6 +142,13 @@
</property> </property>
</widget> </widget>
</item> </item>
<item>
<widget class="QPushButton" name="pushButton_add_new_plot">
<property name="text">
<string>Add New Plot</string>
</property>
</widget>
</item>
<item> <item>
<spacer name="horizontalSpacer_3"> <spacer name="horizontalSpacer_3">
<property name="orientation"> <property name="orientation">