Skip to content
Permalink
Browse files

[processing] drop WebView dependency (follow up 38f6ace)

  • Loading branch information
alexbruy committed May 27, 2016
1 parent dd69a59 commit cc7eb27a2720466e79eeff017be9c9de9daa145f
Showing with 147 additions and 222 deletions.
  1. +2 −1 python/plugins/processing/algs/examplescripts/ProcessingExampleScriptsPlugin.py
  2. +1 −1 python/plugins/processing/algs/examplescripts/scripts/examplescript.py
  3. +2 −2 python/plugins/processing/algs/grass/GrassAlgorithmProvider.py
  4. +1 −1 python/plugins/processing/algs/otb/OTBUtils.py
  5. +2 −2 python/plugins/processing/algs/qgis/QGISAlgorithmProvider.py
  6. +1 −1 python/plugins/processing/algs/saga/SagaUtils.py
  7. +6 −8 python/plugins/processing/core/Processing.py
  8. +2 −1 python/plugins/processing/core/alglist.py
  9. +0 −1 python/plugins/processing/core/defaultproviders.py
  10. +22 −9 python/plugins/processing/gui/AlgorithmDialogBase.py
  11. +1 −0 python/plugins/processing/gui/DeleteScriptAction.py
  12. +1 −0 python/plugins/processing/gui/EditScriptAction.py
  13. +4 −4 python/plugins/processing/gui/GetScriptsAndModels.py
  14. +2 −3 python/plugins/processing/gui/HelpEditionDialog.py
  15. +9 −4 python/plugins/processing/gui/ResultsDialog.py
  16. +1 −0 python/plugins/processing/modeler/DeleteModelAction.py
  17. +1 −0 python/plugins/processing/modeler/EditModelAction.py
  18. +35 −20 python/plugins/processing/modeler/ModelerParametersDialog.py
  19. +1 −0 python/plugins/processing/preconfigured/DeletePreconfiguredAlgorithmAction.py
  20. +1 −17 python/plugins/processing/ui/DlgAlgorithmBase.ui
  21. +48 −101 python/plugins/processing/ui/DlgGetScriptsAndModels.ui
  22. +3 −14 python/plugins/processing/ui/DlgHelpEdition.ui
  23. +1 −32 python/plugins/processing/ui/DlgResults.ui
@@ -29,10 +29,11 @@

from processing.core.Processing import Processing


class ProcessingExampleScriptsPlugin:

def initGui(self):
Processing.addScripts(os.path.join(os.path.dirname(__file__), "scripts"))

def unload(self):
Processing.removeScripts(os.path.join(os.path.dirname(__file__), "scripts"))
@@ -1,3 +1,3 @@
##text=string

print text
print text
@@ -55,8 +55,8 @@ def initializeSettings(self):
GrassUtils.grassPath(), valuetype=Setting.FOLDER))
if isWindows():
ProcessingConfig.addSetting(Setting(self.getDescription(),
GrassUtils.GRASS_WIN_SHELL, self.tr('Msys folder'),
GrassUtils.grassWinShell(), valuetype=Setting.FOLDER))
GrassUtils.GRASS_WIN_SHELL, self.tr('Msys folder'),
GrassUtils.grassWinShell(), valuetype=Setting.FOLDER))
ProcessingConfig.addSetting(Setting(self.getDescription(),
GrassUtils.GRASS_LOG_COMMANDS,
self.tr('Log execution commands'), False))
@@ -161,7 +161,7 @@ def executeOtb(commands, progress, addToLog=True):
os.putenv('ITK_AUTOLOAD_PATH', otbLibPath())
fused_command = ''.join(['"%s" ' % re.sub(r'^"|"$', '', c) for c in commands])
proc = subprocess.Popen(fused_command, shell=True, stdout=subprocess.PIPE, stdin=open(os.devnull), stderr=subprocess.STDOUT, universal_newlines=True).stdout
if isMac(): #This trick avoids having an uninterrupted system call exception if OTB is not installed
if isMac(): # This trick avoids having an uninterrupted system call exception if OTB is not installed
time.sleep(1)
for line in iter(proc.readline, ""):
if "[*" in line:
@@ -222,8 +222,8 @@ def __init__(self):
from .ExecuteSQL import ExecuteSQL
self.alglist.extend([ExecuteSQL()])

self.externalAlgs = [] #to store algs added by 3rd party plugins as scripts
self.externalAlgs = [] # to store algs added by 3rd party plugins as scripts

folder = os.path.join(os.path.dirname(__file__), 'scripts')
scripts = ScriptUtils.loadFromFolder(folder)
for script in scripts:
@@ -134,7 +134,7 @@ def getSagaInstalledVersion(runSaga=False):
stderr=subprocess.STDOUT,
universal_newlines=True,
).stdout
if isMac(): #This trick avoids having an uninterrupted system call exception if SAGA is not installed
if isMac(): # This trick avoids having an uninterrupted system call exception if SAGA is not installed
time.sleep(1)
try:
lines = proc.readlines()
@@ -64,11 +64,11 @@
from processing.algs.taudem.TauDEMAlgorithmProvider import TauDEMAlgorithmProvider
from processing.preconfigured.PreconfiguredAlgorithmProvider import PreconfiguredAlgorithmProvider


class Processing:

providers = []


# Same structure as algs in algList
actions = {}

@@ -134,8 +134,8 @@ def initialize():
ProcessingConfig.initialize()
ProcessingConfig.readSettings()
RenderingStyles.loadStyles()
@staticmethod

@staticmethod
def addScripts(folder):
Processing.initialize()
provider = Processing.getProviderFromName("qgis")
@@ -145,19 +145,17 @@ def addScripts(folder):
script.allowEdit = False
script._icon = provider._icon
script.provider = provider
provider.externalAlgs.extend(scripts)
provider.externalAlgs.extend(scripts)
Processing.reloadProvider("qgis")



@staticmethod
def removeScripts(folder):
provider = Processing.getProviderFromName("qgis")
for alg in provider.externalAlgs[::-1]:
path = os.path.dirname(alg.descriptionFile)
if path == folder:
provider.externalAlgs.remove(alg)
provider.externalAlgs.remove(alg)
Processing.reloadProvider("qgis")


@staticmethod
def updateAlgsList():
@@ -27,6 +27,7 @@

from qgis.PyQt.QtCore import QObject, pyqtSignal


class AlgorithmList(QObject):

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

algList = AlgorithmList()
algList = AlgorithmList()
@@ -26,7 +26,6 @@
__revision__ = '$Format:%H$'



def loadDefaultProviders():
# this is here just to "trigger" the above imports so providers are loaded
# and can be found by the Processing.initialize() method
@@ -31,6 +31,7 @@
from qgis.PyQt import uic
from qgis.PyQt.QtCore import QCoreApplication, QSettings, QByteArray, QUrl
from qgis.PyQt.QtWidgets import QApplication, QDialogButtonBox, QDesktopWidget
from qgis.PyQt.QtNetwork import QNetworkRequest, QNetworkReply

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

self.setWindowTitle(self.alg.displayName())

desktop = QDesktopWidget()
if desktop.physicalDpiX() > 96:
self.textHelp.setZoomFactor(desktop.physicalDpiX() / 96)
#~ desktop = QDesktopWidget()
#~ if desktop.physicalDpiX() > 96:
#~ self.txtHelp.setZoomFactor(desktop.physicalDpiX() / 96)

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

def linkClicked(url):
webbrowser.open(url.toString())
self.textShortHelp.anchorClicked.connect(linkClicked)

self.textHelp.page().setNetworkAccessManager(QgsNetworkAccessManager.instance())
self.textShortHelp.anchorClicked.connect(linkClicked)

isText, algHelp = self.alg.help()
if algHelp is not None:
algHelp = algHelp if isText else QUrl(algHelp)
try:
if isText:
self.textHelp.setHtml(algHelp)
self.txtHelp.setHtml(algHelp)
else:
self.textHelp.settings().clearMemoryCaches()
self.textHelp.load(algHelp)
except:
html = self.tr('<p>Downloading algorithm help... Please wait.</p>')
self.txtHelp.setHtml(html)
rq = QNetworkRequest(algHelp)
self.reply = QgsNetworkAccessManager.instance().get(rq)
self.reply.finished.connect(self.requestFinished)
except Exception, e:
self.tabWidget.removeTab(2)
else:
self.tabWidget.removeTab(2)

self.showDebug = ProcessingConfig.getSetting(
ProcessingConfig.SHOW_DEBUG_IN_DIALOG)

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 = unicode(reply.readAll())
reply.deleteLater()
self.txtHelp.setHtml(html)

def closeEvent(self, evt):
self.settings.setValue("/Processing/dialogBase", self.saveGeometry())
super(AlgorithmDialogBase, self).closeEvent(evt)
@@ -35,6 +35,7 @@
from processing.script.ScriptAlgorithm import ScriptAlgorithm
from processing.core.alglist import algList


class DeleteScriptAction(ContextAction):

SCRIPT_PYTHON = 0
@@ -31,6 +31,7 @@
from processing.script.ScriptAlgorithm import ScriptAlgorithm
from processing.core.alglist import algList


class EditScriptAction(ContextAction):

SCRIPT_PYTHON = 0
@@ -208,10 +208,10 @@ def treeLoaded(self, reply):
self.tree.addTopLevelItem(self.notinstalledItem)
self.tree.addTopLevelItem(self.uptodateItem)

self.webView.setHtml(self.HELP_TEXT)
self.txtHelp.setHtml(self.HELP_TEXT)

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

def currentItemChanged(self, item, prev):
if isinstance(item, TreeItem):
url = self.urlBase + item.filename.replace(' ', '%20') + '.help'
self.grabHTTP(url, self.setHelp, item)
else:
self.webView.setHtml(self.HELP_TEXT)
self.txtHelp.setHtml(self.HELP_TEXT)

def getTreeBranchForState(self, filename, version):
if not os.path.exists(os.path.join(self.folder, filename)):
@@ -16,8 +16,6 @@
* *
***************************************************************************
"""
from processing.modeler.ModelerAlgorithm import ModelerAlgorithm


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

from processing.core.ProcessingLog import ProcessingLog
from processing.modeler.ModelerAlgorithm import ModelerAlgorithm

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

def updateHtmlView(self):
self.webView.setHtml(self.getHtml())
self.txtPreview.setHtml(self.getHtml())

def getDescription(self, name):
if name in self.descriptions:
@@ -26,6 +26,7 @@
__revision__ = '$Format:%H$'

import os
import codecs

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

if self.lastUrl:
self.webView.load(self.lastUrl)
self.txtResults.setHtml(self.loadResults(self.lastUrl))

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

def changeResult(self):
item = self.tree.currentItem()
if isinstance(item, TreeResultItem):
url = QUrl(item.filename)
self.webView.load(url)
self.txtResults.setHtml(self.loadResults(item.filename))

def loadResults(self, fileName):
with codecs.open(fileName, encoding='utf-8') as f:
content = f.read()
return content


class TreeResultItem(QTreeWidgetItem):
@@ -31,6 +31,7 @@
from processing.modeler.ModelerAlgorithm import ModelerAlgorithm
from processing.core.alglist import algList


class DeleteModelAction(ContextAction):

def __init__(self):
@@ -30,6 +30,7 @@
from processing.modeler.ModelerDialog import ModelerDialog
from processing.core.alglist import algList


class EditModelAction(ContextAction):

def __init__(self):

0 comments on commit cc7eb27

Please sign in to comment.
You can’t perform that action at this time.