From 809a0dd9cbf051298c2e996ddf2568395ab8a077 Mon Sep 17 00:00:00 2001 From: Pierre-Antoine Rouby <pierre-antoine.rouby@inrae.fr> Date: Mon, 25 Sep 2023 17:01:59 +0200 Subject: [PATCH] refarctoring: Apply PamhyrWindow to frictions. --- src/View/Frictions/Window.py | 58 ++++++++++++++-------------------- src/View/MainWindow.py | 4 +-- src/View/Stricklers/Window.py | 45 +++++++++----------------- src/View/Tools/PamhyrWidget.py | 2 +- 4 files changed, 42 insertions(+), 67 deletions(-) diff --git a/src/View/Frictions/Window.py b/src/View/Frictions/Window.py index 060be330..2a547528 100644 --- a/src/View/Frictions/Window.py +++ b/src/View/Frictions/Window.py @@ -20,8 +20,7 @@ import logging from tools import trace, timer -from View.ASubWindow import ASubMainWindow -from View.ListedSubWindow import ListedSubWindow +from View.Tools.PamhyrWindow import PamhyrWindow from PyQt5.QtGui import ( QKeySequence, @@ -59,39 +58,35 @@ _translate = QCoreApplication.translate logger = logging.getLogger() -class FrictionsWindow(ASubMainWindow, ListedSubWindow): - def __init__(self, title="Frictions", study=None, parent=None): - self._study = study - self._reach = self._study.river.current_reach() +class FrictionsWindow(PamhyrWindow): + _pamhyr_ui = "Frictions" + _pamhyr_name = "Edit frictions" + + def __init__(self, reach=None, study=None, config=None, parent=None): + if reach is not None: + self._reach = reach + else: + self._reach = study.river.current_reach() + self._frictions = self._reach.frictions - self.setup_title(title) + name = ( + self._pamhyr_name + " - " + + study.name + " - " + + self._reach.name + ) super(FrictionsWindow, self).__init__( - name=title, ui="Frictions", parent=parent + title = name, + study = study, + config = config, + parent = parent ) - self.setup_sc() self.setup_table() self.setup_graph() self.setup_connections() - self.ui.setWindowTitle(self._title) - - def setup_title(self, title): - self._title = ( - title + " - " - + self._study.name + " - " - + self._reach.name - ) - - def setup_sc(self): - self._undo_stack = QUndoStack() - - self.undo_sc = QShortcut(QKeySequence.Undo, self) - self.redo_sc = QShortcut(QKeySequence.Redo, self) - self.copy_sc = QShortcut(QKeySequence.Copy, self) - self.paste_sc = QShortcut(QKeySequence.Paste, self) def setup_table(self): retranslate() @@ -156,11 +151,6 @@ class FrictionsWindow(ASubMainWindow, ListedSubWindow): self.find(QAction, "action_sort").triggered.connect(self.sort) self.find(QAction, "action_edit_stricklers").triggered.connect(self.edit_stricklers) - self.undo_sc.activated.connect(self.undo) - self.redo_sc.activated.connect(self.redo) - self.copy_sc.activated.connect(self.copy) - self.paste_sc.activated.connect(self.paste) - table = self.find(QTableView, f"tableView") table.selectionModel()\ .selectionChanged\ @@ -234,16 +224,16 @@ class FrictionsWindow(ASubMainWindow, ListedSubWindow): row = self.index_selected_row() self._table.move_down(row) - def copy(self): + def _copy(self): logger.info("TODO: copy") - def paste(self): + def _paste(self): logger.info("TODO: paste") - def undo(self): + def _undo(self): self._table.undo() - def redo(self): + def _redo(self): self._table.redo() def edit_stricklers(self): diff --git a/src/View/MainWindow.py b/src/View/MainWindow.py index f5b3ffef..562b05d7 100644 --- a/src/View/MainWindow.py +++ b/src/View/MainWindow.py @@ -48,8 +48,8 @@ from View.Geometry.Window import GeometryWindow from View.BoundaryCondition.Window import BoundaryConditionWindow from View.LateralContribution.Window import LateralContributionWindow from View.InitialConditions.Window import InitialConditionsWindow -# from View.Stricklers.Window import StricklersWindow -# from View.Frictions.Window import FrictionsWindow +from View.Stricklers.Window import StricklersWindow +from View.Frictions.Window import FrictionsWindow # from View.SedimentLayers.Window import SedimentLayersWindow # from View.SedimentLayers.Reach.Window import ReachSedimentLayersWindow # from View.SolverParameters.Window import SolverParametersWindow diff --git a/src/View/Stricklers/Window.py b/src/View/Stricklers/Window.py index 12620c4f..d9128d00 100644 --- a/src/View/Stricklers/Window.py +++ b/src/View/Stricklers/Window.py @@ -20,8 +20,7 @@ import logging from tools import trace, timer -from View.ASubWindow import ASubMainWindow -from View.ListedSubWindow import ListedSubWindow +from View.Tools.PamhyrWindow import PamhyrWindow from PyQt5.QtGui import ( QKeySequence, @@ -50,32 +49,23 @@ _translate = QCoreApplication.translate logger = logging.getLogger() -class StricklersWindow(ASubMainWindow, ListedSubWindow): - def __init__(self, title="Stricklers", study=None, config=None, parent=None): - self._title = title + " - " + study.name +class StricklersWindow(PamhyrWindow): + _pamhyr_ui = "Stricklers" + _pamhyr_name = "Stricklers" + + def __init__(self, study=None, config=None, parent=None): + name = self._pamhyr_name + " - " + study.name super(StricklersWindow, self).__init__( - name=title, ui="Stricklers", parent=parent + title = name, + study = study, + config = config, + parent = parent ) - self._study = study - self._config = config - - self.setup_sc() self.setup_table() self.setup_connections() - self.ui.setWindowTitle(self._title) - - def setup_sc(self): - self._undo_stack = QUndoStack() - - self.undo_sc = QShortcut(QKeySequence.Undo, self) - self.redo_sc = QShortcut(QKeySequence.Redo, self) - self.copy_sc = QShortcut(QKeySequence.Copy, self) - self.paste_sc = QShortcut(QKeySequence.Paste, self) - - def setup_table(self): retranslate() self._table = {} @@ -105,11 +95,6 @@ class StricklersWindow(ASubMainWindow, ListedSubWindow): self.find(QAction, "action_del").triggered.connect(self.delete) self.find(QAction, "action_sort").triggered.connect(self.sort) - self.undo_sc.activated.connect(self.undo) - self.redo_sc.activated.connect(self.redo) - self.copy_sc.activated.connect(self.copy) - self.paste_sc.activated.connect(self.paste) - def index_selected_rows(self): table = self.find(QTableView, f"tableView_study") return list( @@ -139,14 +124,14 @@ class StricklersWindow(ASubMainWindow, ListedSubWindow): def sort(self): self._table['study'].sort(False) - def copy(self): + def _copy(self): logger.info("TODO: copy") - def paste(self): + def _paste(self): logger.info("TODO: paste") - def undo(self): + def _undo(self): self._table['study'].undo() - def redo(self): + def _redo(self): self._table['study'].redo() diff --git a/src/View/Tools/PamhyrWidget.py b/src/View/Tools/PamhyrWidget.py index 22bf9584..8c85b1c1 100644 --- a/src/View/Tools/PamhyrWidget.py +++ b/src/View/Tools/PamhyrWidget.py @@ -31,7 +31,7 @@ from View.Tools.ASubWindow import AWidget logger = logging.getLogger() class PamhyrWidget(AWidget): - _pamhyr_ui = "" + _pamhyr_ui = None _pamhyr_name = "PamhyrWidget" def __init__(self, parent=None): -- GitLab