mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-14 00:07:35 -04:00
[processing] open help in the default webbrowser to be consistent with
the rest of QGIS dialogs
This commit is contained in:
parent
77fa17781e
commit
a137a7c0f3
@ -44,7 +44,7 @@ from processing.gui.ConfigDialog import ConfigOptionsPage
|
||||
from processing.gui.ResultsDock import ResultsDock
|
||||
from processing.gui.AlgorithmLocatorFilter import AlgorithmLocatorFilter
|
||||
from processing.modeler.ModelerDialog import ModelerDialog
|
||||
from processing.tools.system import tempFolder
|
||||
from processing.tools.system import tempFolder, tempHelpFolder
|
||||
from processing.gui.menus import removeMenus, initializeMenus, createMenus
|
||||
from processing.core.ProcessingResults import resultsList
|
||||
|
||||
@ -146,6 +146,11 @@ class ProcessingPlugin(object):
|
||||
if QDir(folder).exists():
|
||||
shutil.rmtree(folder, True)
|
||||
|
||||
# also delete temporary help files
|
||||
folder = tempHelpFolder()
|
||||
if QDir(folder).exists():
|
||||
shutil.rmtree(folder, True)
|
||||
|
||||
self.iface.unregisterMainWindowAction(self.toolboxAction)
|
||||
self.iface.unregisterMainWindowAction(self.modelerAction)
|
||||
self.iface.unregisterMainWindowAction(self.historyAction)
|
||||
|
@ -80,19 +80,15 @@ class GdalAlgorithm(GeoAlgorithm):
|
||||
commands[i] = c
|
||||
GdalUtils.runGdal(commands, feedback)
|
||||
|
||||
def shortHelpString(self):
|
||||
def helpUrl(self):
|
||||
helpPath = GdalUtils.gdalHelpPath()
|
||||
if helpPath == '':
|
||||
return
|
||||
return None
|
||||
|
||||
if os.path.exists(helpPath):
|
||||
url = QUrl.fromLocalFile(os.path.join(helpPath, '{}.html'.format(self.commandName()))).toString()
|
||||
return QUrl.fromLocalFile(os.path.join(helpPath, '{}.html'.format(self.commandName()))).toString()
|
||||
else:
|
||||
url = helpPath + '{}.html'.format(self.commandName())
|
||||
|
||||
return '''This algorithm is based on the GDAL {} module.
|
||||
For more info, see the <a href={}> module help</a>
|
||||
'''.format(self.commandName(), url)
|
||||
return helpPath + '{}.html'.format(self.commandName())
|
||||
|
||||
def commandName(self):
|
||||
parameters = {}
|
||||
|
@ -390,3 +390,6 @@ def executeAlgorithm(alg, parameters, context=None, feedback=None, model=None):
|
||||
# lines.append(traceback.format_exc())
|
||||
#QgsMessageLog.logMessage('\n'.join(lines), self.tr('Processing'), QgsMessageLog.CRITICAL)
|
||||
#raise GeoAlgorithmExecutionException(str(e) + self.tr('\nSee log for more details'), lines, e)
|
||||
|
||||
def helpUrl(self):
|
||||
return None
|
||||
|
@ -32,11 +32,9 @@ import webbrowser
|
||||
from qgis.PyQt import uic
|
||||
from qgis.PyQt.QtCore import QCoreApplication, QByteArray, QUrl
|
||||
from qgis.PyQt.QtWidgets import QApplication, QDialogButtonBox
|
||||
from qgis.PyQt.QtNetwork import QNetworkRequest, QNetworkReply
|
||||
|
||||
from qgis.utils import iface
|
||||
from qgis.core import (QgsNetworkAccessManager,
|
||||
QgsProject,
|
||||
from qgis.core import (QgsProject,
|
||||
QgsProcessingFeedback,
|
||||
QgsSettings)
|
||||
|
||||
@ -103,6 +101,7 @@ class AlgorithmDialogBase(BASE, WIDGET):
|
||||
self.buttonCancel.setEnabled(False)
|
||||
|
||||
self.btnClose = self.buttonBox.button(QDialogButtonBox.Close)
|
||||
self.buttonBox.helpRequested.connect(self.openHelp)
|
||||
|
||||
# don't collapse parameters panel
|
||||
self.splitter.setCollapsible(0, False)
|
||||
@ -128,23 +127,6 @@ class AlgorithmDialogBase(BASE, WIDGET):
|
||||
|
||||
self.textShortHelp.anchorClicked.connect(linkClicked)
|
||||
|
||||
if self.alg.helpString() is not None:
|
||||
try:
|
||||
self.txtHelp.setHtml(self.alg.helpString())
|
||||
except Exception:
|
||||
self.tabWidget.removeTab(2)
|
||||
elif self.alg.helpUrl() is not None:
|
||||
try:
|
||||
html = self.tr('<p>Downloading algorithm help... Please wait.</p>')
|
||||
self.txtHelp.setHtml(html)
|
||||
rq = QNetworkRequest(QUrl(self.alg.helpUrl()))
|
||||
self.reply = QgsNetworkAccessManager.instance().get(rq)
|
||||
self.reply.finished.connect(self.requestFinished)
|
||||
except Exception:
|
||||
self.tabWidget.removeTab(2)
|
||||
else:
|
||||
self.tabWidget.removeTab(2)
|
||||
|
||||
self.showDebug = ProcessingConfig.getSetting(
|
||||
ProcessingConfig.SHOW_DEBUG_IN_DIALOG)
|
||||
|
||||
@ -154,16 +136,6 @@ class AlgorithmDialogBase(BASE, WIDGET):
|
||||
return None
|
||||
return "<h2>%s</h2>%s" % (alg.displayName(), "".join(["<p>%s</p>" % s for s in text.split("\n")]))
|
||||
|
||||
def requestFinished(self):
|
||||
"""Change the webview HTML content"""
|
||||
reply = self.sender()
|
||||
if reply.error() != QNetworkReply.NoError:
|
||||
html = self.tr('<h2>No help available for this algorithm</h2><p>{}</p>'.format(reply.errorString()))
|
||||
else:
|
||||
html = str(reply.readAll())
|
||||
reply.deleteLater()
|
||||
self.txtHelp.setHtml(html)
|
||||
|
||||
def closeEvent(self, event):
|
||||
self._saveGeometry()
|
||||
super(AlgorithmDialogBase, self).closeEvent(event)
|
||||
@ -237,6 +209,11 @@ class AlgorithmDialogBase(BASE, WIDGET):
|
||||
def finish(self, context):
|
||||
pass
|
||||
|
||||
def openHelp(self):
|
||||
algHelp = self.alg.helpUrl()
|
||||
if algHelp is not None:
|
||||
webbrowser.open(algHelp)
|
||||
|
||||
def _saveGeometry(self):
|
||||
self.settings.setValue("/Processing/dialogBaseSplitter", self.splitter.saveState())
|
||||
self.settings.setValue("/Processing/dialogBase", self.saveGeometry())
|
||||
|
@ -27,11 +27,14 @@ __copyright__ = '(C) 2012, Victor Olaya'
|
||||
|
||||
__revision__ = '$Format:%H$'
|
||||
|
||||
from qgis.PyQt.QtCore import QCoreApplication
|
||||
import os
|
||||
import re
|
||||
import json
|
||||
|
||||
from qgis.PyQt.QtCore import QCoreApplication, QUrl
|
||||
|
||||
from processing.tools import system
|
||||
|
||||
ALG_DESC = 'ALG_DESC'
|
||||
ALG_CREATOR = 'ALG_CREATOR'
|
||||
ALG_HELP_CREATOR = 'ALG_HELP_CREATOR'
|
||||
@ -63,7 +66,13 @@ def getHtmlFromHelpFile(alg, helpFile):
|
||||
try:
|
||||
with open(helpFile) as f:
|
||||
descriptions = json.load(f)
|
||||
return getHtmlFromDescriptionsDict(alg, descriptions)
|
||||
|
||||
content = getHtmlFromDescriptionsDict(alg, descriptions)
|
||||
algGroup, algName = alg.id().split(':')
|
||||
filePath = os.path.join(system.tempHelpFolder(), "{}_{}.html".format(algGroup, algName))
|
||||
with open(filePath, 'w', encoding='utf-8') as f:
|
||||
f.write(content)
|
||||
return QUrl.fromLocalFile(filePath).toString()
|
||||
except:
|
||||
return None
|
||||
|
||||
|
@ -539,7 +539,7 @@ class ModelerAlgorithm(GeoAlgorithm):
|
||||
if self.modelerdialog:
|
||||
self.modelerdialog.repaintModel()
|
||||
|
||||
def helpString(self):
|
||||
def helpUrl(self):
|
||||
try:
|
||||
return getHtmlFromDescriptionsDict(self, self.helpContent)
|
||||
except:
|
||||
|
@ -198,9 +198,9 @@ class ScriptAlgorithm(GeoAlgorithm):
|
||||
for out in self.outputs:
|
||||
out.setValue(ns[out.name])
|
||||
|
||||
def helpString(self):
|
||||
def helpUrl(self):
|
||||
if self.descriptionFile is None:
|
||||
return False, None
|
||||
return None
|
||||
helpfile = self.descriptionFile + '.help'
|
||||
if os.path.exists(helpfile):
|
||||
return getHtmlFromHelpFile(self, helpfile)
|
||||
|
@ -142,6 +142,14 @@ def mkdir(newdir):
|
||||
os.mkdir(newdir)
|
||||
|
||||
|
||||
def tempHelpFolder():
|
||||
tmp = os.path.join(str(QDir.tempPath()), 'processing_help')
|
||||
if not QDir(tmp).exists():
|
||||
QDir().mkpath(tmp)
|
||||
|
||||
return str(os.path.abspath(tmp))
|
||||
|
||||
|
||||
def escapeAndJoin(strList):
|
||||
joined = ''
|
||||
for s in strList:
|
||||
|
Loading…
x
Reference in New Issue
Block a user