mirror of https://gitlab.com/pamhyr/pamhyr2
Replace missing reach warning with a reach selection dropdown list on opening geometry, frictions, sediment layers, and initial conditions
parent
6d4dc3a22b
commit
d97620ad56
|
|
@ -918,13 +918,31 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
|
||||||
# MSG AND DIALOG #
|
# MSG AND DIALOG #
|
||||||
##################
|
##################
|
||||||
|
|
||||||
def msg_select_reach(self):
|
def ensure_current_reach(self):
|
||||||
self.message_box(
|
"""Offer a reach selection when needed; return False on cancellation."""
|
||||||
window_title=self._trad["Warning"],
|
if self._study is None:
|
||||||
text=self._trad["mb_select_reach_title"],
|
return False
|
||||||
informative_text=self._trad["mb_select_reach_msg"]
|
river = self._study.river
|
||||||
|
if river.has_current_reach():
|
||||||
|
return True
|
||||||
|
edges = list(river.edges())
|
||||||
|
if not edges:
|
||||||
|
QMessageBox.information(
|
||||||
|
self, self._trad["Select reach"], self._trad["no_reach"]
|
||||||
|
)
|
||||||
|
return False
|
||||||
|
labels = [f"{edge.name or self._trad['reach']} (#{edge.id})"
|
||||||
|
for edge in edges]
|
||||||
|
selected, accepted = QInputDialog.getItem(
|
||||||
|
self, self._trad["Select reach"],
|
||||||
|
self._trad["reach"] + ":", labels, 0, False
|
||||||
)
|
)
|
||||||
self.open_network()
|
if not accepted:
|
||||||
|
return False
|
||||||
|
river.set_current_reach(edges[labels.index(selected)])
|
||||||
|
self._tab_widget_graph.update()
|
||||||
|
self._propagate_update(key=Modules.NETWORK)
|
||||||
|
return True
|
||||||
|
|
||||||
def dialog_reopen_study(self):
|
def dialog_reopen_study(self):
|
||||||
dlg = QMessageBox(self)
|
dlg = QMessageBox(self)
|
||||||
|
|
@ -1359,7 +1377,7 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
|
||||||
Returns:
|
Returns:
|
||||||
Nothing
|
Nothing
|
||||||
"""
|
"""
|
||||||
if (self._study is not None and self._study.river.has_current_reach()):
|
if self.ensure_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(
|
||||||
|
|
@ -1379,9 +1397,7 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
|
||||||
)
|
)
|
||||||
geometry.show()
|
geometry.show()
|
||||||
return geometry
|
return geometry
|
||||||
else:
|
return None
|
||||||
self.msg_select_reach()
|
|
||||||
return None
|
|
||||||
|
|
||||||
def open_meshing(self):
|
def open_meshing(self):
|
||||||
"""Open the current reach geometry and its meshing dialog."""
|
"""Open the current reach geometry and its meshing dialog."""
|
||||||
|
|
@ -1464,27 +1480,24 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
|
||||||
strick.show()
|
strick.show()
|
||||||
|
|
||||||
def open_frictions(self):
|
def open_frictions(self):
|
||||||
if self._study is not None:
|
if self.ensure_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, self.conf, reach]
|
data=[self._study, self.conf, reach]
|
||||||
):
|
):
|
||||||
return
|
return
|
||||||
|
|
||||||
frictions = FrictionsWindow(
|
frictions = FrictionsWindow(
|
||||||
study=self._study,
|
study=self._study,
|
||||||
config=self.conf,
|
config=self.conf,
|
||||||
parent=self
|
parent=self
|
||||||
)
|
)
|
||||||
frictions.show()
|
frictions.show()
|
||||||
else:
|
|
||||||
self.msg_select_reach()
|
|
||||||
|
|
||||||
def open_initial_conditions(self):
|
def open_initial_conditions(self):
|
||||||
if self._study.river.has_current_reach():
|
if self.ensure_current_reach():
|
||||||
reach = self._study.river.current_reach()
|
reach = self._study.river.current_reach()
|
||||||
|
|
||||||
if self.sub_window_exists(
|
if self.sub_window_exists(
|
||||||
|
|
@ -1500,8 +1513,6 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
|
||||||
parent=self
|
parent=self
|
||||||
)
|
)
|
||||||
initial.show()
|
initial.show()
|
||||||
else:
|
|
||||||
self.msg_select_reach()
|
|
||||||
|
|
||||||
def open_additional_files(self):
|
def open_additional_files(self):
|
||||||
if self._study is not None:
|
if self._study is not None:
|
||||||
|
|
@ -1575,8 +1586,7 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
|
|
||||||
if not self._study.river.has_current_reach():
|
if not self.ensure_current_reach():
|
||||||
self.msg_select_reach()
|
|
||||||
return
|
return
|
||||||
|
|
||||||
reach = self._study.river.current_reach().reach
|
reach = self._study.river.current_reach().reach
|
||||||
|
|
|
||||||
|
|
@ -209,13 +209,8 @@ class MainTranslate(UnitTranslate):
|
||||||
self._dict["Warning"] = _translate(
|
self._dict["Warning"] = _translate(
|
||||||
"MainWindow", "Warning"
|
"MainWindow", "Warning"
|
||||||
)
|
)
|
||||||
self._dict["mb_select_reach_title"] = _translate(
|
self._dict["no_reach"] = _translate(
|
||||||
"MainWindow", "Please select a reach"
|
"MainWindow", "Create a reach in the network before opening this window."
|
||||||
)
|
|
||||||
self._dict["mb_select_reach_msg"] = _translate(
|
|
||||||
"MainWindow",
|
|
||||||
"This edition window need a reach selected "
|
|
||||||
"into the river network to work on it"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
self._dict["mb_last_open_title"] = _translate(
|
self._dict["mb_last_open_title"] = _translate(
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue