From f074e1fdf254fc592d52ac8a1284a38b605cfc9a Mon Sep 17 00:00:00 2001 From: Pierre-Antoine Rouby <pierre-antoine.rouby@inrae.fr> Date: Fri, 20 Oct 2023 17:01:28 +0200 Subject: [PATCH] Geometry: Fix profile sub window open. --- src/View/Geometry/Profile/Window.py | 2 ++ src/View/Geometry/Window.py | 48 +++++++++++++++++++++-------- 2 files changed, 37 insertions(+), 13 deletions(-) diff --git a/src/View/Geometry/Profile/Window.py b/src/View/Geometry/Profile/Window.py index dfce6d9d..9fd3f1aa 100644 --- a/src/View/Geometry/Profile/Window.py +++ b/src/View/Geometry/Profile/Window.py @@ -65,6 +65,8 @@ class ProfileWindow(PamhyrWindow): parent=parent ) + self._hash_data.append(profile) + self.setup_table() self.setup_plot() self.setup_connections() diff --git a/src/View/Geometry/Window.py b/src/View/Geometry/Window.py index ac021ad1..459bc95d 100644 --- a/src/View/Geometry/Window.py +++ b/src/View/Geometry/Window.py @@ -216,6 +216,30 @@ class GeometryWindow(PamhyrWindow): self.plot_kpc() self.plot_ac() + def _sub_window_exists(self, cls, + data=None): + """Check if window already exists + + Check if window already exists, used to deni window open + duplication + + Args: + cls: Window class, must inerit to PamhyrWindow or + PamhyrDialog + data: Data used for hash computation of cls + + Returns: + The window if hash already exists on sub window dictionary, + otherelse None + """ + hash = cls._hash(data) + if self.sub_win_exists(hash): + win = self.get_sub_win(hash) + win.activateWindow() + return True + else: + return False + def edit_profile(self): self.tableView.model().blockSignals(True) @@ -228,20 +252,18 @@ class GeometryWindow(PamhyrWindow): for row in rows: profile = self._reach.profile(row) - win = self.sub_win_filter_first( - "Profile", - contain=[self._reach.name, str(profile.kp)] - ) + if self._sub_window_exists( + ProfileWindow, + data=[None, None, profile] + ): + continue - if win is None: - win = ProfileWindow( - profile=profile, - parent=self, - ) - self._profile_window.append(win) - win.show() - else: - win.activateWindow() + win = ProfileWindow( + profile=profile, + parent=self, + ) + self._profile_window.append(win) + win.show() self.tableView.model().blockSignals(False) -- GitLab