Skip to content
Permalink
Browse files

[processing] drop WebView dependency (backported from cc7eb27)

  • Loading branch information
jef-n committed Jun 26, 2016
1 parent f93faac commit fad50ecdb2c05ba5e12034159cfcf7c86522a9ce
@@ -31,6 +31,7 @@
from PyQt4 import uic
from PyQt4.QtCore import QCoreApplication, QSettings, QByteArray, SIGNAL, QUrl
from PyQt4.QtGui import QApplication, QDialogButtonBox, QDesktopWidget
from PyQt4.QtNetwork import QNetworkRequest, QNetworkReply

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

self.setWindowTitle(AlgorithmClassification.getDisplayName(self.alg))

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

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

def linkClicked(url):
webbrowser.open(url.toString())
self.textShortHelp.connect(self.textShortHelp, SIGNAL("anchorClicked(const QUrl&)"), 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)
@@ -207,10 +207,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>')
@@ -222,14 +222,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)):
@@ -138,7 +138,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 PyQt4 import uic
from PyQt4.QtCore import QUrl
@@ -52,7 +53,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()
@@ -63,13 +64,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):
@@ -27,7 +27,9 @@

from PyQt4.QtCore import Qt, QUrl, QMetaObject
from PyQt4.QtGui import QDialog, QDialogButtonBox, QLabel, QLineEdit, QFrame, QPushButton, QSizePolicy, QVBoxLayout, QHBoxLayout, QTabWidget, QWidget, QScrollArea, QComboBox, QTableWidgetItem, QMessageBox
from PyQt4.QtWebKit import QWebView
from PyQt4.QtNetwork import QNetworkRequest, QNetworkReply

from qgis.core import QgsNetworkAccessManager

from processing.modeler.ModelerAlgorithm import ValueFromInput, \
ValueFromOutput, Algorithm, ModelerOutput
@@ -166,27 +168,27 @@ def setupUi(self):
self.scrollArea.setWidget(self.paramPanel)
self.scrollArea.setWidgetResizable(True)
self.tabWidget.addTab(self.scrollArea, self.tr('Parameters'))
self.webView = QWebView()

self.txtHelp = QTextBrowser()

html = None
url = None
isText, help = self._alg.help()
if help is not None:
if isText:
html = help
else:
url = QUrl(help)
else:
html = self.tr('<h2>Sorry, no help is available for this '
'algorithm.</h2>')
try:
if html:
self.webView.setHtml(html)
elif url:
self.webView.load(url)
except:
self.webView.setHtml(self.tr('<h2>Could not open help file :-( </h2>'))
self.tabWidget.addTab(self.webView, 'Help')
isText, algHelp = self._alg.help()
if algHelp is not None:
algHelp = algHelp if isText else QUrl(algHelp)
try:
if isText:
self.txtHelp.setHtml(algHelp)
else:
html = self.tr('<p>Downloading algorithm help... Please wait.</p>')
self.txtHelp.setHtml(html)
self.reply = QgsNetworkAccessManager.instance().get(QNetworkRequest(algHelp))
self.reply.finished.connect(self.requestFinished)
except:
self.txtHelp.setHtml(self.tr('<h2>No help available for this algorithm</h2>'))

self.tabWidget.addTab(self.txtHelp, 'Help')

self.verticalLayout2.addWidget(self.tabWidget)
self.verticalLayout2.addWidget(self.buttonBox)
self.setLayout(self.verticalLayout2)
@@ -205,6 +207,16 @@ def getAvailableDependencies(self):
opts.append(alg)
return opts

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 getDependenciesPanel(self):
return MultipleInputPanel([alg.algorithm.name for alg in self.getAvailableDependencies()])

@@ -47,9 +47,6 @@
</property>
<item>
<widget class="QTextEdit" name="txtLog">
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
@@ -69,13 +66,7 @@
<number>0</number>
</property>
<item>
<widget class="QWebView" name="textHelp">
<property name="url">
<url>
<string>about:blank</string>
</url>
</property>
</widget>
<widget class="QTextBrowser" name="txtHelp"/>
</item>
</layout>
</widget>
@@ -131,13 +122,6 @@
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>QWebView</class>
<extends>QWidget</extends>
<header>QtWebKit/QWebView</header>
</customwidget>
</customwidgets>
<resources/>
<connections>
<connection>
@@ -74,7 +74,7 @@
<number>0</number>
</property>
<item>
<widget class="QWebView" name="webView">
<widget class="QTextEdit" name="txtHelp">
<property name="maximumSize">
<size>
<width>10000</width>
@@ -20,18 +20,14 @@
<property name="margin">
<number>9</number>
</property>
<item>
<widget class="QTextEdit" name="txtPreview"/>
</item>
<item>
<widget class="QSplitter" name="splitter_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<widget class="QWebView" name="webView">
<property name="url">
<url>
<string>about:blank</string>
</url>
</property>
</widget>
<widget class="QSplitter" name="splitter">
<property name="orientation">
<enum>Qt::Horizontal</enum>
@@ -110,13 +106,6 @@
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>QWebView</class>
<extends>QWidget</extends>
<header>QtWebKit/QWebView</header>
</customwidget>
</customwidgets>
<resources/>
<connections>
<connection>
@@ -41,19 +41,7 @@
</property>
</column>
</widget>
<widget class="QWebView" name="webView">
<property name="minimumSize">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="url">
<url>
<string>about:blank</string>
</url>
</property>
</widget>
<widget class="QTextEdit" name="txtResults"/>
</widget>
</item>
<item>
@@ -68,13 +56,6 @@
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>QWebView</class>
<extends>QWidget</extends>
<header>QtWebKit/QWebView</header>
</customwidget>
</customwidgets>
<resources/>
<connections>
<connection>

0 comments on commit fad50ec

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