From 7365bf70b61ac3671f58379b24b0e53131448809 Mon Sep 17 00:00:00 2001 From: Pierre-Antoine Rouby Date: Mon, 9 Oct 2023 14:51:19 +0200 Subject: [PATCH] doc: Add mage documentation open action. --- src/View/Doc/Window.py | 3 ++- src/View/MainWindow.py | 27 +++++++++++++++++++-------- src/View/ui/MainWindow.ui | 4 ++-- 3 files changed, 23 insertions(+), 11 deletions(-) diff --git a/src/View/Doc/Window.py b/src/View/Doc/Window.py index ce6077ea..4be981b8 100644 --- a/src/View/Doc/Window.py +++ b/src/View/Doc/Window.py @@ -36,7 +36,8 @@ class DocWindow(PamhyrWindow): _pamhyr_ui = "WebView" _pamhyr_name = "Doc" - def _path_file(self, filename): + @classmethod + def _path_file(cls, filename): if ".py" in sys.argv[0]: return os.path.abspath( os.path.join( diff --git a/src/View/MainWindow.py b/src/View/MainWindow.py index 3c74158d..8539af1d 100644 --- a/src/View/MainWindow.py +++ b/src/View/MainWindow.py @@ -23,11 +23,11 @@ from queue import Queue from PyQt5 import QtGui from PyQt5.QtGui import ( - QKeySequence, + QKeySequence, QDesktopServices, ) from PyQt5.QtCore import ( - QTranslator, QEvent + QTranslator, QEvent, QUrl, ) from PyQt5.QtWidgets import ( QMainWindow, QApplication, QAction, @@ -190,6 +190,7 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit): "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_mage": self.open_doc_mage, "action_menu_about": self.open_about, # ToolBar action "action_toolBar_quit": self.close, @@ -721,13 +722,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() + ################# + # DOCUMENTATION # + ################# + def open_doc(self, filename): + if ".odt" in filename: + url = QUrl(f"file://{DocWindow._path_file(filename)}") + QDesktopServices.openUrl(url) + else: + doc = DocWindow( + filename = filename, + parent = self + ) + doc.show() def open_doc_user(self, ext="pdf"): self.open_doc(f"Pamhyr2-users.{ext}") @@ -735,6 +743,9 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit): def open_doc_dev(self, ext="pdf"): self.open_doc(f"Pamhyr2-dev.{ext}") + def open_doc_mage(self): + self.open_doc("Mage-8.odt") + ######### # DEBUG # ######### diff --git a/src/View/ui/MainWindow.ui b/src/View/ui/MainWindow.ui index 951dadc9..9cd766c4 100644 --- a/src/View/ui/MainWindow.ui +++ b/src/View/ui/MainWindow.ui @@ -174,7 +174,7 @@ - + @@ -920,7 +920,7 @@ Pamhyr2 developer - + Mage