Replace missing reach warning with a reach selection dropdown list on opening geometry, frictions, sediment layers, and initial conditions

dev_dylan
Dylan Jeannin 2026-09-09 10:31:22 +02:00
parent 6d4dc3a22b
commit d97620ad56
2 changed files with 43 additions and 38 deletions

View File

@ -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"]
)
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):
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,9 +1397,7 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
)
geometry.show()
return geometry
else:
self.msg_select_reach()
return None
return None
def open_meshing(self):
"""Open the current reach geometry and its meshing dialog."""
@ -1464,27 +1480,24 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
strick.show()
def open_frictions(self):
if self._study is not None:
if self._study.river.has_current_reach():
reach = self._study.river.current_reach()
if self.ensure_current_reach():
reach = self._study.river.current_reach()
if self.sub_window_exists(
FrictionsWindow,
data=[self._study, self.conf, reach]
):
return
if self.sub_window_exists(
FrictionsWindow,
data=[self._study, self.conf, reach]
):
return
frictions = FrictionsWindow(
study=self._study,
config=self.conf,
parent=self
)
frictions.show()
else:
self.msg_select_reach()
frictions = FrictionsWindow(
study=self._study,
config=self.conf,
parent=self
)
frictions.show()
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

View File

@ -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(