From effe368b3fdfb11156a036c2ee7dc8c020c56d23 Mon Sep 17 00:00:00 2001 From: Sam Tygier Date: Tue, 20 Jul 2021 15:12:37 +0100 Subject: [PATCH] Link to new operation user docs The help button in the operations window now links to the new user docs. THe new docs have a link to the API docs if needed. --- docs/ext/operations_user_doc.py | 3 +++ mantidimaging/core/net/help_pages.py | 21 +++++++++++++------- mantidimaging/gui/windows/operations/view.py | 7 +++---- 3 files changed, 20 insertions(+), 11 deletions(-) diff --git a/docs/ext/operations_user_doc.py b/docs/ext/operations_user_doc.py index 4f20e4afe52..c38eb8cb23a 100644 --- a/docs/ext/operations_user_doc.py +++ b/docs/ext/operations_user_doc.py @@ -72,6 +72,9 @@ def run(self) -> List[Node]: rst_lines += get_params(op.filter_func.__doc__) rst_lines.append("") + rst_lines.append(f":class:`{op.filter_name} API docs<{op.__module__}>`") + rst_lines.append("") + rst = ViewList() for n, rst_line in enumerate(rst_lines): rst.append(rst_line, "generated.rst", n) diff --git a/mantidimaging/core/net/help_pages.py b/mantidimaging/core/net/help_pages.py index 49a3f7e6a7a..54d2e70add5 100644 --- a/mantidimaging/core/net/help_pages.py +++ b/mantidimaging/core/net/help_pages.py @@ -1,19 +1,26 @@ # Copyright (C) 2021 ISIS Rutherford Appleton Laboratory UKRI # SPDX - License - Identifier: GPL-3.0-or-later +from typing import Optional + from PyQt5.QtCore import QUrl from PyQt5.QtGui import QDesktopServices DOCS_BASE = "https://mantidproject.github.io/mantidimaging" -SECTION_API = f"{DOCS_BASE}/api/" SECTION_USER_GUIDE = f"{DOCS_BASE}/user_guide/" -def open_api_webpage(page_url: str): - open_help_webpage(SECTION_API, page_url) +def open_user_operation_docs(operation_name: str): + page_url = "operations/index" + section = operation_name.lower().replace(" ", "-") + open_help_webpage(SECTION_USER_GUIDE, page_url, section) + +def open_help_webpage(section_url: str, page_url: str, section: Optional[str] = None): + if section is not None: + url = f"{section_url}{page_url}.html#{section}" + else: + url = f"{section_url}{page_url}.html" -def open_help_webpage(section_url: str, page_url: str): - url = QUrl(f"{section_url}{page_url}.html") - if not QDesktopServices.openUrl(url): - raise RuntimeError(f"Url could not be opened: {url.toString()}") + if not QDesktopServices.openUrl(QUrl(url)): + raise RuntimeError(f"Url could not be opened: {url}") diff --git a/mantidimaging/gui/windows/operations/view.py b/mantidimaging/gui/windows/operations/view.py index 40537357e80..e60aaef85b0 100644 --- a/mantidimaging/gui/windows/operations/view.py +++ b/mantidimaging/gui/windows/operations/view.py @@ -9,7 +9,7 @@ QPushButton, QSizePolicy, QSplitter, QStyle, QVBoxLayout) from pyqtgraph import ImageItem -from mantidimaging.core.net.help_pages import open_api_webpage +from mantidimaging.core.net.help_pages import open_user_operation_docs from mantidimaging.gui.mvp_base import BaseMainWindowView from mantidimaging.gui.utility import delete_all_widgets_from_layout from mantidimaging.gui.widgets.mi_image_view.view import MIImageView @@ -188,11 +188,10 @@ def show_operation_completed(self, operation_name): self.notification_text.setText(f"{operation_name} completed successfully!") def open_help_webpage(self): - filter_id = self.presenter.model._find_filter_index_from_filter_name(self.filterSelector.currentText()) - filter_module_path = self.presenter.get_filter_module_name(filter_id) + filter_name = self.filterSelector.currentText() try: - open_api_webpage(filter_module_path) + open_user_operation_docs(filter_name) except RuntimeError as err: self.show_error_dialog(str(err))