Unverified Commit 03ab3498 authored by Peterson, Peter's avatar Peterson, Peter Committed by GitHub
Browse files

Merge pull request #30787 from mantidproject/help_url_error

Improved interface help interaction (ornlnext)
parents 7b6eb20e 149fb210
...@@ -512,22 +512,22 @@ class AlignComponents(PythonAlgorithm): ...@@ -512,22 +512,22 @@ class AlignComponents(PythonAlgorithm):
.. math:: .. math::
\sum_i^{N_d}\sum_j^{N_p} (1 - m_{i,j}) \frac{|d_{i,j} - d_j^*|}{d_j^*} \\sum_i^{N_d}\\sum_j^{N_p} (1 - m_{i,j}) \\frac{|d_{i,j} - d_j^*|}{d_j^*}
where :math:`N_d` is the number of detectors in the bank, :math:`N_p` is the number of reference peaks, and where :math:`N_d` is the number of detectors in the bank, :math:`N_p` is the number of reference peaks, and
:math:`m_{i,j}` is the mask for peak :math:`j` and detector :math:`i`. The mask evaluates to 1 if the :math:`m_{i,j}` is the mask for peak :math:`j` and detector :math:`i`. The mask evaluates to 1 if the
detector is defective or the peak is missing in the detector, otherwise the mask evaluates to zero. detector is defective or the peak is missing in the detector, otherwise the mask evaluates to zero.
There's an implicit one-to-correspondence between array index of `difc` and workspace index of `wks_name`, There's an implicit one-to-correspondence between array index of ``difc`` and workspace index of ``wks_name``,
that is, between row index of the input TOFS table and workspace index of `wks_name`. that is, between row index of the input TOFS table and workspace index of ``wks_name``.
@param x_0 :: list of length 3 (new XYZ coordinates of the component) or length 6 (XYZ and rotation coords) @param x_0 :: list of length 3 (new XYZ coordinates of the component) or length 6 (XYZ and rotation coords)
@param wks_name :: name of a workspace with an embedded instrument. The instrument will be adjusted according to @param wks_name :: name of a workspace with an embedded instrument. The instrument will be adjusted according to
the new coordinates `x_0` for instrument component `component`. It's pixel spectra will contain the new DIFC the new coordinates ``x_0`` for instrument component ``component``. It's pixel spectra will contain the new DIFC
@param component :: name of the instrument component to be optimized @param component :: name of the instrument component to be optimized
@param firstIndex :: workspace index of first index of `difc` array to be considered when comparing old @param firstIndex :: workspace index of first index of ``difc`` array to be considered when comparing old
and new DIFC values. When fitting the source or sample, this is the first spectrum index. and new DIFC values. When fitting the source or sample, this is the first spectrum index.
@param lastIndex :: workspace index of last index of `difc` array to be considered when comparing old @param lastIndex :: workspace index of last index of ``difc`` array to be considered when comparing old
and new DIFC values. When fitting the source or sample, this is the last row number of the input and new DIFC values. When fitting the source or sample, this is the last row number of the input
TOFS table. TOFS table.
...@@ -557,7 +557,7 @@ class AlignComponents(PythonAlgorithm): ...@@ -557,7 +557,7 @@ class AlignComponents(PythonAlgorithm):
@param component :: reference to a detector component object @param component :: reference to a detector component object
@returns detector ID (`int`) of the first detector in the component @returns detector ID (``int``) of the first detector in the component
""" """
if component.type() == 'DetectorComponent' or component.type() == 'GridDetectorPixel': if component.type() == 'DetectorComponent' or component.type() == 'GridDetectorPixel':
return component.getID() return component.getID()
......
...@@ -328,7 +328,7 @@ public: ...@@ -328,7 +328,7 @@ public:
void showAlgorithmHelp(const QString &name, const int version=-1); void showAlgorithmHelp(const QString &name, const int version=-1);
void showConceptHelp(const QString &name); void showConceptHelp(const QString &name);
void showFitFunctionHelp(const QString &name=QString()); void showFitFunctionHelp(const QString &name=QString());
void showCustomInterfaceHelp(const QString &name); void showCustomInterfaceHelp(const QString &name, const QString &area=QString(), const QString &section=QString());
void showWebPage(const QString &url); void showWebPage(const QString &url);
void closeHelpWindow(); void closeHelpWindow();
}; };
......
...@@ -9,6 +9,14 @@ from qtpy import QtCore, QtGui ...@@ -9,6 +9,14 @@ from qtpy import QtCore, QtGui
import matplotlib import matplotlib
import sys import sys
import os import os
try:
from mantid import __version__ as __mtd_version
from mantid import _bindir as __mtd_bin_dir
# convert to major.minor
__mtd_version = '.'.join(__mtd_version.split(".")[:2])
except ImportError: # mantid not found
__mtd_version = ''
__mtd_bin_dir=''
def set_matplotlib_backend(): def set_matplotlib_backend():
...@@ -25,10 +33,10 @@ def set_matplotlib_backend(): ...@@ -25,10 +33,10 @@ def set_matplotlib_backend():
backend = 'Qt5Agg' backend = 'Qt5Agg'
else: else:
from qtpy import PYQT4, PYQT5 # noqa from qtpy import PYQT4, PYQT5 # noqa
if PYQT4: if PYQT5:
backend = 'Qt4Agg'
elif PYQT5:
backend = 'Qt5Agg' backend = 'Qt5Agg'
elif PYQT4:
backend = 'Qt4Agg'
else: else:
raise RuntimeError('Do not know which matplotlib backend to set') raise RuntimeError('Do not know which matplotlib backend to set')
matplotlib.use(backend) matplotlib.use(backend)
...@@ -50,31 +58,55 @@ def get_qapplication(): ...@@ -50,31 +58,55 @@ def get_qapplication():
return QApplication(sys.argv), False return QApplication(sys.argv), False
def show_interface_help(mantidplot_name, assistant_process, collection_file, qt_url, external_url): def __to_external_url(interface_name: str, section: str, external_url: str) -> QtCore.QUrl:
if not external_url:
template = 'http://docs.mantidproject.org/nightly/interfaces/{}/{}.html'
external_url = template.format(section, interface_name)
return QtCore.QUrl(external_url)
def __to_qthelp_url(interface_name: str, section: str, qt_url: str) -> str:
if qt_url:
return qt_url
else:
template = 'qthelp://org.sphinx.mantidproject.{}/doc/interfaces/{}/{}.html'
return template.format(__mtd_version, section, interface_name)
def __get_collection_file(collection_file: str) -> str:
if not collection_file:
if not __mtd_bin_dir:
return 'HELP COLLECTION FILE NOT FOUND'
else:
collection_file = os.path.join(__mtd_bin_dir, '../docs/qthelp/MantidProject.qhc')
return os.path.abspath(collection_file)
def show_interface_help(mantidplot_name, assistant_process, area: str='',
collection_file: str='',
qt_url: str='', external_url: str=""):
''' Shows the help page for a custom interface ''' Shows the help page for a custom interface
@param mantidplot_name: used by showCustomInterfaceHelp @param mantidplot_name: used by showCustomInterfaceHelp
@param assistant_process: needs to be started/closed from outside (see example below) @param assistant_process: needs to be started/closed from outside (see example below)
@param collection_file: qth file containing the help in format used by qtassistant @param collection_file: qth file containing the help in format used by qtassistant. The default is
@param qt_url: location of the help in the qth file ``mantid._bindir + '../docs/qthelp/MantidProject.qhc'``
@param external_url: location of external page to be displayed in the default browser @param qt_url: location of the help in the qth file. The default value is
``qthelp://org.sphinx.mantidproject.{mtdversion}/doc/interfaces/{mantidplot_name}.html``.
@param external_url: location of external page to be displayed in the default browser. The default value is
``http://docs.mantidproject.org/nightly/interfaces/framework/{mantidplot_name}.html``
Example: Example using defaults:
#in the __init__ function of the GUI add: #in the __init__ function of the GUI add:
self.assistant_process = QtCore.QProcess(self) self.assistant_process = QtCore.QProcess(self)
self.mantidplot_name='DGS Planner' self.mantidplot_name='DGS Planner'
self.collection_file = os.path.join(mantid._bindir, '../docs/qthelp/MantidProject.qhc')
version = ".".join(mantid.__version__.split(".")[:2])
self.qt_url = 'qthelp://org.sphinx.mantidproject.' + version + '/doc/interfaces/DGS Planner.html'
self.external_url = 'http://docs.mantidproject.org/nightly/interfaces/DGS Planner.html'
#add a help function in the GUI #add a help function in the GUI
def help(self): def help(self):
show_interface_help(self.mantidplot_name, show_interface_help(self.mantidplot_name,
self.assistant_process, self.assistant_process)
self.collection_file,
self.qt_url,
self.external_url)
#make sure you close the qtassistant when the GUI is closed #make sure you close the qtassistant when the GUI is closed
def closeEvent(self, event): def closeEvent(self, event):
...@@ -83,24 +115,40 @@ def show_interface_help(mantidplot_name, assistant_process, collection_file, qt_ ...@@ -83,24 +115,40 @@ def show_interface_help(mantidplot_name, assistant_process, collection_file, qt_
event.accept() event.accept()
''' '''
try: try:
# try using built-in help in mantid
import mantidqt import mantidqt
mantidqt.interfacemanager.InterfaceManager().showCustomInterfaceHelp(mantidplot_name) mantidqt.interfacemanager.InterfaceManager().showCustomInterfaceHelp(mantidplot_name, area)
except: #(ImportError, ModuleNotFoundError) raises the wrong type of error except: #(ImportError, ModuleNotFoundError) raises the wrong type of error
# built-in help failed, try external qtassistant then give up and launch a browser
# cleanup previous version
assistant_process.close() assistant_process.close()
assistant_process.waitForFinished() assistant_process.waitForFinished()
# where to expect qtassistant
helpapp = QtCore.QLibraryInfo.location(QtCore.QLibraryInfo.BinariesPath) + QtCore.QDir.separator() helpapp = QtCore.QLibraryInfo.location(QtCore.QLibraryInfo.BinariesPath) + QtCore.QDir.separator()
helpapp += 'assistant' helpapp += 'assistant'
args = ['-enableRemoteControl', '-collectionFile', collection_file, '-showUrl', qt_url]
collection_file = __get_collection_file(collection_file)
if os.path.isfile(helpapp) and os.path.isfile(collection_file): if os.path.isfile(helpapp) and os.path.isfile(collection_file):
# try to find the collection file and launch qtassistant
args = ['-enableRemoteControl',
'-collectionFile', collection_file,
'-showUrl', __to_qthelp_url(mantidplot_name, area, qt_url)]
assistant_process.close() assistant_process.close()
assistant_process.waitForFinished() assistant_process.waitForFinished()
assistant_process.start(helpapp, args) assistant_process.start(helpapp, args)
else: else:
# give up and upen a URL in default browser
openUrl=QtGui.QDesktopServices.openUrl openUrl=QtGui.QDesktopServices.openUrl
sysenv=QtCore.QProcessEnvironment.systemEnvironment() sysenv=QtCore.QProcessEnvironment.systemEnvironment()
ldp=sysenv.value('LD_PRELOAD') ldp=sysenv.value('LD_PRELOAD')
if ldp: if ldp:
del os.environ['LD_PRELOAD'] del os.environ['LD_PRELOAD']
openUrl(QtCore.QUrl(external_url))
# create a url to the help in the default location
openUrl(__to_external_url(mantidplot_name, area, external_url))
if ldp: if ldp:
os.environ['LD_PRELOAD']=ldp os.environ['LD_PRELOAD']=ldp
...@@ -22,7 +22,7 @@ ALFCustomInstrumentView::ALFCustomInstrumentView(const std::string &instrument, ...@@ -22,7 +22,7 @@ ALFCustomInstrumentView::ALFCustomInstrumentView(const std::string &instrument,
m_extractSingleTubeObservable(nullptr), m_averageTubeObservable(nullptr), m_extractSingleTubeObservable(nullptr), m_averageTubeObservable(nullptr),
m_extractAction(nullptr), m_averageAction(nullptr), m_extractAction(nullptr), m_averageAction(nullptr),
m_analysisPane(nullptr) { m_analysisPane(nullptr) {
m_helpPage = "ALF View"; m_helpPage = "direct/ALF View";
} }
void ALFCustomInstrumentView::setUpInstrument( void ALFCustomInstrumentView::setUpInstrument(
...@@ -97,4 +97,4 @@ void ALFCustomInstrumentView::addSpectrum(const std::string &wsName) { ...@@ -97,4 +97,4 @@ void ALFCustomInstrumentView::addSpectrum(const std::string &wsName) {
} }
} // namespace CustomInterfaces } // namespace CustomInterfaces
} // namespace MantidQt } // namespace MantidQt
\ No newline at end of file
...@@ -1101,7 +1101,7 @@ void EnggDiffractionViewQtGUI::closeEvent(QCloseEvent *event) { ...@@ -1101,7 +1101,7 @@ void EnggDiffractionViewQtGUI::closeEvent(QCloseEvent *event) {
void EnggDiffractionViewQtGUI::openHelpWin() { void EnggDiffractionViewQtGUI::openHelpWin() {
MantidQt::API::HelpWindow::showCustomInterface( MantidQt::API::HelpWindow::showCustomInterface(
nullptr, QString("Engineering Diffraction")); nullptr, QString("Engineering Diffraction"), QString("diffraction"));
} }
void EnggDiffractionViewQtGUI::updateTabsInstrument( void EnggDiffractionViewQtGUI::updateTabsInstrument(
......
...@@ -507,7 +507,7 @@ void MantidEV::setDefaultState_slot() { ...@@ -507,7 +507,7 @@ void MantidEV::setDefaultState_slot() {
*/ */
void MantidEV::help_slot() { void MantidEV::help_slot() {
MantidQt::API::HelpWindow::showCustomInterface( MantidQt::API::HelpWindow::showCustomInterface(
nullptr, QString("SCD Event Data Reduction")); nullptr, QString("SCD Event Data Reduction"), QString("diffraction"));
} }
/** /**
......
...@@ -55,7 +55,7 @@ void SampleTransmission::initLayout() { ...@@ -55,7 +55,7 @@ void SampleTransmission::initLayout() {
*/ */
void SampleTransmission::showHelp() { void SampleTransmission::showHelp() {
MantidQt::API::HelpWindow::showCustomInterface( MantidQt::API::HelpWindow::showCustomInterface(
nullptr, QString("Sample Transmission Calculator")); nullptr, QString("Sample Transmission Calculator"), QString("general"));
} }
/** /**
......
...@@ -306,8 +306,8 @@ void MainWindowPresenter::initNewBatch(IBatchPresenter *batchPresenter, ...@@ -306,8 +306,8 @@ void MainWindowPresenter::initNewBatch(IBatchPresenter *batchPresenter,
} }
void MainWindowPresenter::showHelp() { void MainWindowPresenter::showHelp() {
MantidQt::API::HelpWindow::showCustomInterface(nullptr, MantidQt::API::HelpWindow::showCustomInterface(
QString("ISIS Reflectometry")); nullptr, std::string("ISIS Reflectometry"), std::string("reflectometry"));
} }
void MainWindowPresenter::notifySaveBatchRequested(int tabIndex) { void MainWindowPresenter::notifySaveBatchRequested(int tabIndex) {
......
...@@ -25,7 +25,8 @@ IndirectInterface::IndirectInterface(QWidget *parent) ...@@ -25,7 +25,8 @@ IndirectInterface::IndirectInterface(QWidget *parent)
void IndirectInterface::help() { void IndirectInterface::help() {
HelpWindow::showCustomInterface(nullptr, HelpWindow::showCustomInterface(nullptr,
QString::fromStdString(documentationPage())); QString::fromStdString(documentationPage()),
QString("indirect"));
} }
void IndirectInterface::settings() { void IndirectInterface::settings() {
......
...@@ -31,8 +31,8 @@ void IndirectSettingsView::emitApplyClicked() { emit applyClicked(); } ...@@ -31,8 +31,8 @@ void IndirectSettingsView::emitApplyClicked() { emit applyClicked(); }
void IndirectSettingsView::emitCancelClicked() { emit cancelClicked(); } void IndirectSettingsView::emitCancelClicked() { emit cancelClicked(); }
void IndirectSettingsView::openHelp() { void IndirectSettingsView::openHelp() {
MantidQt::API::HelpWindow::showCustomInterface(nullptr, MantidQt::API::HelpWindow::showCustomInterface(
QString("Indirect Settings")); nullptr, QString("Indirect Settings"), QString("indirect"));
} }
void IndirectSettingsView::setSelectedFacility(QString const &text) { void IndirectSettingsView::setSelectedFacility(QString const &text) {
......
...@@ -226,7 +226,8 @@ void ALCBaselineModellingView::setSelectorValues( ...@@ -226,7 +226,8 @@ void ALCBaselineModellingView::setSelectorValues(
} }
void ALCBaselineModellingView::help() { void ALCBaselineModellingView::help() {
MantidQt::API::HelpWindow::showCustomInterface(nullptr, QString("Muon ALC")); MantidQt::API::HelpWindow::showCustomInterface(nullptr, QString("Muon ALC"),
QString("muon"));
} }
void ALCBaselineModellingView::emitFitRequested() { emit fitRequested(); } void ALCBaselineModellingView::emitFitRequested() { emit fitRequested(); }
......
...@@ -316,7 +316,8 @@ void ALCDataLoadingView::setTimeRange(double tMin, double tMax) { ...@@ -316,7 +316,8 @@ void ALCDataLoadingView::setTimeRange(double tMin, double tMax) {
} }
void ALCDataLoadingView::help() { void ALCDataLoadingView::help() {
MantidQt::API::HelpWindow::showCustomInterface(nullptr, QString("Muon ALC")); MantidQt::API::HelpWindow::showCustomInterface(nullptr, QString("Muon ALC"),
QString("muon"));
} }
void ALCDataLoadingView::disableAll() { void ALCDataLoadingView::disableAll() {
......
...@@ -124,7 +124,8 @@ void ALCPeakFittingView::setPeakPicker(const IPeakFunction_const_sptr &peak) { ...@@ -124,7 +124,8 @@ void ALCPeakFittingView::setPeakPicker(const IPeakFunction_const_sptr &peak) {
} }
void ALCPeakFittingView::help() { void ALCPeakFittingView::help() {
MantidQt::API::HelpWindow::showCustomInterface(nullptr, QString("Muon ALC")); MantidQt::API::HelpWindow::showCustomInterface(nullptr, QString("Muon ALC"),
QString("muon"));
} }
void ALCPeakFittingView::displayError(const QString &message) { void ALCPeakFittingView::displayError(const QString &message) {
......
...@@ -385,8 +385,8 @@ void MuonAnalysis::setChosenGroupAndPeriods(const QString &wsName) { ...@@ -385,8 +385,8 @@ void MuonAnalysis::setChosenGroupAndPeriods(const QString &wsName) {
* Muon Analysis help (slot) * Muon Analysis help (slot)
*/ */
void MuonAnalysis::muonAnalysisHelpClicked() { void MuonAnalysis::muonAnalysisHelpClicked() {
MantidQt::API::HelpWindow::showCustomInterface(nullptr, MantidQt::API::HelpWindow::showCustomInterface(
QString("Muon Analysis")); nullptr, QString("Muon Analysis"), QString("muon"));
} }
/** /**
...@@ -394,7 +394,8 @@ void MuonAnalysis::muonAnalysisHelpClicked() { ...@@ -394,7 +394,8 @@ void MuonAnalysis::muonAnalysisHelpClicked() {
*/ */
void MuonAnalysis::muonAnalysisHelpGroupingClicked() { void MuonAnalysis::muonAnalysisHelpGroupingClicked() {
MantidQt::API::HelpWindow::showCustomInterface( MantidQt::API::HelpWindow::showCustomInterface(
nullptr, QString("Muon Analysis"), QString("grouping-options")); nullptr, QString("Muon Analysis"), QString("muon"),
QString("grouping-options"));
} }
/** /**
......
...@@ -37,7 +37,8 @@ void MuonAnalysisFitDataTab::init() { ...@@ -37,7 +37,8 @@ void MuonAnalysisFitDataTab::init() {
*/ */
void MuonAnalysisFitDataTab::muonAnalysisHelpDataAnalysisClicked() { void MuonAnalysisFitDataTab::muonAnalysisHelpDataAnalysisClicked() {
MantidQt::API::HelpWindow::showCustomInterface( MantidQt::API::HelpWindow::showCustomInterface(
nullptr, QString("Muon Analysis"), QString("data-analysis")); nullptr, QString("Muon Analysis"), QString("muon"),
QString("data-analysis"));
} }
/** /**
......
...@@ -151,7 +151,7 @@ void MuonAnalysisOptionTab::initLayout() { ...@@ -151,7 +151,7 @@ void MuonAnalysisOptionTab::initLayout() {
*/ */
void MuonAnalysisOptionTab::muonAnalysisHelpSettingsClicked() { void MuonAnalysisOptionTab::muonAnalysisHelpSettingsClicked() {
MantidQt::API::HelpWindow::showCustomInterface( MantidQt::API::HelpWindow::showCustomInterface(
nullptr, QString("Muon Analysis"), QString("settings")); nullptr, QString("Muon Analysis"), QString(""), QString("settings"));
} }
/* /*
...@@ -159,7 +159,7 @@ void MuonAnalysisOptionTab::muonAnalysisHelpSettingsClicked() { ...@@ -159,7 +159,7 @@ void MuonAnalysisOptionTab::muonAnalysisHelpSettingsClicked() {
*/ */
void MuonAnalysisOptionTab::rebinHelpClicked() { void MuonAnalysisOptionTab::rebinHelpClicked() {
MantidQt::API::HelpWindow::showCustomInterface( MantidQt::API::HelpWindow::showCustomInterface(
nullptr, QString("Muon Analysis"), QString("data-binning")); nullptr, QString("Muon Analysis"), QString(""), QString("data-binning"));
} }
/** /**
......
...@@ -102,7 +102,7 @@ MuonAnalysisResultTableTab::MuonAnalysisResultTableTab(Ui::MuonAnalysis &uiForm) ...@@ -102,7 +102,7 @@ MuonAnalysisResultTableTab::MuonAnalysisResultTableTab(Ui::MuonAnalysis &uiForm)
*/ */
void MuonAnalysisResultTableTab::helpResultsClicked() { void MuonAnalysisResultTableTab::helpResultsClicked() {
MantidQt::API::HelpWindow::showCustomInterface( MantidQt::API::HelpWindow::showCustomInterface(
nullptr, QString("Muon Analysis"), QString("results-table")); nullptr, QString("Muon Analysis"), QString(""), QString("results-table"));
} }
/** /**
......
...@@ -33,10 +33,12 @@ public: ...@@ -33,10 +33,12 @@ public:
static void showFitFunction(QWidget *parent, static void showFitFunction(QWidget *parent,
const std::string &name = std::string()); const std::string &name = std::string());
static void showCustomInterface(QWidget *parent, const QString &name, static void showCustomInterface(QWidget *parent, const QString &name,
const QString &area = QString(),
const QString &section = QString()); const QString &section = QString());
static void showCustomInterface(QWidget *parent, static void showCustomInterface(QWidget *parent,
const std::string &name = std::string(), const std::string &name = std::string(),
const std::string &area = std::string(),
const std::string &section = std::string()); const std::string &section = std::string());
}; };
} // namespace API } // namespace API
} // namespace MantidQt } // namespace MantidQt
\ No newline at end of file
...@@ -100,8 +100,14 @@ public: ...@@ -100,8 +100,14 @@ public:
/// @param name of fit function to show help for /// @param name of fit function to show help for
void showFitFunctionHelp(const QString &name = QString()); void showFitFunctionHelp(const QString &name = QString());
/// @param name of interface to show help for /**
void showCustomInterfaceHelp(const QString &name); * @param name of interface to show help for
* @param area - folder for documentation in the interfaces directory
* @param section - section in the html document
**/
void showCustomInterfaceHelp(const QString &name,
const QString &area = QString(),
const QString &section = QString());
/// @param url of web page to open in browser /// @param url of web page to open in browser
void showWebPage(const QString &url); void showWebPage(const QString &url);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment