Skip to content

Commit

Permalink
[processing] drop WebView dependency (follow up 38f6ace)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexbruy committed May 27, 2016
1 parent dd69a59 commit cc7eb27
Show file tree
Hide file tree
Showing 23 changed files with 147 additions and 222 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
##text=string

print text
print text
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion python/plugins/processing/algs/otb/OTBUtils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions python/plugins/processing/algs/qgis/QGISAlgorithmProvider.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion python/plugins/processing/algs/saga/SagaUtils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
14 changes: 6 additions & 8 deletions python/plugins/processing/core/Processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}

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

@staticmethod
def addScripts(folder):
Processing.initialize()
provider = Processing.getProviderFromName("qgis")
Expand All @@ -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():
Expand Down
3 changes: 2 additions & 1 deletion python/plugins/processing/core/alglist.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

from qgis.PyQt.QtCore import QObject, pyqtSignal


class AlgorithmList(QObject):

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

algList = AlgorithmList()
algList = AlgorithmList()
1 change: 0 additions & 1 deletion python/plugins/processing/core/defaultproviders.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
31 changes: 22 additions & 9 deletions python/plugins/processing/gui/AlgorithmDialogBase.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand All @@ -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)
Expand Down
1 change: 1 addition & 0 deletions python/plugins/processing/gui/DeleteScriptAction.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
from processing.script.ScriptAlgorithm import ScriptAlgorithm
from processing.core.alglist import algList


class DeleteScriptAction(ContextAction):

SCRIPT_PYTHON = 0
Expand Down
1 change: 1 addition & 0 deletions python/plugins/processing/gui/EditScriptAction.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
from processing.script.ScriptAlgorithm import ScriptAlgorithm
from processing.core.alglist import algList


class EditScriptAction(ContextAction):

SCRIPT_PYTHON = 0
Expand Down
8 changes: 4 additions & 4 deletions python/plugins/processing/gui/GetScriptsAndModels.py
Original file line number Diff line number Diff line change
Expand Up @@ -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>')
Expand All @@ -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)):
Expand Down
5 changes: 2 additions & 3 deletions python/plugins/processing/gui/HelpEditionDialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
* *
***************************************************************************
"""
from processing.modeler.ModelerAlgorithm import ModelerAlgorithm


__author__ = 'Victor Olaya'
__date__ = 'August 2012'
Expand All @@ -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(
Expand Down Expand Up @@ -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:
Expand Down
13 changes: 9 additions & 4 deletions python/plugins/processing/gui/ResultsDialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
__revision__ = '$Format:%H$'

import os
import codecs

from qgis.PyQt import uic
from qgis.PyQt.QtCore import QUrl
Expand Down Expand Up @@ -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()
Expand All @@ -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):
Expand Down
1 change: 1 addition & 0 deletions python/plugins/processing/modeler/DeleteModelAction.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
from processing.modeler.ModelerAlgorithm import ModelerAlgorithm
from processing.core.alglist import algList


class DeleteModelAction(ContextAction):

def __init__(self):
Expand Down
1 change: 1 addition & 0 deletions python/plugins/processing/modeler/EditModelAction.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
from processing.modeler.ModelerDialog import ModelerDialog
from processing.core.alglist import algList


class EditModelAction(ContextAction):

def __init__(self):
Expand Down
Loading

0 comments on commit cc7eb27

Please sign in to comment.