diff --git a/src/ert/gui/ertwidgets/caselist.py b/src/ert/gui/ertwidgets/caselist.py index 0192e69ba08..7e38b1c6460 100644 --- a/src/ert/gui/ertwidgets/caselist.py +++ b/src/ert/gui/ertwidgets/caselist.py @@ -1,3 +1,5 @@ +from typing import Callable + from qtpy.QtCore import QSize, Qt from qtpy.QtGui import QIcon from qtpy.QtWidgets import ( @@ -6,7 +8,6 @@ QLabel, QListWidget, QListWidgetItem, - QMessageBox, QToolButton, QVBoxLayout, QWidget, @@ -18,42 +19,37 @@ from ert.storage import StorageAccessor -class AddRemoveWidget(QWidget): +class AddWidget(QWidget): """ - A simple class that provides to vertically positioned buttons for adding and - removing something. The addFunction and removeFunction functions must be - provided. + A widget with an add button. + + Parameters + ---------- + addFunction: Callable to be connected to the add button. """ - def __init__(self, addFunction=None, removeFunction=None): - QWidget.__init__(self) + def __init__(self, addFunction: Callable): + super().__init__() self.addButton = QToolButton(self) self.addButton.setIcon(QIcon("img:add_circle_outlined.svg")) self.addButton.setIconSize(QSize(16, 16)) self.addButton.clicked.connect(addFunction) - self.removeButton = QToolButton(self) - self.removeButton.setIcon(QIcon("img:remove_outlined.svg")) - self.removeButton.setIconSize(QSize(16, 16)) - self.removeButton.clicked.connect(removeFunction) + self.removeButton = None self.buttonLayout = QHBoxLayout() - self.buttonLayout.setContentsMargins(0, 0, 0, 0) - self.buttonLayout.addStretch(1) - self.buttonLayout.addWidget(self.addButton) - self.buttonLayout.addWidget(self.removeButton) - self.buttonLayout.addSpacing(2) self.setLayout(self.buttonLayout) - def enableRemoveButton(self, state): - """Enable or disable the remove button""" - self.removeButton.setEnabled(state) + def enableRemoveButton(self, state: bool): + """Enable or disable the remove button.""" + if self.removeButton: + self.removeButton.setEnabled(state) class CaseList(QWidget): @@ -72,9 +68,8 @@ def __init__(self, config: ErtConfig, notifier: ErtNotifier, ensemble_size: int) layout.addWidget(QLabel("Available cases:")) layout.addWidget(self._list, stretch=1) - self._addRemoveWidget = AddRemoveWidget(self.addItem, self.removeItem) - self._addRemoveWidget.enableRemoveButton(False) - layout.addWidget(self._addRemoveWidget) + self._addWidget = AddWidget(self.addItem) + layout.addWidget(self._addWidget) self._title = "New keyword" self._description = "Enter name of keyword:" @@ -108,10 +103,6 @@ def addItem(self): self.notifier.set_current_case(ensemble) self.notifier.ertChanged.emit() - def removeItem(self): - message = "Support for removal of items has not been implemented!" - QMessageBox.information(self, "Not implemented!", message) - def updateList(self): """Retrieves data from the model and inserts it into the list""" case_list = sorted( diff --git a/tests/unit_tests/gui/conftest.py b/tests/unit_tests/gui/conftest.py index 3b597e85b4f..1dee7b5839a 100644 --- a/tests/unit_tests/gui/conftest.py +++ b/tests/unit_tests/gui/conftest.py @@ -31,7 +31,7 @@ REALIZATION_STATE_UNKNOWN, ) from ert.gui.ertwidgets import ClosableDialog -from ert.gui.ertwidgets.caselist import AddRemoveWidget +from ert.gui.ertwidgets.caselist import AddWidget from ert.gui.ertwidgets.caseselector import CaseSelector from ert.gui.ertwidgets.validateddialog import ValidatedDialog from ert.gui.main import ErtMainWindow, GUILogHandler, _setup_main_window @@ -412,7 +412,7 @@ def handle_dialog(dialog, cases_panel): cases_panel.setCurrentIndex(0) current_tab = cases_panel.currentWidget() assert current_tab.objectName() == "create_new_case_tab" - create_widget = get_child(current_tab, AddRemoveWidget) + create_widget = get_child(current_tab, AddWidget) # Click add case and name it "iter-0" def handle_add_dialog(): diff --git a/tests/unit_tests/gui/test_main_window.py b/tests/unit_tests/gui/test_main_window.py index 5bcd94ca4b9..e1477aebc0f 100644 --- a/tests/unit_tests/gui/test_main_window.py +++ b/tests/unit_tests/gui/test_main_window.py @@ -23,7 +23,7 @@ from ert.config import ErtConfig from ert.enkf_main import EnKFMain from ert.gui.ertwidgets.analysismodulevariablespanel import AnalysisModuleVariablesPanel -from ert.gui.ertwidgets.caselist import AddRemoveWidget, CaseList +from ert.gui.ertwidgets.caselist import AddWidget, CaseList from ert.gui.ertwidgets.caseselector import CaseSelector from ert.gui.ertwidgets.customdialog import CustomDialog from ert.gui.ertwidgets.listeditbox import ListEditBox @@ -504,7 +504,7 @@ def handle_dialog(dialog, cases_panel): cases_panel.setCurrentIndex(0) current_tab = cases_panel.currentWidget() assert current_tab.objectName() == "create_new_case_tab" - create_widget = get_child(current_tab, AddRemoveWidget) + create_widget = get_child(current_tab, AddWidget) case_list = get_child(current_tab, CaseList) # The case list should contain the expected cases @@ -644,7 +644,7 @@ def handle_dialog(dialog, cases_panel): cases_panel.setCurrentIndex(0) current_tab = cases_panel.currentWidget() assert current_tab.objectName() == "create_new_case_tab" - create_widget = get_child(current_tab, AddRemoveWidget) + create_widget = get_child(current_tab, AddWidget) case_list = get_child(current_tab, CaseList) assert case_list._list.count() == 0