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 # # 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"]
) )
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): 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,8 +1397,6 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
) )
geometry.show() geometry.show()
return geometry return geometry
else:
self.msg_select_reach()
return None return None
def open_meshing(self): def open_meshing(self):
@ -1464,8 +1480,7 @@ 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(
@ -1480,11 +1495,9 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
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

View File

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