Skip to content

Commit

Permalink
[processing] convert results viewer to dock
Browse files Browse the repository at this point in the history
  • Loading branch information
alexbruy committed Feb 16, 2017
1 parent 35d9b83 commit 5fa0713
Show file tree
Hide file tree
Showing 6 changed files with 119 additions and 135 deletions.
29 changes: 20 additions & 9 deletions python/plugins/processing/ProcessingPlugin.py
Expand Up @@ -40,13 +40,13 @@
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:
Expand All @@ -65,6 +65,12 @@ def initGui(self):
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'))
Expand Down Expand Up @@ -93,11 +99,11 @@ def initGui(self):
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)

Expand Down Expand Up @@ -132,6 +138,10 @@ def initGui(self):
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
Expand Down Expand Up @@ -171,9 +181,10 @@ def updateModel(self):
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()
Expand Down
23 changes: 15 additions & 8 deletions python/plugins/processing/core/ProcessingResults.py
Expand Up @@ -26,22 +26,29 @@

__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()
12 changes: 6 additions & 6 deletions python/plugins/processing/gui/Postprocessing.py
Expand Up @@ -34,10 +34,10 @@
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
Expand Down Expand Up @@ -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

Expand All @@ -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
Expand Up @@ -2,7 +2,7 @@

"""
***************************************************************************
ResultsDialog.py
ResultsDock.py
---------------------
Date : August 2012
Copyright : (C) 2012 by Victor Olaya
Expand Down Expand Up @@ -30,57 +30,49 @@

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
82 changes: 0 additions & 82 deletions python/plugins/processing/ui/DlgResults.ui

This file was deleted.

56 changes: 56 additions & 0 deletions python/plugins/processing/ui/resultsdockbase.ui
@@ -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>

0 comments on commit 5fa0713

Please sign in to comment.