[processing] convert results viewer to dock

This commit is contained in:
Alexander Bruy 2017-02-10 13:35:58 +02:00
parent 35d9b83aa5
commit 5fa0713747
6 changed files with 119 additions and 135 deletions

View File

@ -40,13 +40,13 @@ from processing.core.Processing import Processing
from processing.gui.ProcessingToolbox import ProcessingToolbox
from processing.gui.HistoryDialog import HistoryDialog
from processing.gui.ConfigDialog import ConfigDialog
from processing.gui.ResultsDialog import ResultsDialog
from processing.gui.ResultsDock import ResultsDock
from processing.gui.CommanderWindow import CommanderWindow
from processing.modeler.ModelerDialog import ModelerDialog
from processing.tools.system import tempFolder
from processing.gui.menus import removeMenus, initializeMenus, createMenus
from processing.core.alglist import algList
from processing.core.ProcessingResults import resultsList
cmd_folder = os.path.split(inspect.getfile(inspect.currentframe()))[0]
if cmd_folder not in sys.path:
@ -65,6 +65,12 @@ class ProcessingPlugin(object):
self.iface.addDockWidget(Qt.RightDockWidgetArea, self.toolbox)
self.toolbox.hide()
self.resultsDock = ResultsDock()
self.iface.addDockWidget(Qt.RightDockWidgetArea, self.resultsDock)
self.resultsDock.hide()
resultsList.resultAdded.connect(self.resultsDock.fillTree)
self.menu = QMenu(self.iface.mainWindow().menuBar())
self.menu.setObjectName('processing')
self.menu.setTitle(self.tr('Pro&cessing'))
@ -93,11 +99,11 @@ class ProcessingPlugin(object):
self.iface.registerMainWindowAction(self.historyAction, 'Ctrl+Alt+H')
self.menu.addAction(self.historyAction)
self.resultsAction = QAction(
QIcon(os.path.join(cmd_folder, 'images', 'results.svg')),
self.tr('&Results Viewer...'), self.iface.mainWindow())
self.resultsAction = self.resultsDock.toggleViewAction()
self.resultsAction.setObjectName('resultsAction')
self.resultsAction.triggered.connect(self.openResults)
self.resultsAction.setIcon(
QIcon(os.path.join(cmd_folder, 'images', 'results.svg')))
self.resultsAction.setText(self.tr('&Results Viewer...'))
self.iface.registerMainWindowAction(self.resultsAction, 'Ctrl+Alt+R')
self.menu.addAction(self.resultsAction)
@ -132,6 +138,10 @@ class ProcessingPlugin(object):
def unload(self):
self.toolbox.setVisible(False)
self.iface.removeDockWidget(self.toolbox)
self.resultsDock.setVisible(False)
self.iface.removeDockWidget(self.resultsDock)
self.menu.deleteLater()
# delete temporary output files
@ -171,9 +181,10 @@ class ProcessingPlugin(object):
algList.reloadProvider('model')
def openResults(self):
dlg = ResultsDialog()
dlg.show()
dlg.exec_()
if self.resultsDock.isVisible():
self.resultsDock.hide()
else:
self.resultsDock.show()
def openHistory(self):
dlg = HistoryDialog()

View File

@ -26,22 +26,29 @@ __copyright__ = '(C) 2012, Victor Olaya'
__revision__ = '$Format:%H$'
from qgis.PyQt.QtCore import QObject, pyqtSignal
class ProcessingResults(object):
class ProcessingResults(QObject):
resultAdded = pyqtSignal()
results = []
@staticmethod
def addResult(name, result):
ProcessingResults.results.append(Result(name, result))
def addResult(self, icon, name, result):
self.results.append(Result(icon, name, result))
self.resultAdded.emit()
@staticmethod
def getResults():
return ProcessingResults.results
def getResults(self):
return self.results
class Result(object):
def __init__(self, name, filename):
def __init__(self, icon, name, filename):
self.icon = icon
self.name = name
self.filename = filename
resultsList = ProcessingResults()

View File

@ -34,10 +34,10 @@ from qgis.core import (QgsProject,
QgsProcessingFeedback)
from processing.core.ProcessingConfig import ProcessingConfig
from processing.core.ProcessingResults import ProcessingResults
from processing.core.ProcessingResults import resultsList
from processing.core.ProcessingLog import ProcessingLog
from processing.gui.ResultsDialog import ResultsDialog
#from processing.gui.ResultsDock import ResultsDock
from processing.gui.RenderingStyles import RenderingStyles
from processing.core.outputs import OutputRaster
@ -78,7 +78,7 @@ def handleAlgorithmResults(alg, feedback=None, showResults=True):
"Error loading result layer:\n" + traceback.format_exc())
wrongLayers.append(out.description)
elif isinstance(out, OutputHTML):
ProcessingResults.addResult(out.description, out.value)
resultsList.addResult(alg.getIcon(), out.description, out.value)
htmlResults = True
i += 1
@ -89,8 +89,8 @@ def handleAlgorithmResults(alg, feedback=None, showResults=True):
msg += "You can check the log messages to find more information about the execution of the algorithm"
feedback.reportError(msg)
if showResults and htmlResults and not wrongLayers:
dlg = ResultsDialog()
dlg.exec_()
#~ if showResults and htmlResults and not wrongLayers:
#~ dlg = ResultsDialog()
#~ dlg.exec_()
return len(wrongLayers) == 0

View File

@ -2,7 +2,7 @@
"""
***************************************************************************
ResultsDialog.py
ResultsDock.py
---------------------
Date : August 2012
Copyright : (C) 2012 by Victor Olaya
@ -30,57 +30,49 @@ import codecs
from qgis.PyQt import uic
from qgis.PyQt.QtCore import QUrl
from qgis.PyQt.QtGui import QIcon
from qgis.PyQt.QtWidgets import QStyle, QTreeWidgetItem
from qgis.PyQt.QtGui import QDesktopServices
from qgis.PyQt.QtWidgets import QTreeWidgetItem
from processing.core.ProcessingResults import ProcessingResults
from processing.core.ProcessingResults import resultsList
pluginPath = os.path.split(os.path.dirname(__file__))[0]
WIDGET, BASE = uic.loadUiType(
os.path.join(pluginPath, 'ui', 'DlgResults.ui'))
os.path.join(pluginPath, 'ui', 'resultsdockbase.ui'))
class ResultsDialog(BASE, WIDGET):
class ResultsDock(BASE, WIDGET):
def __init__(self):
super(ResultsDialog, self).__init__(None)
super(ResultsDock, self).__init__(None)
self.setupUi(self)
self.keyIcon = QIcon()
self.keyIcon.addPixmap(self.style().standardPixmap(QStyle.SP_FileIcon))
self.tree.currentItemChanged.connect(self.changeResult)
self.treeResults.currentItemChanged.connect(self.updateDescription)
self.treeResults.itemDoubleClicked.connect(self.openResult)
self.fillTree()
if self.lastUrl:
self.txtResults.setHtml(self.loadResults(self.lastUrl))
def fillTree(self):
elements = ProcessingResults.getResults()
if len(elements) == 0:
self.lastUrl = None
return
self.treeResults.blockSignals(True)
self.treeResults.clear()
elements = resultsList.getResults()
for element in elements:
item = TreeResultItem(element)
item.setIcon(0, self.keyIcon)
self.tree.addTopLevelItem(item)
self.lastUrl = elements[-1].filename
self.treeResults.addTopLevelItem(item)
self.treeResults.blockSignals(False)
def changeResult(self):
item = self.tree.currentItem()
if isinstance(item, TreeResultItem):
self.txtResults.setHtml(self.loadResults(item.filename))
def updateDescription(self, current, previous):
if isinstance(current, TreeResultItem):
html = '<b>Algorithm</b>: {}<br><b>File path</b>: {}'.format(current.text(0), current.filename)
self.txtDescription.setHtml(html)
def loadResults(self, fileName):
with codecs.open(fileName, encoding='utf-8') as f:
content = f.read()
return content
def openResult(self, item, column):
QDesktopServices.openUrl(QUrl.fromLocalFile(item.filename))
class TreeResultItem(QTreeWidgetItem):
def __init__(self, result):
QTreeWidgetItem.__init__(self)
self.filename = result.filename
self.setIcon(0, result.icon)
self.setText(0, result.name)
self.filename = result.filename

View File

@ -1,82 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>DlgResults</class>
<widget class="QDialog" name="DlgResults">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>623</width>
<height>515</height>
</rect>
</property>
<property name="windowTitle">
<string>Results</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QSplitter" name="splitter">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<widget class="QTreeWidget" name="tree">
<attribute name="headerVisible">
<bool>false</bool>
</attribute>
<column>
<property name="text">
<string notr="true">1</string>
</property>
</column>
</widget>
<widget class="QTextEdit" name="txtResults"/>
</widget>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Close</set>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>DlgResults</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>DlgResults</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>

View File

@ -0,0 +1,56 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>DockWidget</class>
<widget class="QDockWidget" name="DockWidget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>274</width>
<height>303</height>
</rect>
</property>
<property name="windowTitle">
<string>Processing results viewer</string>
</property>
<widget class="QWidget" name="dockWidgetContents">
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QSplitter" name="splitter">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<widget class="QTreeWidget" name="treeResults">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="MinimumExpanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="editTriggers">
<set>QAbstractItemView::NoEditTriggers</set>
</property>
<property name="alternatingRowColors">
<bool>false</bool>
</property>
<property name="rootIsDecorated">
<bool>false</bool>
</property>
<attribute name="headerVisible">
<bool>false</bool>
</attribute>
<column>
<property name="text">
<string notr="true">1</string>
</property>
</column>
</widget>
<widget class="QTextEdit" name="txtDescription"/>
</widget>
</item>
</layout>
</widget>
</widget>
<resources/>
<connections/>
</ui>