Skip to content

Commit

Permalink
Link to new operation user docs
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
samtygier-stfc committed Jul 20, 2021
1 parent a50e52e commit effe368
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 11 deletions.
3 changes: 3 additions & 0 deletions docs/ext/operations_user_doc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
21 changes: 14 additions & 7 deletions mantidimaging/core/net/help_pages.py
Original file line number Diff line number Diff line change
@@ -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}")
7 changes: 3 additions & 4 deletions mantidimaging/gui/windows/operations/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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))

Expand Down

0 comments on commit effe368

Please sign in to comment.