From 631f06e7d6ed7c23b50c5bd31baecf0817de4324 Mon Sep 17 00:00:00 2001
From: Pierre-Antoine Rouby <pierre-antoine.rouby@inrae.fr>
Date: Wed, 5 Apr 2023 13:47:07 +0200
Subject: [PATCH] pamhyr: Disable posibility to open multiple network window.

---
 src/View/ListedSubWindow.py | 9 +++++++++
 src/View/MainWindow.py      | 8 +++++++-
 2 files changed, 16 insertions(+), 1 deletion(-)

diff --git a/src/View/ListedSubWindow.py b/src/View/ListedSubWindow.py
index 3e46bbad..719de3d6 100644
--- a/src/View/ListedSubWindow.py
+++ b/src/View/ListedSubWindow.py
@@ -1,5 +1,7 @@
 # -*- coding: utf-8 -*-
 
+from functools import reduce
+
 class ListedSubWindow(object):
     def __init__(self):
         super(ListedSubWindow, self).__init__()
@@ -26,3 +28,10 @@ class ListedSubWindow(object):
         )
         self.sub_win_cnt = len(self.sub_win_list)
         print(f"- {name} ({self.sub_win_cnt})")
+
+    def sub_win_exists(self, name):
+        return reduce(
+            lambda acc, n: (acc or (n[0] == name)),
+            self.sub_win_list,
+            False
+        )
diff --git a/src/View/MainWindow.py b/src/View/MainWindow.py
index c99c4e3a..6f9a82be 100644
--- a/src/View/MainWindow.py
+++ b/src/View/MainWindow.py
@@ -289,11 +289,17 @@ class ApplicationWindow(QMainWindow, ListedSubWindow):
         Returns:
             Nothing
         """
-        if not self.model is None:
+        if (self.model is not None and
+            not self.sub_win_exists("River network")):
             self.network = NetworkWindow(model=self.model, parent=self)
             self.network.show()
 
     def open_geometry(self):
+        """Open geometry window
+
+        Returns:
+            Nothing
+        """
         if not self.model is None:
             geometry = GeometryWindow(parent=self)
             geometry.show()
-- 
GitLab