Skip to content

Commit a137a7c

Browse files
committedJun 6, 2017
[processing] open help in the default webbrowser to be consistent with
the rest of QGIS dialogs
1 parent 77fa177 commit a137a7c

File tree

8 files changed

+42
-44
lines changed

8 files changed

+42
-44
lines changed
 

‎python/plugins/processing/ProcessingPlugin.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
from processing.gui.ResultsDock import ResultsDock
4545
from processing.gui.AlgorithmLocatorFilter import AlgorithmLocatorFilter
4646
from processing.modeler.ModelerDialog import ModelerDialog
47-
from processing.tools.system import tempFolder
47+
from processing.tools.system import tempFolder, tempHelpFolder
4848
from processing.gui.menus import removeMenus, initializeMenus, createMenus
4949
from processing.core.ProcessingResults import resultsList
5050

@@ -146,6 +146,11 @@ def unload(self):
146146
if QDir(folder).exists():
147147
shutil.rmtree(folder, True)
148148

149+
# also delete temporary help files
150+
folder = tempHelpFolder()
151+
if QDir(folder).exists():
152+
shutil.rmtree(folder, True)
153+
149154
self.iface.unregisterMainWindowAction(self.toolboxAction)
150155
self.iface.unregisterMainWindowAction(self.modelerAction)
151156
self.iface.unregisterMainWindowAction(self.historyAction)

‎python/plugins/processing/algs/gdal/GdalAlgorithm.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -80,19 +80,15 @@ def processAlgorithm(self, parameters, context, feedback):
8080
commands[i] = c
8181
GdalUtils.runGdal(commands, feedback)
8282

83-
def shortHelpString(self):
83+
def helpUrl(self):
8484
helpPath = GdalUtils.gdalHelpPath()
8585
if helpPath == '':
86-
return
86+
return None
8787

8888
if os.path.exists(helpPath):
89-
url = QUrl.fromLocalFile(os.path.join(helpPath, '{}.html'.format(self.commandName()))).toString()
89+
return QUrl.fromLocalFile(os.path.join(helpPath, '{}.html'.format(self.commandName()))).toString()
9090
else:
91-
url = helpPath + '{}.html'.format(self.commandName())
92-
93-
return '''This algorithm is based on the GDAL {} module.
94-
For more info, see the <a href={}> module help</a>
95-
'''.format(self.commandName(), url)
91+
return helpPath + '{}.html'.format(self.commandName())
9692

9793
def commandName(self):
9894
parameters = {}

‎python/plugins/processing/core/GeoAlgorithm.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,3 +390,6 @@ def executeAlgorithm(alg, parameters, context=None, feedback=None, model=None):
390390
# lines.append(traceback.format_exc())
391391
#QgsMessageLog.logMessage('\n'.join(lines), self.tr('Processing'), QgsMessageLog.CRITICAL)
392392
#raise GeoAlgorithmExecutionException(str(e) + self.tr('\nSee log for more details'), lines, e)
393+
394+
def helpUrl(self):
395+
return None

‎python/plugins/processing/gui/AlgorithmDialogBase.py

Lines changed: 7 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,9 @@
3232
from qgis.PyQt import uic
3333
from qgis.PyQt.QtCore import QCoreApplication, QByteArray, QUrl
3434
from qgis.PyQt.QtWidgets import QApplication, QDialogButtonBox
35-
from qgis.PyQt.QtNetwork import QNetworkRequest, QNetworkReply
3635

3736
from qgis.utils import iface
38-
from qgis.core import (QgsNetworkAccessManager,
39-
QgsProject,
37+
from qgis.core import (QgsProject,
4038
QgsProcessingFeedback,
4139
QgsSettings)
4240

@@ -103,6 +101,7 @@ def __init__(self, alg):
103101
self.buttonCancel.setEnabled(False)
104102

105103
self.btnClose = self.buttonBox.button(QDialogButtonBox.Close)
104+
self.buttonBox.helpRequested.connect(self.openHelp)
106105

107106
# don't collapse parameters panel
108107
self.splitter.setCollapsible(0, False)
@@ -128,23 +127,6 @@ def linkClicked(url):
128127

129128
self.textShortHelp.anchorClicked.connect(linkClicked)
130129

131-
if self.alg.helpString() is not None:
132-
try:
133-
self.txtHelp.setHtml(self.alg.helpString())
134-
except Exception:
135-
self.tabWidget.removeTab(2)
136-
elif self.alg.helpUrl() is not None:
137-
try:
138-
html = self.tr('<p>Downloading algorithm help... Please wait.</p>')
139-
self.txtHelp.setHtml(html)
140-
rq = QNetworkRequest(QUrl(self.alg.helpUrl()))
141-
self.reply = QgsNetworkAccessManager.instance().get(rq)
142-
self.reply.finished.connect(self.requestFinished)
143-
except Exception:
144-
self.tabWidget.removeTab(2)
145-
else:
146-
self.tabWidget.removeTab(2)
147-
148130
self.showDebug = ProcessingConfig.getSetting(
149131
ProcessingConfig.SHOW_DEBUG_IN_DIALOG)
150132

@@ -154,16 +136,6 @@ def formatHelp(self, alg):
154136
return None
155137
return "<h2>%s</h2>%s" % (alg.displayName(), "".join(["<p>%s</p>" % s for s in text.split("\n")]))
156138

157-
def requestFinished(self):
158-
"""Change the webview HTML content"""
159-
reply = self.sender()
160-
if reply.error() != QNetworkReply.NoError:
161-
html = self.tr('<h2>No help available for this algorithm</h2><p>{}</p>'.format(reply.errorString()))
162-
else:
163-
html = str(reply.readAll())
164-
reply.deleteLater()
165-
self.txtHelp.setHtml(html)
166-
167139
def closeEvent(self, event):
168140
self._saveGeometry()
169141
super(AlgorithmDialogBase, self).closeEvent(event)
@@ -237,6 +209,11 @@ def reject(self):
237209
def finish(self, context):
238210
pass
239211

212+
def openHelp(self):
213+
algHelp = self.alg.helpUrl()
214+
if algHelp is not None:
215+
webbrowser.open(algHelp)
216+
240217
def _saveGeometry(self):
241218
self.settings.setValue("/Processing/dialogBaseSplitter", self.splitter.saveState())
242219
self.settings.setValue("/Processing/dialogBase", self.saveGeometry())

‎python/plugins/processing/gui/Help2Html.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,14 @@
2727

2828
__revision__ = '$Format:%H$'
2929

30-
from qgis.PyQt.QtCore import QCoreApplication
3130
import os
3231
import re
3332
import json
3433

34+
from qgis.PyQt.QtCore import QCoreApplication, QUrl
35+
36+
from processing.tools import system
37+
3538
ALG_DESC = 'ALG_DESC'
3639
ALG_CREATOR = 'ALG_CREATOR'
3740
ALG_HELP_CREATOR = 'ALG_HELP_CREATOR'
@@ -63,7 +66,13 @@ def getHtmlFromHelpFile(alg, helpFile):
6366
try:
6467
with open(helpFile) as f:
6568
descriptions = json.load(f)
66-
return getHtmlFromDescriptionsDict(alg, descriptions)
69+
70+
content = getHtmlFromDescriptionsDict(alg, descriptions)
71+
algGroup, algName = alg.id().split(':')
72+
filePath = os.path.join(system.tempHelpFolder(), "{}_{}.html".format(algGroup, algName))
73+
with open(filePath, 'w', encoding='utf-8') as f:
74+
f.write(content)
75+
return QUrl.fromLocalFile(filePath).toString()
6776
except:
6877
return None
6978

‎python/plugins/processing/modeler/ModelerAlgorithm.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -539,7 +539,7 @@ def updateModelerView(self):
539539
if self.modelerdialog:
540540
self.modelerdialog.repaintModel()
541541

542-
def helpString(self):
542+
def helpUrl(self):
543543
try:
544544
return getHtmlFromDescriptionsDict(self, self.helpContent)
545545
except:

‎python/plugins/processing/script/ScriptAlgorithm.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,9 +198,9 @@ def processAlgorithm(self, parameters, context, feedback):
198198
for out in self.outputs:
199199
out.setValue(ns[out.name])
200200

201-
def helpString(self):
201+
def helpUrl(self):
202202
if self.descriptionFile is None:
203-
return False, None
203+
return None
204204
helpfile = self.descriptionFile + '.help'
205205
if os.path.exists(helpfile):
206206
return getHtmlFromHelpFile(self, helpfile)

‎python/plugins/processing/tools/system.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,14 @@ def mkdir(newdir):
142142
os.mkdir(newdir)
143143

144144

145+
def tempHelpFolder():
146+
tmp = os.path.join(str(QDir.tempPath()), 'processing_help')
147+
if not QDir(tmp).exists():
148+
QDir().mkpath(tmp)
149+
150+
return str(os.path.abspath(tmp))
151+
152+
145153
def escapeAndJoin(strList):
146154
joined = ''
147155
for s in strList:

0 commit comments

Comments
 (0)
Please sign in to comment.