diff --git a/bec_widgets/widgets/monitor/config_dialog.py b/bec_widgets/widgets/monitor/config_dialog.py index 19cbb2e5..5930ab04 100644 --- a/bec_widgets/widgets/monitor/config_dialog.py +++ b/bec_widgets/widgets/monitor/config_dialog.py @@ -28,27 +28,42 @@ class ConfigDialog(QWidget, Ui_Form): self.pushButton_apply.clicked.connect(self.apply_config) self.pushButton_cancel.clicked.connect(self.close) - # #TODO hook Scan types buttons + # Hook signals self.pushButton_new_scan_type.clicked.connect( - lambda: self.add_new_scan(self.tabWidget_scan_types, "New Scan Type") + lambda: self.add_new_scan( + self.tabWidget_scan_types, self.lineEdit_scan_type.text(), True + ) ) + # Scan Types changed + self.comboBox_scanTypes.currentIndexChanged.connect(self._init_default) + # Make scan tabs closable + self.tabWidget_scan_types.tabCloseRequested.connect(self.handle_tab_close_request) # Default configuration - self._init_default() # Init functions to make a default dialog #TODO this is useful, but has to be made better - # if default_config is not None: + if default_config is None: + self._init_default() # self.load_config() def _init_default(self): - self.add_new_scan(self.tabWidget_scan_types, "Default") + if self.comboBox_scanTypes.currentText() == "Disabled": + self.add_new_scan(self.tabWidget_scan_types, "Default") + self.pushButton_new_scan_type.setEnabled(False) + self.lineEdit_scan_type.setEnabled(False) + else: + self.pushButton_new_scan_type.setEnabled(True) + self.lineEdit_scan_type.setEnabled(True) + self.tabWidget_scan_types.clear() - def add_new_scan(self, parent_tab: QTabWidget, scan_name: str) -> None: + def add_new_scan(self, parent_tab: QTabWidget, scan_name: str, closable: bool = False) -> None: """ Add a new scan tab to the parent tab widget Args: + closable: parent_tab(QTabWidget): Parent tab widget, where to add scan tab scan_name(str): Scan name + closable(bool): If True, the scan tab will be closable """ # Create a new scan tab scan_tab = QWidget() @@ -57,11 +72,16 @@ class ConfigDialog(QWidget, Ui_Form): # Set a tab widget for plots tabWidget_plots = QTabWidget() tabWidget_plots.setObjectName("tabWidget_plots") + tabWidget_plots.setTabsClosable(True) + tabWidget_plots.tabCloseRequested.connect(self.handle_tab_close_request) scan_tab_layout.addWidget(tabWidget_plots) # Add scan tab parent_tab.addTab(scan_tab, scan_name) + # Optionally, connect the tabCloseRequested signal to a slot to handle the tab close request + if closable: + parent_tab.setTabsClosable(closable) # Add first plot self.add_new_plot(scan_tab) @@ -95,29 +115,28 @@ class ConfigDialog(QWidget, Ui_Form): 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 handle_tab_close_request(self, index: int) -> None: + """ + Handle tab close request + + Args: + index(int): Index of the tab to be closed + """ + print(index) + parent_tab = self.sender() + parent_tab.removeTab(index) def apply_config(self): ...