From 94a0a9665936df6c56eb6bda9216943c8d524dbf Mon Sep 17 00:00:00 2001 From: Pierre-Antoine Rouby <pierre-antoine.rouby@inrae.fr> Date: Fri, 4 Aug 2023 15:55:25 +0200 Subject: [PATCH] BC, LC: Forbidden duplicate window. --- src/View/BoundaryCondition/Edit/Window.py | 2 +- src/View/BoundaryCondition/Window.py | 22 +++++++++++------ src/View/LateralContribution/Edit/Window.py | 8 +++---- src/View/LateralContribution/Window.py | 22 +++++++++++------ src/View/ListedSubWindow.py | 2 +- src/View/MainWindow.py | 26 +++++++++++++++++---- 6 files changed, 57 insertions(+), 25 deletions(-) diff --git a/src/View/BoundaryCondition/Edit/Window.py b/src/View/BoundaryCondition/Edit/Window.py index 9ecd240c..efcf0993 100644 --- a/src/View/BoundaryCondition/Edit/Window.py +++ b/src/View/BoundaryCondition/Edit/Window.py @@ -71,7 +71,7 @@ class EditBoundaryConditionWindow(ASubMainWindow, ListedSubWindow): self._title = ( _translate("Edit boundary condition", self._title) + f" - {self._study.name} " + - f" - {self._data.name} " + + f" - {self._data.name} ({self._data.id}) " + f"({long_types[self._data.bctype]} - {node_name})" ) diff --git a/src/View/BoundaryCondition/Window.py b/src/View/BoundaryCondition/Window.py index af314574..a2853590 100644 --- a/src/View/BoundaryCondition/Window.py +++ b/src/View/BoundaryCondition/Window.py @@ -65,7 +65,7 @@ logger = logging.getLogger() class BoundaryConditionWindow(ASubMainWindow, ListedSubWindow): def __init__(self, title="Boundary conditions", study=None, parent=None): - title = title + " - " + study.name + self._title = title + " - " + study.name super(BoundaryConditionWindow, self).__init__( name=title, ui="BoundaryConditions", parent=parent @@ -79,7 +79,7 @@ class BoundaryConditionWindow(ASubMainWindow, ListedSubWindow): self.setup_graph() self.setup_connections() - self.ui.setWindowTitle(title) + self.ui.setWindowTitle(self._title) def setup_sc(self): self._undo_stack = QUndoStack() @@ -220,9 +220,17 @@ class BoundaryConditionWindow(ASubMainWindow, ListedSubWindow): tab = self.current_tab() rows = self.index_selected_rows() for row in rows: - win = EditBoundaryConditionWindow( - data=self._bcs.get(tab, row), - study=self._study, - parent=self + win = self.sub_win_filter_first( + "Edit boundary condition", + contain = [f"({self._bcs.get(tab, row).id})"] ) - win.show() + + if win is None: + win = EditBoundaryConditionWindow( + data=self._bcs.get(tab, row), + study=self._study, + parent=self + ) + win.show() + else: + win.activateWindow() diff --git a/src/View/LateralContribution/Edit/Window.py b/src/View/LateralContribution/Edit/Window.py index c3459958..3a801591 100644 --- a/src/View/LateralContribution/Edit/Window.py +++ b/src/View/LateralContribution/Edit/Window.py @@ -45,7 +45,7 @@ from View.LateralContribution.Edit.Plot import Plot _translate = QCoreApplication.translate class EditLateralContributionWindow(ASubMainWindow, ListedSubWindow): - def __init__(self, title="Edit lateral conditribution", + def __init__(self, title="Edit lateral contribution", data=None, study=None, parent=None): self._data = data self._study = study @@ -54,7 +54,7 @@ class EditLateralContributionWindow(ASubMainWindow, ListedSubWindow): self.compute_title() super(EditLateralContributionWindow, self).__init__( - name=self._title, ui="EditLateralContribution", parent=parent + name=title, ui="EditLateralContribution", parent=parent ) self.ui.setWindowTitle(self._title) @@ -69,9 +69,9 @@ class EditLateralContributionWindow(ASubMainWindow, ListedSubWindow): edge_name = (self._data.edge.name if self._data.edge is not None else _translate("LateralContribution", "Not associate")) self._title = ( - _translate("Edit Lateral contribution", self._title) + + _translate("Edit lateral contribution", self._title) + f" - {self._study.name} " + - f" - {self._data.name} " + + f" - {self._data.name} ({self._data.id}) " + f"({long_types[self._data.lctype]} - {edge_name})" ) diff --git a/src/View/LateralContribution/Window.py b/src/View/LateralContribution/Window.py index 003ad48e..dc3dd94f 100644 --- a/src/View/LateralContribution/Window.py +++ b/src/View/LateralContribution/Window.py @@ -65,7 +65,7 @@ logger = logging.getLogger() class LateralContributionWindow(ASubMainWindow, ListedSubWindow): def __init__(self, title="Lateral contribution", study=None, parent=None): - title = title + " - " + study.name + self._title = title + " - " + study.name super(LateralContributionWindow, self).__init__( name=title, ui="LateralContributions", parent=parent @@ -79,7 +79,7 @@ class LateralContributionWindow(ASubMainWindow, ListedSubWindow): self.setup_graph() self.setup_connections() - self.ui.setWindowTitle(title) + self.ui.setWindowTitle(self._title) def setup_sc(self): self._undo_stack = QUndoStack() @@ -266,9 +266,17 @@ class LateralContributionWindow(ASubMainWindow, ListedSubWindow): tab = self.current_tab() rows = self.index_selected_rows() for row in rows: - win = EditLateralContributionWindow( - data=self._lcs.get(tab, row), - study=self._study, - parent=self + win = self.sub_win_filter_first( + "Edit lateral contribution", + contain = [f"({self._lcs.get(tab, row).id})"] ) - win.show() + + if win is None: + win = EditLateralContributionWindow( + data=self._lcs.get(tab, row), + study=self._study, + parent=self + ) + win.show() + else: + win.activateWindow() diff --git a/src/View/ListedSubWindow.py b/src/View/ListedSubWindow.py index b44efd61..b4dfe416 100644 --- a/src/View/ListedSubWindow.py +++ b/src/View/ListedSubWindow.py @@ -83,7 +83,7 @@ class ListedSubWindow(object): return next( filter( lambda n: ( - (n[0] == name) and + (name in n[0]) and reduce( lambda acc, c: acc and (c in n[1]._title), contain, diff --git a/src/View/MainWindow.py b/src/View/MainWindow.py index 7b03dfb7..8b028d1b 100644 --- a/src/View/MainWindow.py +++ b/src/View/MainWindow.py @@ -461,7 +461,7 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit): contain = [self.model.river.current_reach().name] ) - if geometry == None: + if geometry is None: geometry = GeometryWindow(model=self.model, parent=self) geometry.show() else: @@ -470,12 +470,28 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit): self.msg_select_reach() def open_boundary_cond(self): - bound = BoundaryConditionWindow(study = self.model, parent = self) - bound.show() + bound = self.sub_win_filter_first( + "Boundary conditions", + contain = [] + ) + + if bound is None: + bound = BoundaryConditionWindow(study = self.model, parent = self) + bound.show() + else: + bound.activateWindow() def open_lateral_contrib(self): - lateral = LateralContributionWindow(study = self.model, parent = self) - lateral.show() + lateral = self.sub_win_filter_first( + "Lateral contribution", + contain = [] + ) + + if lateral is None: + lateral = LateralContributionWindow(study = self.model, parent = self) + lateral.show() + else: + lateral.activateWindow() def open_stricklers(self): strick = StricklersWindow( -- GitLab