mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-16 00:03:12 -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.ResultsDock import ResultsDock
|
||||||
from processing.gui.AlgorithmLocatorFilter import AlgorithmLocatorFilter
|
from processing.gui.AlgorithmLocatorFilter import AlgorithmLocatorFilter
|
||||||
from processing.modeler.ModelerDialog import ModelerDialog
|
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.gui.menus import removeMenus, initializeMenus, createMenus
|
||||||
from processing.core.ProcessingResults import resultsList
|
from processing.core.ProcessingResults import resultsList
|
||||||
|
|
||||||
@ -146,6 +146,11 @@ class ProcessingPlugin(object):
|
|||||||
if QDir(folder).exists():
|
if QDir(folder).exists():
|
||||||
shutil.rmtree(folder, True)
|
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.toolboxAction)
|
||||||
self.iface.unregisterMainWindowAction(self.modelerAction)
|
self.iface.unregisterMainWindowAction(self.modelerAction)
|
||||||
self.iface.unregisterMainWindowAction(self.historyAction)
|
self.iface.unregisterMainWindowAction(self.historyAction)
|
||||||
|
@ -80,19 +80,15 @@ class GdalAlgorithm(GeoAlgorithm):
|
|||||||
commands[i] = c
|
commands[i] = c
|
||||||
GdalUtils.runGdal(commands, feedback)
|
GdalUtils.runGdal(commands, feedback)
|
||||||
|
|
||||||
def shortHelpString(self):
|
def helpUrl(self):
|
||||||
helpPath = GdalUtils.gdalHelpPath()
|
helpPath = GdalUtils.gdalHelpPath()
|
||||||
if helpPath == '':
|
if helpPath == '':
|
||||||
return
|
return None
|
||||||
|
|
||||||
if os.path.exists(helpPath):
|
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:
|
else:
|
||||||
url = helpPath + '{}.html'.format(self.commandName())
|
return 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)
|
|
||||||
|
|
||||||
def commandName(self):
|
def commandName(self):
|
||||||
parameters = {}
|
parameters = {}
|
||||||
|
@ -390,3 +390,6 @@ def executeAlgorithm(alg, parameters, context=None, feedback=None, model=None):
|
|||||||
# lines.append(traceback.format_exc())
|
# lines.append(traceback.format_exc())
|
||||||
#QgsMessageLog.logMessage('\n'.join(lines), self.tr('Processing'), QgsMessageLog.CRITICAL)
|
#QgsMessageLog.logMessage('\n'.join(lines), self.tr('Processing'), QgsMessageLog.CRITICAL)
|
||||||
#raise GeoAlgorithmExecutionException(str(e) + self.tr('\nSee log for more details'), lines, e)
|
#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 import uic
|
||||||
from qgis.PyQt.QtCore import QCoreApplication, QByteArray, QUrl
|
from qgis.PyQt.QtCore import QCoreApplication, QByteArray, QUrl
|
||||||
from qgis.PyQt.QtWidgets import QApplication, QDialogButtonBox
|
from qgis.PyQt.QtWidgets import QApplication, QDialogButtonBox
|
||||||
from qgis.PyQt.QtNetwork import QNetworkRequest, QNetworkReply
|
|
||||||
|
|
||||||
from qgis.utils import iface
|
from qgis.utils import iface
|
||||||
from qgis.core import (QgsNetworkAccessManager,
|
from qgis.core import (QgsProject,
|
||||||
QgsProject,
|
|
||||||
QgsProcessingFeedback,
|
QgsProcessingFeedback,
|
||||||
QgsSettings)
|
QgsSettings)
|
||||||
|
|
||||||
@ -103,6 +101,7 @@ class AlgorithmDialogBase(BASE, WIDGET):
|
|||||||
self.buttonCancel.setEnabled(False)
|
self.buttonCancel.setEnabled(False)
|
||||||
|
|
||||||
self.btnClose = self.buttonBox.button(QDialogButtonBox.Close)
|
self.btnClose = self.buttonBox.button(QDialogButtonBox.Close)
|
||||||
|
self.buttonBox.helpRequested.connect(self.openHelp)
|
||||||
|
|
||||||
# don't collapse parameters panel
|
# don't collapse parameters panel
|
||||||
self.splitter.setCollapsible(0, False)
|
self.splitter.setCollapsible(0, False)
|
||||||
@ -128,23 +127,6 @@ class AlgorithmDialogBase(BASE, WIDGET):
|
|||||||
|
|
||||||
self.textShortHelp.anchorClicked.connect(linkClicked)
|
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(
|
self.showDebug = ProcessingConfig.getSetting(
|
||||||
ProcessingConfig.SHOW_DEBUG_IN_DIALOG)
|
ProcessingConfig.SHOW_DEBUG_IN_DIALOG)
|
||||||
|
|
||||||
@ -154,16 +136,6 @@ class AlgorithmDialogBase(BASE, WIDGET):
|
|||||||
return None
|
return None
|
||||||
return "<h2>%s</h2>%s" % (alg.displayName(), "".join(["<p>%s</p>" % s for s in text.split("\n")]))
|
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):
|
def closeEvent(self, event):
|
||||||
self._saveGeometry()
|
self._saveGeometry()
|
||||||
super(AlgorithmDialogBase, self).closeEvent(event)
|
super(AlgorithmDialogBase, self).closeEvent(event)
|
||||||
@ -237,6 +209,11 @@ class AlgorithmDialogBase(BASE, WIDGET):
|
|||||||
def finish(self, context):
|
def finish(self, context):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
def openHelp(self):
|
||||||
|
algHelp = self.alg.helpUrl()
|
||||||
|
if algHelp is not None:
|
||||||
|
webbrowser.open(algHelp)
|
||||||
|
|
||||||
def _saveGeometry(self):
|
def _saveGeometry(self):
|
||||||
self.settings.setValue("/Processing/dialogBaseSplitter", self.splitter.saveState())
|
self.settings.setValue("/Processing/dialogBaseSplitter", self.splitter.saveState())
|
||||||
self.settings.setValue("/Processing/dialogBase", self.saveGeometry())
|
self.settings.setValue("/Processing/dialogBase", self.saveGeometry())
|
||||||
|
@ -27,11 +27,14 @@ __copyright__ = '(C) 2012, Victor Olaya'
|
|||||||
|
|
||||||
__revision__ = '$Format:%H$'
|
__revision__ = '$Format:%H$'
|
||||||
|
|
||||||
from qgis.PyQt.QtCore import QCoreApplication
|
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
import json
|
import json
|
||||||
|
|
||||||
|
from qgis.PyQt.QtCore import QCoreApplication, QUrl
|
||||||
|
|
||||||
|
from processing.tools import system
|
||||||
|
|
||||||
ALG_DESC = 'ALG_DESC'
|
ALG_DESC = 'ALG_DESC'
|
||||||
ALG_CREATOR = 'ALG_CREATOR'
|
ALG_CREATOR = 'ALG_CREATOR'
|
||||||
ALG_HELP_CREATOR = 'ALG_HELP_CREATOR'
|
ALG_HELP_CREATOR = 'ALG_HELP_CREATOR'
|
||||||
@ -63,7 +66,13 @@ def getHtmlFromHelpFile(alg, helpFile):
|
|||||||
try:
|
try:
|
||||||
with open(helpFile) as f:
|
with open(helpFile) as f:
|
||||||
descriptions = json.load(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:
|
except:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
@ -539,7 +539,7 @@ class ModelerAlgorithm(GeoAlgorithm):
|
|||||||
if self.modelerdialog:
|
if self.modelerdialog:
|
||||||
self.modelerdialog.repaintModel()
|
self.modelerdialog.repaintModel()
|
||||||
|
|
||||||
def helpString(self):
|
def helpUrl(self):
|
||||||
try:
|
try:
|
||||||
return getHtmlFromDescriptionsDict(self, self.helpContent)
|
return getHtmlFromDescriptionsDict(self, self.helpContent)
|
||||||
except:
|
except:
|
||||||
|
@ -198,9 +198,9 @@ class ScriptAlgorithm(GeoAlgorithm):
|
|||||||
for out in self.outputs:
|
for out in self.outputs:
|
||||||
out.setValue(ns[out.name])
|
out.setValue(ns[out.name])
|
||||||
|
|
||||||
def helpString(self):
|
def helpUrl(self):
|
||||||
if self.descriptionFile is None:
|
if self.descriptionFile is None:
|
||||||
return False, None
|
return None
|
||||||
helpfile = self.descriptionFile + '.help'
|
helpfile = self.descriptionFile + '.help'
|
||||||
if os.path.exists(helpfile):
|
if os.path.exists(helpfile):
|
||||||
return getHtmlFromHelpFile(self, helpfile)
|
return getHtmlFromHelpFile(self, helpfile)
|
||||||
|
@ -142,6 +142,14 @@ def mkdir(newdir):
|
|||||||
os.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):
|
def escapeAndJoin(strList):
|
||||||
joined = ''
|
joined = ''
|
||||||
for s in strList:
|
for s in strList:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user