mirror of https://gitlab.com/pamhyr/pamhyr2
BC, LC: Fix sub window open.
parent
f074e1fdf2
commit
e395f9f575
|
|
@ -124,6 +124,8 @@ class EditBoundaryConditionWindow(PamhyrWindow):
|
|||
parent=parent
|
||||
)
|
||||
|
||||
self._hash_data.append(data)
|
||||
|
||||
self.setup_table()
|
||||
self.setup_plot()
|
||||
self.setup_data()
|
||||
|
|
|
|||
|
|
@ -214,17 +214,17 @@ class BoundaryConditionWindow(PamhyrWindow):
|
|||
tab = self.current_tab()
|
||||
rows = self.index_selected_rows()
|
||||
for row in rows:
|
||||
win = self.sub_win_filter_first(
|
||||
"Edit boundary condition",
|
||||
contain=[f"({self._bcs.get(tab, row).id})"]
|
||||
)
|
||||
data = self._bcs.get(tab, row)
|
||||
|
||||
if win is None:
|
||||
win = EditBoundaryConditionWindow(
|
||||
data=self._bcs.get(tab, row),
|
||||
study=self._study,
|
||||
parent=self
|
||||
)
|
||||
win.show()
|
||||
else:
|
||||
win.activateWindow()
|
||||
if self.sub_window_exists(
|
||||
EditBoundaryConditionWindow,
|
||||
data=[self._study, None, data]
|
||||
):
|
||||
continue
|
||||
|
||||
win = EditBoundaryConditionWindow(
|
||||
data=data,
|
||||
study=self._study,
|
||||
parent=self
|
||||
)
|
||||
win.show()
|
||||
|
|
|
|||
|
|
@ -216,30 +216,6 @@ 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)
|
||||
|
||||
|
|
@ -252,7 +228,7 @@ class GeometryWindow(PamhyrWindow):
|
|||
for row in rows:
|
||||
profile = self._reach.profile(row)
|
||||
|
||||
if self._sub_window_exists(
|
||||
if self.sub_window_exists(
|
||||
ProfileWindow,
|
||||
data=[None, None, profile]
|
||||
):
|
||||
|
|
|
|||
|
|
@ -77,6 +77,8 @@ class EditLateralContributionWindow(PamhyrWindow):
|
|||
parent=parent
|
||||
)
|
||||
|
||||
self._hash_data.append(data)
|
||||
|
||||
self.setup_table()
|
||||
self.setup_plot()
|
||||
self.setup_connections()
|
||||
|
|
|
|||
|
|
@ -258,17 +258,17 @@ class LateralContributionWindow(PamhyrWindow):
|
|||
tab = self.current_tab()
|
||||
rows = self.index_selected_rows()
|
||||
for row in rows:
|
||||
win = self.sub_win_filter_first(
|
||||
"Edit lateral contribution",
|
||||
contain=[f"({self._lcs.get(tab, row).id})"]
|
||||
)
|
||||
data = self._lcs.get(tab, row)
|
||||
|
||||
if win is None:
|
||||
win = EditLateralContributionWindow(
|
||||
data=self._lcs.get(tab, row),
|
||||
study=self._study,
|
||||
parent=self
|
||||
)
|
||||
win.show()
|
||||
else:
|
||||
win.activateWindow()
|
||||
if self.sub_window_exists(
|
||||
EditLateralContributionWindow,
|
||||
data=[self._study, None, data]
|
||||
):
|
||||
continue
|
||||
|
||||
win = EditLateralContributionWindow(
|
||||
data=data,
|
||||
study=self._study,
|
||||
parent=self
|
||||
)
|
||||
win.show()
|
||||
|
|
|
|||
|
|
@ -480,30 +480,6 @@ 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
|
||||
|
||||
|
|
@ -512,7 +488,7 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
|
|||
Returns:
|
||||
Nothing
|
||||
"""
|
||||
if self._sub_window_exists(
|
||||
if self.sub_window_exists(
|
||||
ConfigureWindow,
|
||||
data=[None, self.conf]
|
||||
):
|
||||
|
|
@ -529,7 +505,7 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
|
|||
Returns:
|
||||
Nothing
|
||||
"""
|
||||
if self._sub_window_exists(
|
||||
if self.sub_window_exists(
|
||||
AboutWindow,
|
||||
data=[None, None]
|
||||
):
|
||||
|
|
@ -563,7 +539,7 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
|
|||
Nothing
|
||||
"""
|
||||
if self._study is None:
|
||||
if self._sub_window_exists(
|
||||
if self.sub_window_exists(
|
||||
NewStudyWindow,
|
||||
data=[None, None]
|
||||
):
|
||||
|
|
@ -579,7 +555,7 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
|
|||
Nothing
|
||||
"""
|
||||
if self._study is not None:
|
||||
if self._sub_window_exists(
|
||||
if self.sub_window_exists(
|
||||
NewStudyWindow,
|
||||
data=[self._study, None]
|
||||
):
|
||||
|
|
@ -595,7 +571,7 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
|
|||
Nothing
|
||||
"""
|
||||
if self._study is not None:
|
||||
if self._sub_window_exists(
|
||||
if self.sub_window_exists(
|
||||
NetworkWindow,
|
||||
data=[self._study, None]
|
||||
):
|
||||
|
|
@ -613,7 +589,7 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
|
|||
if (self._study is not None and self._study.river.has_current_reach()):
|
||||
reach = self._study.river.current_reach().reach
|
||||
|
||||
if self._sub_window_exists(
|
||||
if self.sub_window_exists(
|
||||
GeometryWindow,
|
||||
data=[self._study, self.conf, reach]
|
||||
):
|
||||
|
|
@ -630,7 +606,7 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
|
|||
self.msg_select_reach()
|
||||
|
||||
def open_boundary_cond(self):
|
||||
if self._sub_window_exists(
|
||||
if self.sub_window_exists(
|
||||
BoundaryConditionWindow,
|
||||
data=[self._study, None]
|
||||
):
|
||||
|
|
@ -640,7 +616,7 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
|
|||
bound.show()
|
||||
|
||||
def open_lateral_contrib(self):
|
||||
if self._sub_window_exists(
|
||||
if self.sub_window_exists(
|
||||
LateralContributionWindow,
|
||||
data=[self._study, None]
|
||||
):
|
||||
|
|
@ -650,7 +626,7 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
|
|||
lateral.show()
|
||||
|
||||
def open_stricklers(self):
|
||||
if self._sub_window_exists(
|
||||
if self.sub_window_exists(
|
||||
StricklersWindow,
|
||||
data=[self._study, self.conf]
|
||||
):
|
||||
|
|
@ -668,7 +644,7 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
|
|||
if self._study.river.has_current_reach():
|
||||
reach = self._study.river.current_reach()
|
||||
|
||||
if self._sub_window_exists(
|
||||
if self.sub_window_exists(
|
||||
FrictionsWindow,
|
||||
data=[self._study, None, reach]
|
||||
):
|
||||
|
|
@ -686,7 +662,7 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
|
|||
if self._study.river.has_current_reach():
|
||||
reach = self._study.river.current_reach()
|
||||
|
||||
if self._sub_window_exists(
|
||||
if self.sub_window_exists(
|
||||
InitialConditionsWindow,
|
||||
data=[self._study, self.conf, reach]
|
||||
):
|
||||
|
|
@ -703,7 +679,7 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
|
|||
self.msg_select_reach()
|
||||
|
||||
def open_solver_parameters(self):
|
||||
if self._sub_window_exists(
|
||||
if self.sub_window_exists(
|
||||
SolverParametersWindow,
|
||||
data=[self._study, None]
|
||||
):
|
||||
|
|
@ -716,7 +692,7 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
|
|||
params.show()
|
||||
|
||||
def open_sediment_layers(self):
|
||||
if self._sub_window_exists(
|
||||
if self.sub_window_exists(
|
||||
SedimentLayersWindow,
|
||||
data=[self._study, None]
|
||||
):
|
||||
|
|
@ -731,7 +707,7 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
|
|||
def open_reach_sediment_layers(self):
|
||||
reach = self._study.river.current_reach().reach
|
||||
|
||||
if self._sub_window_exists(
|
||||
if self.sub_window_exists(
|
||||
ReachSedimentLayersWindow,
|
||||
data=[self._study, None, reach]
|
||||
):
|
||||
|
|
@ -756,7 +732,7 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
|
|||
if run.exec():
|
||||
solver = run.solver
|
||||
|
||||
if self._sub_window_exists(
|
||||
if self.sub_window_exists(
|
||||
CheckListWindow,
|
||||
data=[
|
||||
self._study,
|
||||
|
|
@ -793,7 +769,7 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
|
|||
return
|
||||
|
||||
# Windows already opened
|
||||
if self._sub_window_exists(
|
||||
if self.sub_window_exists(
|
||||
ResultsWindow,
|
||||
data=[
|
||||
self._study,
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ class ListedSubWindow(object):
|
|||
self.sub_win_cnt += 1
|
||||
try:
|
||||
logger.info(
|
||||
f"Open window: {name}: {self.sub_win_cnt}: {win.hash()}")
|
||||
f"Open window: {name}: {self.sub_win_cnt}")
|
||||
except Exception:
|
||||
logger.info(f"Open window: {name}: {self.sub_win_cnt}: X")
|
||||
logger.warning(f"Sub window without hash method !")
|
||||
|
|
@ -52,7 +52,7 @@ class ListedSubWindow(object):
|
|||
)
|
||||
)
|
||||
self.sub_win_cnt = len(self.sub_win_list)
|
||||
logger.info(f"Close window: {h}: {self.sub_win_cnt}")
|
||||
logger.info(f"Close window: ({h}) {self.sub_win_cnt}")
|
||||
|
||||
def _sub_win_exists(self, h):
|
||||
return reduce(
|
||||
|
|
@ -74,3 +74,27 @@ class ListedSubWindow(object):
|
|||
)[1]
|
||||
except Exception:
|
||||
return None
|
||||
|
||||
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
|
||||
|
|
|
|||
Loading…
Reference in New Issue