Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 21 additions & 15 deletions qt/python/mantidqt/mantidqt/widgets/helpwindow/helpwindowbridge.py
Original file line number Diff line number Diff line change
@@ -1,56 +1,62 @@
# Mantid Repository : https://github.com/mantidproject/mantid
#
# Copyright © 2017 ISIS Rutherford Appleton Laboratory UKRI,
# NScD Oak Ridge National Laboratory, European Spallation Source,
# Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
# SPDX - License - Identifier: GPL - 3.0 +
import os
import sys
import argparse

from qtpy.QtWidgets import QApplication
from mantidqt.widgets.helpwindow.helpwindowpresenter import HelpWindowPresenter

_presenter = None


def show_help_page(relativeUrl, localDocs=None, onlineBaseUrl="https://docs.mantidproject.org/"):
def show_help_page(relativeUrl, onlineBaseUrl="https://docs.mantidproject.org/"):
"""
Show the help window at the given relative URL path.
Local docs path is now determined internally via ConfigService.
"""
global _presenter
if _presenter is None:
# Create a Presenter once. Re-use it on subsequent calls.
_presenter = HelpWindowPresenter(localDocs=localDocs, onlineBaseUrl=onlineBaseUrl)
_presenter = HelpWindowPresenter(onlineBaseUrl=onlineBaseUrl)

# Ask the Presenter to load the requested page
_presenter.show_help_page(relativeUrl)


def main(cmdargs=sys.argv):
"""
Run this script standalone to test the Python-based Help Window.
Local docs path is determined from Mantid's ConfigService.
"""
import argparse

parser = argparse.ArgumentParser(description="Standalone test of the Python-based Mantid Help Window.")
parser.add_argument(
"relativeUrl", nargs="?", default="", help="Relative doc path (e.g. 'algorithms/Load-v1.html'), defaults to 'index.html' if empty."
)
parser.add_argument("--local-docs", default=None, help="Path to local Mantid HTML docs. Overrides environment if set.")

parser.add_argument(
"--online-base-url",
default="https://docs.mantidproject.org/",
help="Base URL for online docs if local docs are not set or invalid.",
help="Base URL for online docs if local docs path from config is invalid or not found.",
)
args = parser.parse_args(cmdargs or sys.argv[1:])

# If user gave no --local-docs, fall back to environment
if args.local_docs is None:
args.local_docs = os.environ.get("MANTID_LOCAL_DOCS_BASE", None)
try:
import mantid.kernel

log = mantid.kernel.Logger("HelpWindowBridge")
log.information("Mantid kernel imported successfully.")
except ImportError as e:
print(f"ERROR: Failed to import Mantid Kernel: {e}", file=sys.stderr)
print(
"Ensure Mantid is built and PYTHONPATH is set correctly (e.g., export PYTHONPATH=/path/to/mantid/build/bin:$PYTHONPATH)",
file=sys.stderr,
)
sys.exit(1)

app = QApplication(sys.argv)

# Show the requested help page
show_help_page(relativeUrl=args.relativeUrl, localDocs=args.local_docs, onlineBaseUrl=args.online_base_url)
show_help_page(relativeUrl=args.relativeUrl, onlineBaseUrl=args.online_base_url)

sys.exit(app.exec_())

Expand Down
Loading