From 559d7dc00680106da6f99df96eba7bf7f52b8879 Mon Sep 17 00:00:00 2001
From: Pierre-Antoine Rouby <pierre-antoine.rouby@inrae.fr>
Date: Fri, 6 Oct 2023 15:54:27 +0200
Subject: [PATCH] doc: Keep doc html and add doc window in Pamhyr2.

---
 .gitlab-ci.yml            |  3 ++
 doc/users/images/.gitkeep |  0
 src/View/Doc/Window.py    | 70 +++++++++++++++++++++++++++++++++++++++
 src/View/MainWindow.py    | 17 ++++++++++
 src/View/ui/MainWindow.ui | 31 +++++++++++++++--
 src/View/ui/WebView.ui    | 50 ++++++++++++++++++++++++++++
 6 files changed, 169 insertions(+), 2 deletions(-)
 create mode 100644 doc/users/images/.gitkeep
 create mode 100644 src/View/Doc/Window.py
 create mode 100644 src/View/ui/WebView.ui

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 7f2aecdf..7b58f4f4 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -98,6 +98,8 @@ build-users-doc:
   artifacts:
     paths:
       - doc/users/documentation.pdf
+      - doc/users/documentation.html
+      - doc/users/images/
 
 build-developers-doc:
   stage: build
@@ -121,6 +123,7 @@ build-developers-doc:
       - doc/dev/documentation.pdf
       - doc/dev/documentation.html
       - doc/dev/html.tar
+      - doc/dev/images/
 
 build-linux:
   stage: build
diff --git a/doc/users/images/.gitkeep b/doc/users/images/.gitkeep
new file mode 100644
index 00000000..e69de29b
diff --git a/src/View/Doc/Window.py b/src/View/Doc/Window.py
new file mode 100644
index 00000000..73416322
--- /dev/null
+++ b/src/View/Doc/Window.py
@@ -0,0 +1,70 @@
+# Window.py -- Pamhyr
+# Copyright (C) 2023  INRAE
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <https://www.gnu.org/licenses/>.
+
+# -*- coding: utf-8 -*-
+
+import os
+import logging
+
+from View.Tools.PamhyrWindow import PamhyrWindow
+
+from PyQt5.QtCore import QCoreApplication
+
+_translate = QCoreApplication.translate
+logger = logging.getLogger()
+
+
+from PyQt5.QtWidgets import QApplication, QWidget
+from PyQt5.QtCore import QUrl
+from PyQt5.QtWebKitWidgets import QWebView
+from PyQt5.QtWebKit import QWebSettings
+
+class DocWindow(PamhyrWindow):
+    _pamhyr_ui = "WebView"
+    _pamhyr_name = "Doc"
+
+    def _path_file(self, filename):
+        return os.path.abspath(
+            os.path.join(
+                os.path.dirname(__file__),
+                "..", "..", "..", "doc", filename
+            )
+        )
+
+    def __init__(self, filename=None,
+                 study=None, config=None,
+                 parent=None):
+        super(DocWindow, self).__init__(
+            title = self._pamhyr_name,
+            study = study,
+            config = config,
+            options = [],
+            parent = parent
+
+        )
+
+        self.setup_setting()
+        self.setup_url(filename)
+
+    def setup_url(self, filename):
+        webView = self.find(QWebView, "webView")
+        webView.setUrl(QUrl(f"file://{self._path_file(filename)}"))
+
+    def setup_setting(self):
+        webView = self.find(QWebView, "webView")
+        settings = webView.settings()
+        settings.setAttribute(QWebSettings.PluginsEnabled, True)
+        settings.setAttribute(QWebSettings.JavascriptEnabled, False)
diff --git a/src/View/MainWindow.py b/src/View/MainWindow.py
index 23c26b51..f304c144 100644
--- a/src/View/MainWindow.py
+++ b/src/View/MainWindow.py
@@ -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
@@ -183,6 +184,8 @@ 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_results_last": self.open_last_results,
+            "action_menu_Pamhyr": self.open_doc_user,
+            "action_menu_Pamhyr_dev": self.open_doc_dev,
             ## Help
             "action_menu_about": self.open_about,
             # ToolBar action
@@ -715,6 +718,20 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
 
         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):
+        self.open_doc("Pamhyr2-users.html")
+
+    def open_doc_dev(self):
+        self.open_doc("Pamhyr2-dev.html")
+
     #########
     # DEBUG #
     #########
diff --git a/src/View/ui/MainWindow.ui b/src/View/ui/MainWindow.ui
index 7578d600..9fd3b229 100644
--- a/src/View/ui/MainWindow.ui
+++ b/src/View/ui/MainWindow.ui
@@ -160,8 +160,15 @@
     <property name="title">
      <string>&amp;Help</string>
     </property>
-    <addaction name="action_menu_help_pamhyr"/>
-    <addaction name="action_menu_help_mage"/>
+    <widget class="QMenu" name="menuDoc">
+     <property name="title">
+      <string>Help</string>
+     </property>
+     <addaction name="action_menu_Pamhyr"/>
+     <addaction name="action_menu_Pamhyr_dev"/>
+     <addaction name="action_menu_Mage"/>
+    </widget>
+    <addaction name="menuDoc"/>
     <addaction name="action_menu_about"/>
    </widget>
    <widget class="QMenu" name="menuSediment">
@@ -895,6 +902,26 @@
     <string>Edit reach sediment layers</string>
    </property>
   </action>
+  <action name="actionDoc">
+   <property name="text">
+    <string>Doc</string>
+   </property>
+  </action>
+  <action name="action_menu_Pamhyr">
+   <property name="text">
+    <string>Pamhyr2 users</string>
+   </property>
+  </action>
+  <action name="action_menu_Pamhyr_dev">
+   <property name="text">
+    <string>Pamhyr2 developer</string>
+   </property>
+  </action>
+  <action name="action_menu_Mage">
+   <property name="text">
+    <string>Mage</string>
+   </property>
+  </action>
  </widget>
  <resources/>
  <connections>
diff --git a/src/View/ui/WebView.ui b/src/View/ui/WebView.ui
new file mode 100644
index 00000000..d29a0c89
--- /dev/null
+++ b/src/View/ui/WebView.ui
@@ -0,0 +1,50 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>MainWindow</class>
+ <widget class="QMainWindow" name="MainWindow">
+  <property name="geometry">
+   <rect>
+    <x>0</x>
+    <y>0</y>
+    <width>640</width>
+    <height>480</height>
+   </rect>
+  </property>
+  <property name="windowTitle">
+   <string>MainWindow</string>
+  </property>
+  <widget class="QWidget" name="centralwidget">
+   <layout class="QGridLayout" name="gridLayout">
+    <item row="0" column="0">
+     <widget class="QWebView" name="webView">
+      <property name="url">
+       <url>
+        <string>about:blank</string>
+       </url>
+      </property>
+     </widget>
+    </item>
+   </layout>
+  </widget>
+  <widget class="QMenuBar" name="menubar">
+   <property name="geometry">
+    <rect>
+     <x>0</x>
+     <y>0</y>
+     <width>640</width>
+     <height>22</height>
+    </rect>
+   </property>
+  </widget>
+  <widget class="QStatusBar" name="statusbar"/>
+ </widget>
+ <customwidgets>
+  <customwidget>
+   <class>QWebView</class>
+   <extends>QWidget</extends>
+   <header location="global">QtWebKitWidgets/QWebView</header>
+  </customwidget>
+ </customwidgets>
+ <resources/>
+ <connections/>
+</ui>
-- 
GitLab