Skip to content

Commit cc7eb27

Browse files
committed
[processing] drop WebView dependency (follow up 38f6ace)
1 parent dd69a59 commit cc7eb27

23 files changed

+147
-222
lines changed

python/plugins/processing/algs/examplescripts/ProcessingExampleScriptsPlugin.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,11 @@
2929

3030
from processing.core.Processing import Processing
3131

32+
3233
class ProcessingExampleScriptsPlugin:
3334

3435
def initGui(self):
3536
Processing.addScripts(os.path.join(os.path.dirname(__file__), "scripts"))
36-
37+
3738
def unload(self):
3839
Processing.removeScripts(os.path.join(os.path.dirname(__file__), "scripts"))
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
##text=string
22

3-
print text
3+
print text

python/plugins/processing/algs/grass/GrassAlgorithmProvider.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ def initializeSettings(self):
5555
GrassUtils.grassPath(), valuetype=Setting.FOLDER))
5656
if isWindows():
5757
ProcessingConfig.addSetting(Setting(self.getDescription(),
58-
GrassUtils.GRASS_WIN_SHELL, self.tr('Msys folder'),
59-
GrassUtils.grassWinShell(), valuetype=Setting.FOLDER))
58+
GrassUtils.GRASS_WIN_SHELL, self.tr('Msys folder'),
59+
GrassUtils.grassWinShell(), valuetype=Setting.FOLDER))
6060
ProcessingConfig.addSetting(Setting(self.getDescription(),
6161
GrassUtils.GRASS_LOG_COMMANDS,
6262
self.tr('Log execution commands'), False))

python/plugins/processing/algs/otb/OTBUtils.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ def executeOtb(commands, progress, addToLog=True):
161161
os.putenv('ITK_AUTOLOAD_PATH', otbLibPath())
162162
fused_command = ''.join(['"%s" ' % re.sub(r'^"|"$', '', c) for c in commands])
163163
proc = subprocess.Popen(fused_command, shell=True, stdout=subprocess.PIPE, stdin=open(os.devnull), stderr=subprocess.STDOUT, universal_newlines=True).stdout
164-
if isMac(): #This trick avoids having an uninterrupted system call exception if OTB is not installed
164+
if isMac(): # This trick avoids having an uninterrupted system call exception if OTB is not installed
165165
time.sleep(1)
166166
for line in iter(proc.readline, ""):
167167
if "[*" in line:

python/plugins/processing/algs/qgis/QGISAlgorithmProvider.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -222,8 +222,8 @@ def __init__(self):
222222
from .ExecuteSQL import ExecuteSQL
223223
self.alglist.extend([ExecuteSQL()])
224224

225-
self.externalAlgs = [] #to store algs added by 3rd party plugins as scripts
226-
225+
self.externalAlgs = [] # to store algs added by 3rd party plugins as scripts
226+
227227
folder = os.path.join(os.path.dirname(__file__), 'scripts')
228228
scripts = ScriptUtils.loadFromFolder(folder)
229229
for script in scripts:

python/plugins/processing/algs/saga/SagaUtils.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ def getSagaInstalledVersion(runSaga=False):
134134
stderr=subprocess.STDOUT,
135135
universal_newlines=True,
136136
).stdout
137-
if isMac(): #This trick avoids having an uninterrupted system call exception if SAGA is not installed
137+
if isMac(): # This trick avoids having an uninterrupted system call exception if SAGA is not installed
138138
time.sleep(1)
139139
try:
140140
lines = proc.readlines()

python/plugins/processing/core/Processing.py

+6-8
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,11 @@
6464
from processing.algs.taudem.TauDEMAlgorithmProvider import TauDEMAlgorithmProvider
6565
from processing.preconfigured.PreconfiguredAlgorithmProvider import PreconfiguredAlgorithmProvider
6666

67+
6768
class Processing:
6869

6970
providers = []
7071

71-
7272
# Same structure as algs in algList
7373
actions = {}
7474

@@ -134,8 +134,8 @@ def initialize():
134134
ProcessingConfig.initialize()
135135
ProcessingConfig.readSettings()
136136
RenderingStyles.loadStyles()
137-
138-
@staticmethod
137+
138+
@staticmethod
139139
def addScripts(folder):
140140
Processing.initialize()
141141
provider = Processing.getProviderFromName("qgis")
@@ -145,19 +145,17 @@ def addScripts(folder):
145145
script.allowEdit = False
146146
script._icon = provider._icon
147147
script.provider = provider
148-
provider.externalAlgs.extend(scripts)
148+
provider.externalAlgs.extend(scripts)
149149
Processing.reloadProvider("qgis")
150-
151-
150+
152151
@staticmethod
153152
def removeScripts(folder):
154153
provider = Processing.getProviderFromName("qgis")
155154
for alg in provider.externalAlgs[::-1]:
156155
path = os.path.dirname(alg.descriptionFile)
157156
if path == folder:
158-
provider.externalAlgs.remove(alg)
157+
provider.externalAlgs.remove(alg)
159158
Processing.reloadProvider("qgis")
160-
161159

162160
@staticmethod
163161
def updateAlgsList():

python/plugins/processing/core/alglist.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
from qgis.PyQt.QtCore import QObject, pyqtSignal
2929

30+
3031
class AlgorithmList(QObject):
3132

3233
providerAdded = pyqtSignal(str)
@@ -76,4 +77,4 @@ def getAlgorithmFromFullName(self, name):
7677
if alg.name == name:
7778
return alg
7879

79-
algList = AlgorithmList()
80+
algList = AlgorithmList()

python/plugins/processing/core/defaultproviders.py

-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
__revision__ = '$Format:%H$'
2727

2828

29-
3029
def loadDefaultProviders():
3130
# this is here just to "trigger" the above imports so providers are loaded
3231
# and can be found by the Processing.initialize() method

python/plugins/processing/gui/AlgorithmDialogBase.py

+22-9
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
from qgis.PyQt import uic
3232
from qgis.PyQt.QtCore import QCoreApplication, QSettings, QByteArray, QUrl
3333
from qgis.PyQt.QtWidgets import QApplication, QDialogButtonBox, QDesktopWidget
34+
from qgis.PyQt.QtNetwork import QNetworkRequest, QNetworkReply
3435

3536
from qgis.utils import iface
3637
from qgis.core import QgsNetworkAccessManager
@@ -63,9 +64,9 @@ def __init__(self, alg):
6364

6465
self.setWindowTitle(self.alg.displayName())
6566

66-
desktop = QDesktopWidget()
67-
if desktop.physicalDpiX() > 96:
68-
self.textHelp.setZoomFactor(desktop.physicalDpiX() / 96)
67+
#~ desktop = QDesktopWidget()
68+
#~ if desktop.physicalDpiX() > 96:
69+
#~ self.txtHelp.setZoomFactor(desktop.physicalDpiX() / 96)
6970

7071
algHelp = self.alg.shortHelp()
7172
if algHelp is None:
@@ -83,27 +84,39 @@ def __init__(self, alg):
8384

8485
def linkClicked(url):
8586
webbrowser.open(url.toString())
86-
self.textShortHelp.anchorClicked.connect(linkClicked)
8787

88-
self.textHelp.page().setNetworkAccessManager(QgsNetworkAccessManager.instance())
88+
self.textShortHelp.anchorClicked.connect(linkClicked)
8989

9090
isText, algHelp = self.alg.help()
9191
if algHelp is not None:
9292
algHelp = algHelp if isText else QUrl(algHelp)
9393
try:
9494
if isText:
95-
self.textHelp.setHtml(algHelp)
95+
self.txtHelp.setHtml(algHelp)
9696
else:
97-
self.textHelp.settings().clearMemoryCaches()
98-
self.textHelp.load(algHelp)
99-
except:
97+
html = self.tr('<p>Downloading algorithm help... Please wait.</p>')
98+
self.txtHelp.setHtml(html)
99+
rq = QNetworkRequest(algHelp)
100+
self.reply = QgsNetworkAccessManager.instance().get(rq)
101+
self.reply.finished.connect(self.requestFinished)
102+
except Exception, e:
100103
self.tabWidget.removeTab(2)
101104
else:
102105
self.tabWidget.removeTab(2)
103106

104107
self.showDebug = ProcessingConfig.getSetting(
105108
ProcessingConfig.SHOW_DEBUG_IN_DIALOG)
106109

110+
def requestFinished(self):
111+
"""Change the webview HTML content"""
112+
reply = self.sender()
113+
if reply.error() != QNetworkReply.NoError:
114+
html = self.tr('<h2>No help available for this algorithm</h2><p>{}</p>'.format(reply.errorString()))
115+
else:
116+
html = unicode(reply.readAll())
117+
reply.deleteLater()
118+
self.txtHelp.setHtml(html)
119+
107120
def closeEvent(self, evt):
108121
self.settings.setValue("/Processing/dialogBase", self.saveGeometry())
109122
super(AlgorithmDialogBase, self).closeEvent(evt)

python/plugins/processing/gui/DeleteScriptAction.py

+1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
from processing.script.ScriptAlgorithm import ScriptAlgorithm
3636
from processing.core.alglist import algList
3737

38+
3839
class DeleteScriptAction(ContextAction):
3940

4041
SCRIPT_PYTHON = 0

python/plugins/processing/gui/EditScriptAction.py

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
from processing.script.ScriptAlgorithm import ScriptAlgorithm
3232
from processing.core.alglist import algList
3333

34+
3435
class EditScriptAction(ContextAction):
3536

3637
SCRIPT_PYTHON = 0

python/plugins/processing/gui/GetScriptsAndModels.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -208,10 +208,10 @@ def treeLoaded(self, reply):
208208
self.tree.addTopLevelItem(self.notinstalledItem)
209209
self.tree.addTopLevelItem(self.uptodateItem)
210210

211-
self.webView.setHtml(self.HELP_TEXT)
211+
self.txtHelp.setHtml(self.HELP_TEXT)
212212

213213
def setHelp(self, reply, item):
214-
"""Change the webview HTML content"""
214+
"""Change the HTML content"""
215215
QApplication.restoreOverrideCursor()
216216
if reply.error() != QNetworkReply.NoError:
217217
html = self.tr('<h2>No detailed description available for this script</h2>')
@@ -223,14 +223,14 @@ def setHelp(self, reply, item):
223223
html += self.tr('<p><b>Created by:</b> %s') % getDescription(ALG_CREATOR, descriptions)
224224
html += self.tr('<p><b>Version:</b> %s') % getDescription(ALG_VERSION, descriptions)
225225
reply.deleteLater()
226-
self.webView.setHtml(html)
226+
self.txtHelp.setHtml(html)
227227

228228
def currentItemChanged(self, item, prev):
229229
if isinstance(item, TreeItem):
230230
url = self.urlBase + item.filename.replace(' ', '%20') + '.help'
231231
self.grabHTTP(url, self.setHelp, item)
232232
else:
233-
self.webView.setHtml(self.HELP_TEXT)
233+
self.txtHelp.setHtml(self.HELP_TEXT)
234234

235235
def getTreeBranchForState(self, filename, version):
236236
if not os.path.exists(os.path.join(self.folder, filename)):

python/plugins/processing/gui/HelpEditionDialog.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616
* *
1717
***************************************************************************
1818
"""
19-
from processing.modeler.ModelerAlgorithm import ModelerAlgorithm
20-
2119

2220
__author__ = 'Victor Olaya'
2321
__date__ = 'August 2012'
@@ -34,6 +32,7 @@
3432
from qgis.PyQt.QtWidgets import QDialog, QTreeWidgetItem
3533

3634
from processing.core.ProcessingLog import ProcessingLog
35+
from processing.modeler.ModelerAlgorithm import ModelerAlgorithm
3736

3837
pluginPath = os.path.split(os.path.dirname(__file__))[0]
3938
WIDGET, BASE = uic.loadUiType(
@@ -138,7 +137,7 @@ def changeItem(self):
138137
self.updateHtmlView()
139138

140139
def updateHtmlView(self):
141-
self.webView.setHtml(self.getHtml())
140+
self.txtPreview.setHtml(self.getHtml())
142141

143142
def getDescription(self, name):
144143
if name in self.descriptions:

python/plugins/processing/gui/ResultsDialog.py

+9-4
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
__revision__ = '$Format:%H$'
2727

2828
import os
29+
import codecs
2930

3031
from qgis.PyQt import uic
3132
from qgis.PyQt.QtCore import QUrl
@@ -53,7 +54,7 @@ def __init__(self):
5354
self.fillTree()
5455

5556
if self.lastUrl:
56-
self.webView.load(self.lastUrl)
57+
self.txtResults.setHtml(self.loadResults(self.lastUrl))
5758

5859
def fillTree(self):
5960
elements = ProcessingResults.getResults()
@@ -64,13 +65,17 @@ def fillTree(self):
6465
item = TreeResultItem(element)
6566
item.setIcon(0, self.keyIcon)
6667
self.tree.addTopLevelItem(item)
67-
self.lastUrl = QUrl(elements[-1].filename)
68+
self.lastUrl = elements[-1].filename
6869

6970
def changeResult(self):
7071
item = self.tree.currentItem()
7172
if isinstance(item, TreeResultItem):
72-
url = QUrl(item.filename)
73-
self.webView.load(url)
73+
self.txtResults.setHtml(self.loadResults(item.filename))
74+
75+
def loadResults(self, fileName):
76+
with codecs.open(fileName, encoding='utf-8') as f:
77+
content = f.read()
78+
return content
7479

7580

7681
class TreeResultItem(QTreeWidgetItem):

python/plugins/processing/modeler/DeleteModelAction.py

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
from processing.modeler.ModelerAlgorithm import ModelerAlgorithm
3232
from processing.core.alglist import algList
3333

34+
3435
class DeleteModelAction(ContextAction):
3536

3637
def __init__(self):

python/plugins/processing/modeler/EditModelAction.py

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
from processing.modeler.ModelerDialog import ModelerDialog
3131
from processing.core.alglist import algList
3232

33+
3334
class EditModelAction(ContextAction):
3435

3536
def __init__(self):

0 commit comments

Comments
 (0)