diff --git a/bec_widgets/widgets/monitor/config_dialog.py b/bec_widgets/widgets/monitor/config_dialog.py index 14736d53..19cbb2e5 100644 --- a/bec_widgets/widgets/monitor/config_dialog.py +++ b/bec_widgets/widgets/monitor/config_dialog.py @@ -1,23 +1,16 @@ import os -from bec_widgets.qt_utils import BECTable from PyQt5 import uic from PyQt5.QtCore import pyqtSignal from PyQt5.QtWidgets import ( QApplication, QWidget, QVBoxLayout, - QLineEdit, - QLabel, - QGroupBox, - QHBoxLayout, - QPushButton, - QTableWidgetItem, QTableWidget, QTabWidget, + QTableWidgetItem, ) - current_path = os.path.dirname(__file__) Ui_Form, BaseClass = uic.loadUiType(os.path.join(current_path, "config_dialog.ui")) Tab_Ui_Form, Tab_BaseClass = uic.loadUiType(os.path.join(current_path, "tab_template.ui")) @@ -50,6 +43,13 @@ class ConfigDialog(QWidget, Ui_Form): self.add_new_scan(self.tabWidget_scan_types, "Default") def add_new_scan(self, parent_tab: QTabWidget, scan_name: str) -> None: + """ + Add a new scan tab to the parent tab widget + + Args: + parent_tab(QTabWidget): Parent tab widget, where to add scan tab + scan_name(str): Scan name + """ # Create a new scan tab scan_tab = QWidget() scan_tab_layout = QVBoxLayout(scan_tab) @@ -65,7 +65,13 @@ class ConfigDialog(QWidget, Ui_Form): # Add first plot self.add_new_plot(scan_tab) - def add_new_plot(self, scan_tab: QTabWidget) -> None: + def add_new_plot(self, scan_tab: QWidget) -> None: + """ + Add a new plot tab to the scan tab + Args: + scan_tab (QWidget): Scan tab widget + + """ # Create a new plot tab from .ui template plot_tab = QWidget() plot_tab_ui = Tab_Ui_Form() @@ -79,10 +85,39 @@ class ConfigDialog(QWidget, Ui_Form): # Hook signal self.hook_plot_tab_signals(scan_tab=scan_tab, plot_tab=plot_tab_ui) - def hook_plot_tab_signals(self, scan_tab: QTabWidget, plot_tab: QTabWidget) -> None: + def hook_plot_tab_signals(self, scan_tab: QTabWidget, plot_tab: Tab_Ui_Form) -> None: + """ + Hook signals of the plot tab + Args: + scan_tab(QTabWidget): Scan tab widget + plot_tab(Tab_Ui_Form): Plot tab widget + """ plot_tab.pushButton_add_new_plot.clicked.connect( lambda: self.add_new_plot(scan_tab=scan_tab) ) + plot_tab.pushButton_remove_current_plot.clicked.connect( + lambda: self.remove_current_plot(scan_tab.findChild(QTabWidget, "tabWidget_plots")) + ) + plot_tab.pushButton_y_new.clicked.connect( + lambda: self.add_new_signal( + scan_tab.findChild(QTabWidget, "tabWidget_plots").table_y_signals + ) + ) + + def remove_current_plot(self, plot_tab: QTabWidget) -> None: + current_index = plot_tab.currentIndex() + total_tabs = plot_tab.count() + # make sure that there is a tab to be removed + if current_index != -1 and total_tabs > 1: + plot_tab.removeTab(current_index) + + def add_new_signal(self, table: QTableWidget) -> None: + row_position = table.rowCount() + table.insertRow(row_position) + table.setItem(row_position, 0, QTableWidgetItem("")) + table.setItem(row_position, 1, QTableWidgetItem("")) + + ... def apply_config(self): ...