Commit e395f9f5 authored by Pierre-Antoine Rouby's avatar Pierre-Antoine Rouby
Browse files

BC, LC: Fix sub window open.

Showing with 73 additions and 93 deletions
+73 -93
...@@ -124,6 +124,8 @@ class EditBoundaryConditionWindow(PamhyrWindow): ...@@ -124,6 +124,8 @@ class EditBoundaryConditionWindow(PamhyrWindow):
parent=parent parent=parent
) )
self._hash_data.append(data)
self.setup_table() self.setup_table()
self.setup_plot() self.setup_plot()
self.setup_data() self.setup_data()
......
...@@ -214,17 +214,17 @@ class BoundaryConditionWindow(PamhyrWindow): ...@@ -214,17 +214,17 @@ class BoundaryConditionWindow(PamhyrWindow):
tab = self.current_tab() tab = self.current_tab()
rows = self.index_selected_rows() rows = self.index_selected_rows()
for row in rows: for row in rows:
win = self.sub_win_filter_first( data = self._bcs.get(tab, row)
"Edit boundary condition",
contain=[f"({self._bcs.get(tab, row).id})"]
)
if win is None: if self.sub_window_exists(
win = EditBoundaryConditionWindow( EditBoundaryConditionWindow,
data=self._bcs.get(tab, row), data=[self._study, None, data]
study=self._study, ):
parent=self continue
)
win.show() win = EditBoundaryConditionWindow(
else: data=data,
win.activateWindow() study=self._study,
parent=self
)
win.show()
...@@ -216,30 +216,6 @@ class GeometryWindow(PamhyrWindow): ...@@ -216,30 +216,6 @@ class GeometryWindow(PamhyrWindow):
self.plot_kpc() self.plot_kpc()
self.plot_ac() 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): def edit_profile(self):
self.tableView.model().blockSignals(True) self.tableView.model().blockSignals(True)
...@@ -252,7 +228,7 @@ class GeometryWindow(PamhyrWindow): ...@@ -252,7 +228,7 @@ class GeometryWindow(PamhyrWindow):
for row in rows: for row in rows:
profile = self._reach.profile(row) profile = self._reach.profile(row)
if self._sub_window_exists( if self.sub_window_exists(
ProfileWindow, ProfileWindow,
data=[None, None, profile] data=[None, None, profile]
): ):
......
...@@ -77,6 +77,8 @@ class EditLateralContributionWindow(PamhyrWindow): ...@@ -77,6 +77,8 @@ class EditLateralContributionWindow(PamhyrWindow):
parent=parent parent=parent
) )
self._hash_data.append(data)
self.setup_table() self.setup_table()
self.setup_plot() self.setup_plot()
self.setup_connections() self.setup_connections()
......
...@@ -258,17 +258,17 @@ class LateralContributionWindow(PamhyrWindow): ...@@ -258,17 +258,17 @@ class LateralContributionWindow(PamhyrWindow):
tab = self.current_tab() tab = self.current_tab()
rows = self.index_selected_rows() rows = self.index_selected_rows()
for row in rows: for row in rows:
win = self.sub_win_filter_first( data = self._lcs.get(tab, row)
"Edit lateral contribution",
contain=[f"({self._lcs.get(tab, row).id})"]
)
if win is None: if self.sub_window_exists(
win = EditLateralContributionWindow( EditLateralContributionWindow,
data=self._lcs.get(tab, row), data=[self._study, None, data]
study=self._study, ):
parent=self continue
)
win.show() win = EditLateralContributionWindow(
else: data=data,
win.activateWindow() study=self._study,
parent=self
)
win.show()
...@@ -480,30 +480,6 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit): ...@@ -480,30 +480,6 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
# SUBWINDOW # # 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): def open_configure(self):
"""Open configure window """Open configure window
...@@ -512,7 +488,7 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit): ...@@ -512,7 +488,7 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
Returns: Returns:
Nothing Nothing
""" """
if self._sub_window_exists( if self.sub_window_exists(
ConfigureWindow, ConfigureWindow,
data=[None, self.conf] data=[None, self.conf]
): ):
...@@ -529,7 +505,7 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit): ...@@ -529,7 +505,7 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
Returns: Returns:
Nothing Nothing
""" """
if self._sub_window_exists( if self.sub_window_exists(
AboutWindow, AboutWindow,
data=[None, None] data=[None, None]
): ):
...@@ -563,7 +539,7 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit): ...@@ -563,7 +539,7 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
Nothing Nothing
""" """
if self._study is None: if self._study is None:
if self._sub_window_exists( if self.sub_window_exists(
NewStudyWindow, NewStudyWindow,
data=[None, None] data=[None, None]
): ):
...@@ -579,7 +555,7 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit): ...@@ -579,7 +555,7 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
Nothing Nothing
""" """
if self._study is not None: if self._study is not None:
if self._sub_window_exists( if self.sub_window_exists(
NewStudyWindow, NewStudyWindow,
data=[self._study, None] data=[self._study, None]
): ):
...@@ -595,7 +571,7 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit): ...@@ -595,7 +571,7 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
Nothing Nothing
""" """
if self._study is not None: if self._study is not None:
if self._sub_window_exists( if self.sub_window_exists(
NetworkWindow, NetworkWindow,
data=[self._study, None] data=[self._study, None]
): ):
...@@ -613,7 +589,7 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit): ...@@ -613,7 +589,7 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
if (self._study is not None and self._study.river.has_current_reach()): if (self._study is not None and self._study.river.has_current_reach()):
reach = self._study.river.current_reach().reach reach = self._study.river.current_reach().reach
if self._sub_window_exists( if self.sub_window_exists(
GeometryWindow, GeometryWindow,
data=[self._study, self.conf, reach] data=[self._study, self.conf, reach]
): ):
...@@ -630,7 +606,7 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit): ...@@ -630,7 +606,7 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
self.msg_select_reach() self.msg_select_reach()
def open_boundary_cond(self): def open_boundary_cond(self):
if self._sub_window_exists( if self.sub_window_exists(
BoundaryConditionWindow, BoundaryConditionWindow,
data=[self._study, None] data=[self._study, None]
): ):
...@@ -640,7 +616,7 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit): ...@@ -640,7 +616,7 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
bound.show() bound.show()
def open_lateral_contrib(self): def open_lateral_contrib(self):
if self._sub_window_exists( if self.sub_window_exists(
LateralContributionWindow, LateralContributionWindow,
data=[self._study, None] data=[self._study, None]
): ):
...@@ -650,7 +626,7 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit): ...@@ -650,7 +626,7 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
lateral.show() lateral.show()
def open_stricklers(self): def open_stricklers(self):
if self._sub_window_exists( if self.sub_window_exists(
StricklersWindow, StricklersWindow,
data=[self._study, self.conf] data=[self._study, self.conf]
): ):
...@@ -668,7 +644,7 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit): ...@@ -668,7 +644,7 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
if self._study.river.has_current_reach(): if self._study.river.has_current_reach():
reach = self._study.river.current_reach() reach = self._study.river.current_reach()
if self._sub_window_exists( if self.sub_window_exists(
FrictionsWindow, FrictionsWindow,
data=[self._study, None, reach] data=[self._study, None, reach]
): ):
...@@ -686,7 +662,7 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit): ...@@ -686,7 +662,7 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
if self._study.river.has_current_reach(): if self._study.river.has_current_reach():
reach = self._study.river.current_reach() reach = self._study.river.current_reach()
if self._sub_window_exists( if self.sub_window_exists(
InitialConditionsWindow, InitialConditionsWindow,
data=[self._study, self.conf, reach] data=[self._study, self.conf, reach]
): ):
...@@ -703,7 +679,7 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit): ...@@ -703,7 +679,7 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
self.msg_select_reach() self.msg_select_reach()
def open_solver_parameters(self): def open_solver_parameters(self):
if self._sub_window_exists( if self.sub_window_exists(
SolverParametersWindow, SolverParametersWindow,
data=[self._study, None] data=[self._study, None]
): ):
...@@ -716,7 +692,7 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit): ...@@ -716,7 +692,7 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
params.show() params.show()
def open_sediment_layers(self): def open_sediment_layers(self):
if self._sub_window_exists( if self.sub_window_exists(
SedimentLayersWindow, SedimentLayersWindow,
data=[self._study, None] data=[self._study, None]
): ):
...@@ -731,7 +707,7 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit): ...@@ -731,7 +707,7 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
def open_reach_sediment_layers(self): def open_reach_sediment_layers(self):
reach = self._study.river.current_reach().reach reach = self._study.river.current_reach().reach
if self._sub_window_exists( if self.sub_window_exists(
ReachSedimentLayersWindow, ReachSedimentLayersWindow,
data=[self._study, None, reach] data=[self._study, None, reach]
): ):
...@@ -756,7 +732,7 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit): ...@@ -756,7 +732,7 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
if run.exec(): if run.exec():
solver = run.solver solver = run.solver
if self._sub_window_exists( if self.sub_window_exists(
CheckListWindow, CheckListWindow,
data=[ data=[
self._study, self._study,
...@@ -793,7 +769,7 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit): ...@@ -793,7 +769,7 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
return return
# Windows already opened # Windows already opened
if self._sub_window_exists( if self.sub_window_exists(
ResultsWindow, ResultsWindow,
data=[ data=[
self._study, self._study,
......
...@@ -39,7 +39,7 @@ class ListedSubWindow(object): ...@@ -39,7 +39,7 @@ class ListedSubWindow(object):
self.sub_win_cnt += 1 self.sub_win_cnt += 1
try: try:
logger.info( logger.info(
f"Open window: {name}: {self.sub_win_cnt}: {win.hash()}") f"Open window: {name}: {self.sub_win_cnt}")
except Exception: except Exception:
logger.info(f"Open window: {name}: {self.sub_win_cnt}: X") logger.info(f"Open window: {name}: {self.sub_win_cnt}: X")
logger.warning(f"Sub window without hash method !") logger.warning(f"Sub window without hash method !")
...@@ -52,7 +52,7 @@ class ListedSubWindow(object): ...@@ -52,7 +52,7 @@ class ListedSubWindow(object):
) )
) )
self.sub_win_cnt = len(self.sub_win_list) 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): def _sub_win_exists(self, h):
return reduce( return reduce(
...@@ -74,3 +74,27 @@ class ListedSubWindow(object): ...@@ -74,3 +74,27 @@ class ListedSubWindow(object):
)[1] )[1]
except Exception: except Exception:
return None 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
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment