Merge branch 'doc-dev' with refactoring and user/dev documentation.

This commit is contained in:
Pierre-Antoine Rouby committed 2023-10-09 11:17:13 +02:00
commit 44b057c522
117 files changed
+3813 -3160

No files matched your search

+85 -53
View File
@@ -36,8 +36,8 @@ from PyQt5.QtWidgets import (
)
from PyQt5.uic import loadUi
from View.ASubWindow import WindowToolKit
from View.ListedSubWindow import ListedSubWindow
from View.Tools.ASubWindow import WindowToolKit
from View.Tools.ListedSubWindow import ListedSubWindow
from View.DummyWindow import DummyWindow
from View.Configure.Window import ConfigureWindow
@@ -56,6 +56,7 @@ from View.SolverParameters.Window import SolverParametersWindow
from View.RunSolver.Window import SelectSolverWindow, SolverLogWindow
from View.CheckList.Window import CheckListWindow
from View.Results.Window import ResultsWindow
from View.Doc.Window import DocWindow
from View.Debug.Window import ReplWindow
from Model.Study import Study
@@ -108,9 +109,10 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
self.conf = conf
# Model
self.model = None
self._study = None
# Results
self._last_solver = None
self._last_results = None
# UI
@@ -133,8 +135,8 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
def set_title(self):
title = "(dbg) " if self.conf.debug else ""
if self.model is not None:
title += f"Pamhyr2 - {self.model.name}"
if self._study is not None:
title += f"Pamhyr2 - {self._study.name}"
self.setWindowTitle(title)
else:
title += "Pamhyr2"
@@ -150,6 +152,7 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
Returns:
Nothing
"""
logger.debug(f"Set {action} to {enable}")
self.findChild(QAction, action).setEnabled(enable)
def setup_sc(self):
@@ -181,7 +184,12 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
"action_menu_sediment_layers": self.open_sediment_layers,
"action_menu_edit_reach_sediment_layers": self.open_reach_sediment_layers,
"action_menu_close": self.close_model,
"action_menu_results_last": self.open_last_results,
## Help
"action_menu_pamhyr_users_pdf": lambda: self.open_doc_user(ext="pdf"),
"action_menu_pamhyr_developers_pdf": lambda: self.open_doc_dev(ext="pdf"),
"action_menu_pamhyr_users_html": lambda: self.open_doc_user(ext="html"),
"action_menu_pamhyr_developers_html": lambda: self.open_doc_dev(ext="html"),
"action_menu_about": self.open_about,
# ToolBar action
"action_toolBar_quit": self.close,
@@ -217,7 +225,7 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
super(ApplicationWindow, self).changeEvent(event)
def close(self):
if self.model is not None and not self.model.is_saved:
if self._study is not None and not self._study.is_saved:
self._close_question = True
if self.dialog_close():
# PAMHYR is close correctly (no crash)
@@ -234,7 +242,7 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
def closeEvent(self, event):
if not self._close_question:
if self.model is not None and not self.model.is_saved:
if self._study is not None and not self._study.is_saved:
if self.dialog_close(cancel = False):
# PAMHYR is close correctly (no crash)
self.conf.set_close_correctly()
@@ -292,16 +300,16 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
#########
def get_model(self):
return self.model
return self._study
def set_model(self, model):
self.model = model
self._study = model
self.update_enable_action()
self.conf.set_last_study(self.model.filename)
self.conf.set_last_study(self._study.filename)
self.set_title()
def close_model(self):
self.model = None
self._study = None
self.update_enable_action()
self.conf.set_close_correctly()
self.set_title()
@@ -315,7 +323,7 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
Returns:
Nothing
"""
no_model = self.model is None
no_model = self._study is None
for action in no_model_action:
self.enable_actions(action, no_model)
@@ -326,9 +334,12 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
for action in model_action:
self.enable_actions(action, not no_model)
def set_results(self, results):
def set_results(self, solver, results):
self._last_solver = solver
self._last_results = results
self.enable_actions("action_menu_results_last", True)
############
# FEATURES #
############
@@ -343,7 +354,7 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
Nothing
"""
self.set_model(Study.open(filename))
logger.info(f"Open Study - {self.model.name}")
logger.info(f"Open Study - {self._study.name}")
self.set_title()
def save_study(self):
@@ -355,22 +366,22 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
Returns:
Nothing
"""
if self.model.filename is None or self.model.filename == "":
if self._study.filename is None or self._study.filename == "":
file_name, _ = QFileDialog.getSaveFileName(
self, "Save File",
"", "Pamhyr(*.pamhyr)"
)
if file_name.rsplit(".", 1)[-1] == "pamhyr":
self.model.filename = file_name
self._study.filename = file_name
else:
self.model.filename = file_name + ".pamhyr"
self._study.filename = file_name + ".pamhyr"
if self.model.is_saved:
if self._study.is_saved:
return
logger.info("Save...")
self.model.save()
self._study.save()
def save_as_study(self):
"""Save current study as new file
@@ -387,11 +398,11 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
)
if file_name[-4:] == ".pamhyr":
self.model.filename = file_name
self._study.filename = file_name
else:
self.model.filename = file_name + ".pamhyr"
self._study.filename = file_name + ".pamhyr"
self.model.save()
self._study.save()
##################
# MSG AND DIALOG #
@@ -457,7 +468,7 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
Returns:
Nothing
"""
self.config = ConfigureWindow(conf=self.conf, parent=self)
self.config = ConfigureWindow(config=self.conf, parent=self)
self.config.show()
def open_about(self):
@@ -477,7 +488,7 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
Returns:
Nothing
"""
if self.model is None:
if self._study is None:
dialog = QFileDialog(self)
dialog.setFileMode(QFileDialog.FileMode.ExistingFile)
dialog.setDefaultSuffix(".pamhyr")
@@ -495,7 +506,7 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
Returns:
Nothing
"""
if self.model is None:
if self._study is None:
self.new_study = NewStudyWindow(parent=self)
self.new_study.show()
@@ -505,8 +516,8 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
Returns:
Nothing
"""
if not self.model is None:
self.new_study = NewStudyWindow(study=self.model, parent=self)
if not self._study is None:
self.new_study = NewStudyWindow(study=self._study, parent=self)
self.new_study.show()
def open_network(self):
@@ -515,9 +526,9 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
Returns:
Nothing
"""
if self.model is not None:
if self._study is not None:
if not self.sub_win_exists("River network"):
self.network = NetworkWindow(model=self.model, parent=self)
self.network = NetworkWindow(study=self._study, parent=self)
self.network.show()
else:
self.network.activateWindow()
@@ -528,14 +539,14 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
Returns:
Nothing
"""
if (self.model is not None and self.model.river.has_current_reach()):
if (self._study is not None and self._study.river.has_current_reach()):
geometry = self.sub_win_filter_first(
"Geometry",
contain = [self.model.river.current_reach().name]
contain = [self._study.river.current_reach().name]
)
if geometry is None:
geometry = GeometryWindow(model=self.model, parent=self)
geometry = GeometryWindow(study=self._study, config=self.conf, parent=self)
geometry.show()
else:
geometry.activateWindow()
@@ -549,7 +560,7 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
)
if bound is None:
bound = BoundaryConditionWindow(study = self.model, parent = self)
bound = BoundaryConditionWindow(study = self._study, parent = self)
bound.show()
else:
bound.activateWindow()
@@ -561,7 +572,7 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
)
if lateral is None:
lateral = LateralContributionWindow(study = self.model, parent = self)
lateral = LateralContributionWindow(study = self._study, parent = self)
lateral.show()
else:
lateral.activateWindow()
@@ -574,7 +585,7 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
if strick is None:
strick = StricklersWindow(
study = self.model,
study = self._study,
config = self.conf,
parent = self
)
@@ -583,17 +594,17 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
strick.activateWindow()
def open_frictions(self):
if (self.model is not None and
self.model.river.has_current_reach()):
if (self._study is not None and
self._study.river.has_current_reach()):
frictions = self.sub_win_filter_first(
"Frictions",
contain = [self.model.river.current_reach().name]
contain = [self._study.river.current_reach().name]
)
if frictions is None:
frictions = FrictionsWindow(
study = self.model,
study = self._study,
parent = self
)
frictions.show()
@@ -603,15 +614,16 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
self.msg_select_reach()
def open_initial_conditions(self):
if self.model.river.has_current_reach():
if self._study.river.has_current_reach():
initial = self.sub_win_filter_first(
"Initial condition",
contain = [self.model.river.current_reach().name]
contain = [self._study.river.current_reach().name]
)
if initial is None:
initial = InitialConditionsWindow(
study = self.model,
study = self._study,
config = self.conf,
parent = self
)
initial.show()
@@ -628,7 +640,7 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
if params is None:
params = SolverParametersWindow(
study = self.model,
study = self._study,
parent = self
)
params.show()
@@ -637,31 +649,31 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
def open_sediment_layers(self):
sl = SedimentLayersWindow(
study = self.model,
study = self._study,
parent = self
)
sl.show()
def open_reach_sediment_layers(self):
sl = ReachSedimentLayersWindow(
study = self.model,
study = self._study,
parent = self
)
sl.show()
def run_solver(self):
if self.model is None:
if self._study is None:
return
run = SelectSolverWindow(
study = self.model,
study = self._study,
config = self.conf,
parent = self
)
if run.exec():
solver = run.solver
check = CheckListWindow(
study = self.model,
study = self._study,
config = self.conf,
solver = solver,
parent = self
@@ -670,7 +682,7 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
def solver_log(self, solver):
sol = SolverLogWindow(
study = self.model,
study = self._study,
config = self.conf,
solver = solver,
parent = self
@@ -694,7 +706,7 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
if res is None:
res = ResultsWindow(
study = self.model,
study = self._study,
solver = solver,
results = results,
parent = self
@@ -703,24 +715,44 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
else:
res.activateWindow()
def open_last_results(self):
if self._last_solver is None or self._last_results is None:
return
self.open_solver_results(self._last_solver, self._last_results)
def open_doc(self, filename):
doc = DocWindow(
filename = filename,
parent = self
)
doc.show()
def open_doc_user(self, ext="pdf"):
self.open_doc(f"Pamhyr2-users.{ext}")
def open_doc_dev(self, ext="pdf"):
self.open_doc(f"Pamhyr2-dev.{ext}")
#########
# DEBUG #
#########
def open_debug(self):
repl = ReplWindow(
study = self.model,
study = self._study,
config = self.conf,
parent = self
)
repl.show()
def open_sqlite(self):
if self.model is None:
if self._study is None:
logger.debug("No study open for sql debuging...")
return
file = self.model.filename
file = self._study.filename
_ = subprocess.Popen(
f"sqlitebrowser {file}",
shell=True