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 #
|
||||
##################
|
||||
|
||||
def msg_select_reach(self):
|
||||
self.message_box(
|
||||
window_title=self._trad["Warning"],
|
||||
text=self._trad["mb_select_reach_title"],
|
||||
informative_text=self._trad["mb_select_reach_msg"]
|
||||
def ensure_current_reach(self):
|
||||
"""Offer a reach selection when needed; return False on cancellation."""
|
||||
if self._study is None:
|
||||
return False
|
||||
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"]
|
||||
)
|
||||
self.open_network()
|
||||
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
|
||||
)
|
||||
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):
|
||||
dlg = QMessageBox(self)
|
||||
|
|
@ -1359,7 +1377,7 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
|
|||
Returns:
|
||||
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
|
||||
|
||||
if self.sub_window_exists(
|
||||
|
|
@ -1379,8 +1397,6 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
|
|||
)
|
||||
geometry.show()
|
||||
return geometry
|
||||
else:
|
||||
self.msg_select_reach()
|
||||
return None
|
||||
|
||||
def open_meshing(self):
|
||||
|
|
@ -1464,8 +1480,7 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
|
|||
strick.show()
|
||||
|
||||
def open_frictions(self):
|
||||
if self._study is not None:
|
||||
if self._study.river.has_current_reach():
|
||||
if self.ensure_current_reach():
|
||||
reach = self._study.river.current_reach()
|
||||
|
||||
if self.sub_window_exists(
|
||||
|
|
@ -1480,11 +1495,9 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
|
|||
parent=self
|
||||
)
|
||||
frictions.show()
|
||||
else:
|
||||
self.msg_select_reach()
|
||||
|
||||
def open_initial_conditions(self):
|
||||
if self._study.river.has_current_reach():
|
||||
if self.ensure_current_reach():
|
||||
reach = self._study.river.current_reach()
|
||||
|
||||
if self.sub_window_exists(
|
||||
|
|
@ -1500,8 +1513,6 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
|
|||
parent=self
|
||||
)
|
||||
initial.show()
|
||||
else:
|
||||
self.msg_select_reach()
|
||||
|
||||
def open_additional_files(self):
|
||||
if self._study is not None:
|
||||
|
|
@ -1575,8 +1586,7 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
|
|||
)
|
||||
return
|
||||
|
||||
if not self._study.river.has_current_reach():
|
||||
self.msg_select_reach()
|
||||
if not self.ensure_current_reach():
|
||||
return
|
||||
|
||||
reach = self._study.river.current_reach().reach
|
||||
|
|
|
|||
|
|
@ -209,13 +209,8 @@ class MainTranslate(UnitTranslate):
|
|||
self._dict["Warning"] = _translate(
|
||||
"MainWindow", "Warning"
|
||||
)
|
||||
self._dict["mb_select_reach_title"] = _translate(
|
||||
"MainWindow", "Please select a reach"
|
||||
)
|
||||
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["no_reach"] = _translate(
|
||||
"MainWindow", "Create a reach in the network before opening this window."
|
||||
)
|
||||
|
||||
self._dict["mb_last_open_title"] = _translate(
|
||||
|
|
|
|||
Loading…
Reference in New Issue