From 254f0d0e8e78b928a68f03a76277ccc6822ffd3f Mon Sep 17 00:00:00 2001 From: Pierre-Antoine Rouby <pierre-antoine.rouby@inrae.fr> Date: Fri, 4 Aug 2023 16:17:18 +0200 Subject: [PATCH] Friction: Forbidden duplicate window. --- src/View/Frictions/Window.py | 20 ++++++++++++++------ src/View/MainWindow.py | 35 ++++++++++++++++++++++++++--------- src/View/Stricklers/Window.py | 4 ++-- 3 files changed, 42 insertions(+), 17 deletions(-) diff --git a/src/View/Frictions/Window.py b/src/View/Frictions/Window.py index d5761485..81049593 100644 --- a/src/View/Frictions/Window.py +++ b/src/View/Frictions/Window.py @@ -68,7 +68,7 @@ class FrictionsWindow(ASubMainWindow, ListedSubWindow): self.setup_title(title) super(FrictionsWindow, self).__init__( - name=self._title, ui="Frictions", parent=parent + name=title, ui="Frictions", parent=parent ) self.setup_sc() @@ -246,9 +246,17 @@ class FrictionsWindow(ASubMainWindow, ListedSubWindow): self._table.redo() def edit_stricklers(self): - self.strick = StricklersWindow( - study = self._study, - config = self.parent.conf, - parent = self + strick = self.sub_win_filter_first( + "Stricklers", + contain = [] ) - self.strick.show() + + if strick is None: + strick = StricklersWindow( + study = self._study, + config = self.parent.conf, + parent = self + ) + strick.show() + else: + strick.activateWindow() diff --git a/src/View/MainWindow.py b/src/View/MainWindow.py index 8b028d1b..08c86628 100644 --- a/src/View/MainWindow.py +++ b/src/View/MainWindow.py @@ -494,21 +494,38 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit): lateral.activateWindow() def open_stricklers(self): - strick = StricklersWindow( - study = self.model, - config = self.conf, - parent = self + strick = self.sub_win_filter_first( + "Stricklers", + contain = [] ) - strick.show() + + if strick is None: + strick = StricklersWindow( + study = self.model, + config = self.conf, + parent = self + ) + strick.show() + else: + strick.activateWindow() def open_frictions(self): if (self.model is not None and self.model.river.has_current_reach()): - frictions = FrictionsWindow( - study = self.model, - parent = self + + frictions = self.sub_win_filter_first( + "Frictions", + contain = [self.model.river.current_reach().name] ) - frictions.show() + + if frictions is None: + frictions = FrictionsWindow( + study = self.model, + parent = self + ) + frictions.show() + else: + frictions.activateWindow() else: self.msg_select_reach() diff --git a/src/View/Stricklers/Window.py b/src/View/Stricklers/Window.py index 29f886cb..8726f971 100644 --- a/src/View/Stricklers/Window.py +++ b/src/View/Stricklers/Window.py @@ -51,7 +51,7 @@ logger = logging.getLogger() class StricklersWindow(ASubMainWindow, ListedSubWindow): def __init__(self, title="Stricklers", study=None, config=None, parent=None): - title = title + " - " + study.name + self._title = title + " - " + study.name super(StricklersWindow, self).__init__( name=title, ui="Stricklers", parent=parent @@ -64,7 +64,7 @@ class StricklersWindow(ASubMainWindow, ListedSubWindow): self.setup_table() self.setup_connections() - self.ui.setWindowTitle(title) + self.ui.setWindowTitle(self._title) def setup_sc(self): self._undo_stack = QUndoStack() -- GitLab