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.
Expand Up @@ -29,10 +29,11 @@


from processing.core.Processing import Processing from processing.core.Processing import Processing



class ProcessingExampleScriptsPlugin: class ProcessingExampleScriptsPlugin:


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

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


print text print text
Expand Up @@ -55,8 +55,8 @@ def initializeSettings(self):
GrassUtils.grassPath(), valuetype=Setting.FOLDER)) GrassUtils.grassPath(), valuetype=Setting.FOLDER))
if isWindows(): if isWindows():
ProcessingConfig.addSetting(Setting(self.getDescription(), ProcessingConfig.addSetting(Setting(self.getDescription(),
GrassUtils.GRASS_WIN_SHELL, self.tr('Msys folder'), GrassUtils.GRASS_WIN_SHELL, self.tr('Msys folder'),
GrassUtils.grassWinShell(), valuetype=Setting.FOLDER)) GrassUtils.grassWinShell(), valuetype=Setting.FOLDER))
ProcessingConfig.addSetting(Setting(self.getDescription(), ProcessingConfig.addSetting(Setting(self.getDescription(),
GrassUtils.GRASS_LOG_COMMANDS, GrassUtils.GRASS_LOG_COMMANDS,
self.tr('Log execution commands'), False)) self.tr('Log execution commands'), False))
Expand Down
2 changes: 1 addition & 1 deletion python/plugins/processing/algs/otb/OTBUtils.py
Expand Up @@ -161,7 +161,7 @@ def executeOtb(commands, progress, addToLog=True):
os.putenv('ITK_AUTOLOAD_PATH', otbLibPath()) os.putenv('ITK_AUTOLOAD_PATH', otbLibPath())
fused_command = ''.join(['"%s" ' % re.sub(r'^"|"$', '', c) for c in commands]) 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 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) time.sleep(1)
for line in iter(proc.readline, ""): for line in iter(proc.readline, ""):
if "[*" in line: if "[*" in line:
Expand Down
4 changes: 2 additions & 2 deletions python/plugins/processing/algs/qgis/QGISAlgorithmProvider.py
Expand Up @@ -222,8 +222,8 @@ def __init__(self):
from .ExecuteSQL import ExecuteSQL from .ExecuteSQL import ExecuteSQL
self.alglist.extend([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') folder = os.path.join(os.path.dirname(__file__), 'scripts')
scripts = ScriptUtils.loadFromFolder(folder) scripts = ScriptUtils.loadFromFolder(folder)
for script in scripts: for script in scripts:
Expand Down
2 changes: 1 addition & 1 deletion python/plugins/processing/algs/saga/SagaUtils.py
Expand Up @@ -134,7 +134,7 @@ def getSagaInstalledVersion(runSaga=False):
stderr=subprocess.STDOUT, stderr=subprocess.STDOUT,
universal_newlines=True, universal_newlines=True,
).stdout ).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) time.sleep(1)
try: try:
lines = proc.readlines() lines = proc.readlines()
Expand Down
14 changes: 6 additions & 8 deletions python/plugins/processing/core/Processing.py
Expand Up @@ -64,11 +64,11 @@
from processing.algs.taudem.TauDEMAlgorithmProvider import TauDEMAlgorithmProvider from processing.algs.taudem.TauDEMAlgorithmProvider import TauDEMAlgorithmProvider
from processing.preconfigured.PreconfiguredAlgorithmProvider import PreconfiguredAlgorithmProvider from processing.preconfigured.PreconfiguredAlgorithmProvider import PreconfiguredAlgorithmProvider



class Processing: class Processing:


providers = [] providers = []



# Same structure as algs in algList # Same structure as algs in algList
actions = {} actions = {}


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

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



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



@staticmethod @staticmethod
def updateAlgsList(): def updateAlgsList():
Expand Down
3 changes: 2 additions & 1 deletion python/plugins/processing/core/alglist.py
Expand Up @@ -27,6 +27,7 @@


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



class AlgorithmList(QObject): class AlgorithmList(QObject):


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


algList = AlgorithmList() algList = AlgorithmList()
1 change: 0 additions & 1 deletion python/plugins/processing/core/defaultproviders.py
Expand Up @@ -26,7 +26,6 @@
__revision__ = '$Format:%H$' __revision__ = '$Format:%H$'





def loadDefaultProviders(): def loadDefaultProviders():
# this is here just to "trigger" the above imports so providers are loaded # this is here just to "trigger" the above imports so providers are loaded
# and can be found by the Processing.initialize() method # and can be found by the Processing.initialize() method
Expand Down
31 changes: 22 additions & 9 deletions python/plugins/processing/gui/AlgorithmDialogBase.py
Expand Up @@ -31,6 +31,7 @@
from qgis.PyQt import uic from qgis.PyQt import uic
from qgis.PyQt.QtCore import QCoreApplication, QSettings, QByteArray, QUrl from qgis.PyQt.QtCore import QCoreApplication, QSettings, QByteArray, QUrl
from qgis.PyQt.QtWidgets import QApplication, QDialogButtonBox, QDesktopWidget from qgis.PyQt.QtWidgets import QApplication, QDialogButtonBox, QDesktopWidget
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 QgsNetworkAccessManager
Expand Down Expand Up @@ -63,9 +64,9 @@ def __init__(self, alg):


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


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


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


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


self.showDebug = ProcessingConfig.getSetting( self.showDebug = ProcessingConfig.getSetting(
ProcessingConfig.SHOW_DEBUG_IN_DIALOG) 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): def closeEvent(self, evt):
self.settings.setValue("/Processing/dialogBase", self.saveGeometry()) self.settings.setValue("/Processing/dialogBase", self.saveGeometry())
super(AlgorithmDialogBase, self).closeEvent(evt) super(AlgorithmDialogBase, self).closeEvent(evt)
Expand Down
1 change: 1 addition & 0 deletions python/plugins/processing/gui/DeleteScriptAction.py
Expand Up @@ -35,6 +35,7 @@
from processing.script.ScriptAlgorithm import ScriptAlgorithm from processing.script.ScriptAlgorithm import ScriptAlgorithm
from processing.core.alglist import algList from processing.core.alglist import algList



class DeleteScriptAction(ContextAction): class DeleteScriptAction(ContextAction):


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



class EditScriptAction(ContextAction): class EditScriptAction(ContextAction):


SCRIPT_PYTHON = 0 SCRIPT_PYTHON = 0
Expand Down
8 changes: 4 additions & 4 deletions python/plugins/processing/gui/GetScriptsAndModels.py
Expand Up @@ -208,10 +208,10 @@ def treeLoaded(self, reply):
self.tree.addTopLevelItem(self.notinstalledItem) self.tree.addTopLevelItem(self.notinstalledItem)
self.tree.addTopLevelItem(self.uptodateItem) self.tree.addTopLevelItem(self.uptodateItem)


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


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


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


def getTreeBranchForState(self, filename, version): def getTreeBranchForState(self, filename, version):
if not os.path.exists(os.path.join(self.folder, filename)): 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
Expand Up @@ -16,8 +16,6 @@
* * * *
*************************************************************************** ***************************************************************************
""" """
from processing.modeler.ModelerAlgorithm import ModelerAlgorithm



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


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


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


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


def getDescription(self, name): def getDescription(self, name):
if name in self.descriptions: if name in self.descriptions:
Expand Down
13 changes: 9 additions & 4 deletions python/plugins/processing/gui/ResultsDialog.py
Expand Up @@ -26,6 +26,7 @@
__revision__ = '$Format:%H$' __revision__ = '$Format:%H$'


import os import os
import codecs


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


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


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


def changeResult(self): def changeResult(self):
item = self.tree.currentItem() item = self.tree.currentItem()
if isinstance(item, TreeResultItem): if isinstance(item, TreeResultItem):
url = QUrl(item.filename) self.txtResults.setHtml(self.loadResults(item.filename))
self.webView.load(url)
def loadResults(self, fileName):
with codecs.open(fileName, encoding='utf-8') as f:
content = f.read()
return content




class TreeResultItem(QTreeWidgetItem): class TreeResultItem(QTreeWidgetItem):
Expand Down
1 change: 1 addition & 0 deletions python/plugins/processing/modeler/DeleteModelAction.py
Expand Up @@ -31,6 +31,7 @@
from processing.modeler.ModelerAlgorithm import ModelerAlgorithm from processing.modeler.ModelerAlgorithm import ModelerAlgorithm
from processing.core.alglist import algList from processing.core.alglist import algList



class DeleteModelAction(ContextAction): class DeleteModelAction(ContextAction):


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



class EditModelAction(ContextAction): class EditModelAction(ContextAction):


def __init__(self): def __init__(self):
Expand Down

0 comments on commit cc7eb27

Please sign in to comment.