mirror of
https://gitlab.com/pamhyr/pamhyr2.git
synced 2026-10-30 03:20:41 +01:00
Pamhyr: Implement window duplication deny mechanism with hash (#7).
This commit is contained in:
1 parent
4c40f675b5
commit
8760cd364d
9 files changed
+186
-122
No files matched your search
+154
-81
@@ -480,6 +480,30 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
|
||||
# SUBWINDOW #
|
||||
#############
|
||||
|
||||
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 open_configure(self):
|
||||
"""Open configure window
|
||||
|
||||
@@ -488,6 +512,12 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
|
||||
Returns:
|
||||
Nothing
|
||||
"""
|
||||
if self._sub_window_exists(
|
||||
ConfigureWindow,
|
||||
data=[None, self.conf]
|
||||
):
|
||||
return
|
||||
|
||||
self.config = ConfigureWindow(config=self.conf, parent=self)
|
||||
self.config.show()
|
||||
|
||||
@@ -499,6 +529,12 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
|
||||
Returns:
|
||||
Nothing
|
||||
"""
|
||||
if self._sub_window_exists(
|
||||
AboutWindow,
|
||||
data=[None, None]
|
||||
):
|
||||
return
|
||||
|
||||
self.about = AboutWindow(parent=self)
|
||||
self.about.show()
|
||||
|
||||
@@ -527,6 +563,12 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
|
||||
Nothing
|
||||
"""
|
||||
if self._study is None:
|
||||
if self._sub_window_exists(
|
||||
NewStudyWindow,
|
||||
data=[None, None]
|
||||
):
|
||||
return
|
||||
|
||||
self.new_study = NewStudyWindow(parent=self)
|
||||
self.new_study.show()
|
||||
|
||||
@@ -537,6 +579,12 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
|
||||
Nothing
|
||||
"""
|
||||
if self._study is not None:
|
||||
if self._sub_window_exists(
|
||||
NewStudyWindow,
|
||||
data=[self._study, None]
|
||||
):
|
||||
return
|
||||
|
||||
self.new_study = NewStudyWindow(study=self._study, parent=self)
|
||||
self.new_study.show()
|
||||
|
||||
@@ -547,11 +595,14 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
|
||||
Nothing
|
||||
"""
|
||||
if self._study is not None:
|
||||
if not self.sub_win_exists("River network"):
|
||||
self.network = NetworkWindow(study=self._study, parent=self)
|
||||
self.network.show()
|
||||
else:
|
||||
self.network.activateWindow()
|
||||
if self._sub_window_exists(
|
||||
NetworkWindow,
|
||||
data=[self._study, None]
|
||||
):
|
||||
return
|
||||
|
||||
self.network = NetworkWindow(study=self._study, parent=self)
|
||||
self.network.show()
|
||||
|
||||
def open_geometry(self):
|
||||
"""Open geometry window
|
||||
@@ -560,115 +611,117 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
|
||||
Nothing
|
||||
"""
|
||||
if (self._study is not None and self._study.river.has_current_reach()):
|
||||
geometry = self.sub_win_filter_first(
|
||||
"Geometry",
|
||||
contain=[self._study.river.current_reach().name]
|
||||
)
|
||||
reach = self._study.river.current_reach().reach
|
||||
|
||||
if geometry is None:
|
||||
geometry = GeometryWindow(
|
||||
study=self._study, config=self.conf, parent=self)
|
||||
geometry.show()
|
||||
else:
|
||||
geometry.activateWindow()
|
||||
if self._sub_window_exists(
|
||||
GeometryWindow,
|
||||
data=[self._study, self.conf, reach]
|
||||
):
|
||||
return
|
||||
|
||||
geometry = GeometryWindow(
|
||||
study=self._study,
|
||||
config=self.conf,
|
||||
reach=reach,
|
||||
parent=self
|
||||
)
|
||||
geometry.show()
|
||||
else:
|
||||
self.msg_select_reach()
|
||||
|
||||
def open_boundary_cond(self):
|
||||
bound = self.sub_win_filter_first(
|
||||
"Boundary conditions",
|
||||
contain=[]
|
||||
)
|
||||
if self._sub_window_exists(
|
||||
BoundaryConditionWindow,
|
||||
data=[self._study, None]
|
||||
):
|
||||
return
|
||||
|
||||
if bound is None:
|
||||
bound = BoundaryConditionWindow(study=self._study, parent=self)
|
||||
bound.show()
|
||||
else:
|
||||
bound.activateWindow()
|
||||
bound = BoundaryConditionWindow(study=self._study, parent=self)
|
||||
bound.show()
|
||||
|
||||
def open_lateral_contrib(self):
|
||||
lateral = self.sub_win_filter_first(
|
||||
"Lateral contribution",
|
||||
contain=[]
|
||||
)
|
||||
if self._sub_window_exists(
|
||||
LateralContributionWindow,
|
||||
data=[self._study, None]
|
||||
):
|
||||
return
|
||||
|
||||
if lateral is None:
|
||||
lateral = LateralContributionWindow(study=self._study, parent=self)
|
||||
lateral.show()
|
||||
else:
|
||||
lateral.activateWindow()
|
||||
lateral = LateralContributionWindow(study=self._study, parent=self)
|
||||
lateral.show()
|
||||
|
||||
def open_stricklers(self):
|
||||
strick = self.sub_win_filter_first(
|
||||
"Stricklers",
|
||||
contain=[]
|
||||
)
|
||||
if self._sub_window_exists(
|
||||
StricklersWindow,
|
||||
data=[self._study, self.conf]
|
||||
):
|
||||
return
|
||||
|
||||
if strick is None:
|
||||
strick = StricklersWindow(
|
||||
study=self._study,
|
||||
config=self.conf,
|
||||
parent=self
|
||||
)
|
||||
strick.show()
|
||||
else:
|
||||
strick.activateWindow()
|
||||
strick = StricklersWindow(
|
||||
study=self._study,
|
||||
config=self.conf,
|
||||
parent=self
|
||||
)
|
||||
strick.show()
|
||||
|
||||
def open_frictions(self):
|
||||
if (self._study is not None and
|
||||
self._study.river.has_current_reach()):
|
||||
if self._study is not None:
|
||||
if self._study.river.has_current_reach():
|
||||
reach = self._study.river.current_reach()
|
||||
|
||||
frictions = self.sub_win_filter_first(
|
||||
"Frictions",
|
||||
contain=[self._study.river.current_reach().name]
|
||||
)
|
||||
if self._sub_window_exists(
|
||||
FrictionsWindow,
|
||||
data=[self._study, None, reach]
|
||||
):
|
||||
return
|
||||
|
||||
if frictions is None:
|
||||
frictions = FrictionsWindow(
|
||||
study=self._study,
|
||||
parent=self
|
||||
)
|
||||
frictions.show()
|
||||
else:
|
||||
frictions.activateWindow()
|
||||
else:
|
||||
self.msg_select_reach()
|
||||
self.msg_select_reach()
|
||||
|
||||
def open_initial_conditions(self):
|
||||
if self._study.river.has_current_reach():
|
||||
initial = self.sub_win_filter_first(
|
||||
"Initial condition",
|
||||
contain=[self._study.river.current_reach().name]
|
||||
)
|
||||
reach = self._study.river.current_reach()
|
||||
|
||||
if initial is None:
|
||||
initial = InitialConditionsWindow(
|
||||
study=self._study,
|
||||
config=self.conf,
|
||||
parent=self
|
||||
)
|
||||
initial.show()
|
||||
else:
|
||||
initial.activateWindow()
|
||||
if self._sub_window_exists(
|
||||
InitialConditionsWindow,
|
||||
data=[self._study, self.conf, reach]
|
||||
):
|
||||
return
|
||||
|
||||
initial = InitialConditionsWindow(
|
||||
study=self._study,
|
||||
config=self.conf,
|
||||
reach=reach,
|
||||
parent=self
|
||||
)
|
||||
initial.show()
|
||||
else:
|
||||
self.msg_select_reach()
|
||||
|
||||
def open_solver_parameters(self):
|
||||
params = self.sub_win_filter_first(
|
||||
"Solver parameters",
|
||||
contain=[]
|
||||
)
|
||||
if self._sub_window_exists(
|
||||
SolverParametersWindow,
|
||||
data=[self._study, None]
|
||||
):
|
||||
return
|
||||
|
||||
if params is None:
|
||||
params = SolverParametersWindow(
|
||||
study=self._study,
|
||||
parent=self
|
||||
)
|
||||
params.show()
|
||||
else:
|
||||
params.activateWindow()
|
||||
params = SolverParametersWindow(
|
||||
study=self._study,
|
||||
parent=self
|
||||
)
|
||||
params.show()
|
||||
|
||||
def open_sediment_layers(self):
|
||||
if self._sub_window_exists(
|
||||
SedimentLayersWindow,
|
||||
data=[self._study, None]
|
||||
):
|
||||
return
|
||||
|
||||
sl = SedimentLayersWindow(
|
||||
study=self._study,
|
||||
parent=self
|
||||
@@ -676,8 +729,17 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
|
||||
sl.show()
|
||||
|
||||
def open_reach_sediment_layers(self):
|
||||
reach = self._study.river.current_reach().reach
|
||||
|
||||
if self._sub_window_exists(
|
||||
ReachSedimentLayersWindow,
|
||||
data=[self._study, None, reach]
|
||||
):
|
||||
return
|
||||
|
||||
sl = ReachSedimentLayersWindow(
|
||||
study=self._study,
|
||||
reach=reach,
|
||||
parent=self
|
||||
)
|
||||
sl.show()
|
||||
@@ -693,6 +755,17 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
|
||||
)
|
||||
if run.exec():
|
||||
solver = run.solver
|
||||
|
||||
if self._sub_window_exists(
|
||||
CheckListWindow,
|
||||
data=[
|
||||
self._study,
|
||||
self.conf,
|
||||
solver
|
||||
]
|
||||
):
|
||||
return
|
||||
|
||||
check = CheckListWindow(
|
||||
study=self._study,
|
||||
config=self.conf,
|
||||
|
||||
Reference in new issue
Block a user