diff --git a/src/View/ASubWindow.py b/src/View/ASubWindow.py index c07465f1a153c93b58f5b601b9bf2239f30a1f0d..d9e121f4d0c411087eb80cfbcafa51d59b65c728 100644 --- a/src/View/ASubWindow.py +++ b/src/View/ASubWindow.py @@ -462,10 +462,12 @@ class ASubWindowFeatures(object): class ASubMainWindow(QMainWindow, ASubWindowFeatures, WindowToolKit): def __init__(self, name="", ui="dummy", parent=None): super(ASubMainWindow, self).__init__(parent=parent) - self.ui = loadUi( - os.path.join(os.path.dirname(__file__), "ui", f"{ui}.ui"), - self - ) + if ui is not None: + self.ui = loadUi( + os.path.join(os.path.dirname(__file__), "ui", f"{ui}.ui"), + self + ) + self.name = name self.parent = parent if self.parent is not None: diff --git a/src/View/Geometry/Profile/Window.py b/src/View/Geometry/Profile/Window.py index cfcf6925d93b0b0bb255e091e94e3f8919d378ba..9f7df09031865de801b054da8cf0022dd3c0b782 100644 --- a/src/View/Geometry/Profile/Window.py +++ b/src/View/Geometry/Profile/Window.py @@ -37,7 +37,7 @@ from PyQt5.QtWidgets import ( from Model.Geometry.Reach import Reach from Model.Geometry.ProfileXYZ import ProfileXYZ -from View.ASubWindow import WindowToolKit +from View.ASubWindow import ASubMainWindow from View.Geometry.Profile.mainwindow_ui_profile import Ui_MainWindow from View.Geometry.Profile.Plot import Plot from View.Geometry.Profile.Table import * @@ -45,10 +45,14 @@ from View.Geometry.Profile.Table import * _translate = QCoreApplication.translate -class ProfileWindow(QMainWindow, WindowToolKit): - def __init__(self, profile=None, parent=None): +class ProfileWindow(ASubMainWindow): + def __init__(self, profile=None, title="Profile", parent=None): + self._title = title self.parent = parent - super(ProfileWindow, self).__init__(self.parent) + super(ProfileWindow, self).__init__( + name=self._title, + parent=self.parent + ) self.ui = Ui_MainWindow() self.ui.setupUi(self) diff --git a/src/View/Geometry/Window.py b/src/View/Geometry/Window.py index 9fd0f6f2a709141f6269b8d76564729579a07ec0..46e339f6ef8712ffae4c86384fc9730c6b58bbd3 100644 --- a/src/View/Geometry/Window.py +++ b/src/View/Geometry/Window.py @@ -41,7 +41,8 @@ from View.Geometry.PlotXY import PlotXY from View.Geometry.PlotKPC import PlotKPC from View.Geometry.PlotAC import PlotAC -from View.ASubWindow import WindowToolKit +from View.ASubWindow import ASubMainWindow, WindowToolKit +from View.ListedSubWindow import ListedSubWindow from View.Geometry.mainwindow_ui_reach import Ui_MainWindow from View.Geometry.Table import * from View.Geometry.Profile.Window import ProfileWindow @@ -49,10 +50,14 @@ from View.Geometry.Profile.Window import ProfileWindow _translate = QCoreApplication.translate -class GeometryWindow(QMainWindow, WindowToolKit): - def __init__(self, model=None, parent=None): +class GeometryWindow(ASubMainWindow, ListedSubWindow): + def __init__(self, model=None, title="Geometry", parent=None): + self._title = title self.parent = parent - super(GeometryWindow, self).__init__(parent=parent) + super(GeometryWindow, self).__init__( + name=self._title, + parent=parent + ) self._model = model self._reach = model.river.current_reach().reach diff --git a/src/View/ListedSubWindow.py b/src/View/ListedSubWindow.py index 37d64234700326f15f5a0b44cea18afb3bee2c04..eaef39ef6cbb2a77c6bbaed8e97240c5a6f47db6 100644 --- a/src/View/ListedSubWindow.py +++ b/src/View/ListedSubWindow.py @@ -48,9 +48,32 @@ class ListedSubWindow(object): self.sub_win_cnt = len(self.sub_win_list) logger.info(f"Close window: {name} ({self.sub_win_cnt})") - def sub_win_exists(self, name): + def _sub_win_exists(self, name): return reduce( lambda acc, n: (acc or (n[0] == name)), self.sub_win_list, False ) + + def _sub_win_exists_with_contain(self, name, contain): + return reduce( + lambda acc, n: ( + acc or + ( + (n[0] == name) and + reduce( + lambda acc, a: acc and (a in n[1]._title), + contain, + True + ) + ) + ), + self.sub_win_list, + False + ) + + def sub_win_exists(self, name, contain = []): + if contain == []: + self._sub_win_exists(name) + else: + self._sub_win_exists_with_contain(name, contain)