From 8d920b92224d11c5fbaa07fcab1bbbbbfd770139 Mon Sep 17 00:00:00 2001 From: Jon Holba Date: Fri, 10 Jan 2025 14:34:37 +0100 Subject: [PATCH] Fixup: reverted windowflags to be the same as before. some minor touchups --- src/ert/gui/ertwidgets/listeditbox.py | 9 ++------ src/ert/gui/model/node.py | 10 ++------- src/ert/gui/model/snapshot.py | 6 ++---- src/ert/gui/simulation/experiment_panel.py | 2 +- src/ert/gui/simulation/run_dialog.py | 21 +++++++++---------- .../customize/limits_customization_view.py | 15 ++++++------- tests/ert/ui_tests/gui/test_main_window.py | 1 + 7 files changed, 24 insertions(+), 40 deletions(-) diff --git a/src/ert/gui/ertwidgets/listeditbox.py b/src/ert/gui/ertwidgets/listeditbox.py index b2096e6c367..e010e8db511 100644 --- a/src/ert/gui/ertwidgets/listeditbox.py +++ b/src/ert/gui/ertwidgets/listeditbox.py @@ -52,12 +52,7 @@ def textUnderCursor(self) -> str: def keyPressEvent(self, arg__1: QKeyEvent) -> None: popup = self._completer.popup() - if ( - popup is not None - and popup.isVisible() - and arg__1 is not None - and arg__1.key() in self.__keysToIgnore - ): + if popup and popup.isVisible() and arg__1.key() in self.__keysToIgnore: arg__1.ignore() return @@ -66,7 +61,7 @@ def keyPressEvent(self, arg__1: QKeyEvent) -> None: completion_prefix = self.textUnderCursor() if completion_prefix != self._completer.completionPrefix(): self.__updateCompleterPopupItems(completion_prefix) - if arg__1 is not None and len(arg__1.text()) > 0 and len(completion_prefix) > 0: + if len(arg__1.text()) > 0 and len(completion_prefix) > 0: self._completer.complete() if popup is not None and len(completion_prefix) == 0: popup.hide() diff --git a/src/ert/gui/model/node.py b/src/ert/gui/model/node.py index 6287a07c34c..b48cd7ac482 100644 --- a/src/ert/gui/model/node.py +++ b/src/ert/gui/model/node.py @@ -14,13 +14,13 @@ class _NodeBase(ABC): _index: int | None = None -def _repr(node: _Node) -> str: +def _repr(node: RootNode | IterNode | RealNode | ForwardModelStepNode) -> str: parent = "no " if node.parent is None else "" children = "no " if not node.children else f"{len(node.children)} " return f"Node<{type(node).__name__}>@{node.id_} with {parent}parent and {children}children" -def _row(node: _Node) -> int: +def _row(node: RootNode | IterNode | RealNode | ForwardModelStepNode) -> int: if not node._index: if node.parent: node._index = list(node.parent.children.keys()).index(node.id_) @@ -105,14 +105,8 @@ class ForwardModelStepNode(_NodeBase): data: FMStepSnapshot = field(default_factory=lambda: FMStepSnapshot()) # noqa: PLW0108 children: dict[str, None] = field(default_factory=dict) - def add_child(self, _: _NodeBase) -> None: - raise RuntimeError(f"Can not add children to {self.__class__.__name__}") - def row(self) -> int: return _row(self) def __repr__(self) -> str: return _repr(self) - - -_Node = RootNode | IterNode | RealNode | ForwardModelStepNode diff --git a/src/ert/gui/model/snapshot.py b/src/ert/gui/model/snapshot.py index 08c06c66152..1b922f3f541 100644 --- a/src/ert/gui/model/snapshot.py +++ b/src/ert/gui/model/snapshot.py @@ -352,7 +352,7 @@ def data( if isinstance(node, ForwardModelStepNode): return self._fm_step_data(index, node, Qt.ItemDataRole(role)) if isinstance(node, RealNode): - return self._real_data(index, node, role) + return self._real_data(node, role) if role == Qt.ItemDataRole.DisplayRole: if index.column() == 0: @@ -383,9 +383,7 @@ def data( return None @staticmethod - def _real_data( - _: QModelIndex | QPersistentModelIndex, node: RealNode, role: int - ) -> Any: + def _real_data(node: RealNode, role: int) -> Any: if role == FMStepColorHint: total_count = len(node.data.fm_step_status_color_by_id) finished_count = sum( diff --git a/src/ert/gui/simulation/experiment_panel.py b/src/ert/gui/simulation/experiment_panel.py index 70a6c51a78e..18294a3ecfa 100644 --- a/src/ert/gui/simulation/experiment_panel.py +++ b/src/ert/gui/simulation/experiment_panel.py @@ -250,7 +250,7 @@ def run_experiment(self) -> None: QMessageBox.warning( self, "ERROR: Failed to create experiment", - (str(e)), + str(e), QMessageBox.StandardButton.Ok, ) return diff --git a/src/ert/gui/simulation/run_dialog.py b/src/ert/gui/simulation/run_dialog.py index cb96009eb8f..8b2aa8eda0d 100644 --- a/src/ert/gui/simulation/run_dialog.py +++ b/src/ert/gui/simulation/run_dialog.py @@ -149,16 +149,15 @@ def _fm_step_clicked(self, index: QModelIndex) -> None: error_dialog.exec() def mouseMoveEvent(self, event: QMouseEvent) -> None: - if event: - index = self.indexAt(event.pos()) - if index.isValid(): - data_name = FM_STEP_COLUMNS[index.column()] - if data_name in {ids.STDOUT, ids.STDERR} and file_has_content( - index.data(FileRole) - ): - self.setCursor(Qt.CursorShape.PointingHandCursor) - else: - self.setCursor(Qt.CursorShape.ArrowCursor) + index = self.indexAt(event.pos()) + if index.isValid(): + data_name = FM_STEP_COLUMNS[index.column()] + if data_name in {ids.STDOUT, ids.STDERR} and file_has_content( + index.data(FileRole) + ): + self.setCursor(Qt.CursorShape.PointingHandCursor) + else: + self.setCursor(Qt.CursorShape.ArrowCursor) return super().mouseMoveEvent(event) @@ -181,7 +180,7 @@ def __init__( QFrame.__init__(self, parent) self.output_path = output_path self.setAttribute(Qt.WidgetAttribute.WA_DeleteOnClose) - self.setWindowFlag(Qt.WindowType.Window, True) + self.setWindowFlags(Qt.WindowType.Window) self.setWindowFlag(Qt.WindowType.WindowContextHelpButtonHint, False) self.setWindowTitle(f"Experiment - {config_file} {find_ert_info()}") diff --git a/src/ert/gui/tools/plot/customize/limits_customization_view.py b/src/ert/gui/tools/plot/customize/limits_customization_view.py index 7a28252b622..6285c291095 100644 --- a/src/ert/gui/tools/plot/customize/limits_customization_view.py +++ b/src/ert/gui/tools/plot/customize/limits_customization_view.py @@ -116,17 +116,14 @@ def getValue(self, axis_name: str | None) -> float | int | date | None: input_ = self._inputs[axis_name] result: float | int | date | None = None if issubclass(type(input_), QLineEdit) or issubclass(type(input_), QLabel): - input_ = cast(QLineEdit | QLabel, input_) - if axis_name in LimitsStack.FLOAT_AXIS: - try: + try: + input_ = cast(QLineEdit | QLabel, input_) + if axis_name in LimitsStack.FLOAT_AXIS: result = float(input_.text()) - except ValueError: - result = None - elif axis_name in LimitsStack.INT_AXIS: - try: + elif axis_name in LimitsStack.INT_AXIS: result = int(input_.text()) - except ValueError: - result = None + except ValueError: + result = None elif axis_name == PlotContext.DATE_AXIS and type(input_) is CustomDateEdit: result = input_.date() diff --git a/tests/ert/ui_tests/gui/test_main_window.py b/tests/ert/ui_tests/gui/test_main_window.py index bf24b653219..97523350300 100644 --- a/tests/ert/ui_tests/gui/test_main_window.py +++ b/tests/ert/ui_tests/gui/test_main_window.py @@ -31,6 +31,7 @@ from ert.gui.ertwidgets.create_experiment_dialog import CreateExperimentDialog from ert.gui.ertwidgets.ensembleselector import EnsembleSelector from ert.gui.main import ErtMainWindow, GUILogHandler, _setup_main_window +from ert.gui.main_window import SidebarToolButton from ert.gui.simulation.experiment_panel import ExperimentPanel from ert.gui.simulation.run_dialog import RunDialog from ert.gui.suggestor import Suggestor