Skip to content

Commit 5fa0713

Browse files
committed
[processing] convert results viewer to dock
1 parent 35d9b83 commit 5fa0713

File tree

6 files changed

+119
-135
lines changed

6 files changed

+119
-135
lines changed

python/plugins/processing/ProcessingPlugin.py

+20-9
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,13 @@
4040
from processing.gui.ProcessingToolbox import ProcessingToolbox
4141
from processing.gui.HistoryDialog import HistoryDialog
4242
from processing.gui.ConfigDialog import ConfigDialog
43-
from processing.gui.ResultsDialog import ResultsDialog
43+
from processing.gui.ResultsDock import ResultsDock
4444
from processing.gui.CommanderWindow import CommanderWindow
4545
from processing.modeler.ModelerDialog import ModelerDialog
4646
from processing.tools.system import tempFolder
4747
from processing.gui.menus import removeMenus, initializeMenus, createMenus
4848
from processing.core.alglist import algList
49-
49+
from processing.core.ProcessingResults import resultsList
5050

5151
cmd_folder = os.path.split(inspect.getfile(inspect.currentframe()))[0]
5252
if cmd_folder not in sys.path:
@@ -65,6 +65,12 @@ def initGui(self):
6565
self.iface.addDockWidget(Qt.RightDockWidgetArea, self.toolbox)
6666
self.toolbox.hide()
6767

68+
self.resultsDock = ResultsDock()
69+
self.iface.addDockWidget(Qt.RightDockWidgetArea, self.resultsDock)
70+
self.resultsDock.hide()
71+
72+
resultsList.resultAdded.connect(self.resultsDock.fillTree)
73+
6874
self.menu = QMenu(self.iface.mainWindow().menuBar())
6975
self.menu.setObjectName('processing')
7076
self.menu.setTitle(self.tr('Pro&cessing'))
@@ -93,11 +99,11 @@ def initGui(self):
9399
self.iface.registerMainWindowAction(self.historyAction, 'Ctrl+Alt+H')
94100
self.menu.addAction(self.historyAction)
95101

96-
self.resultsAction = QAction(
97-
QIcon(os.path.join(cmd_folder, 'images', 'results.svg')),
98-
self.tr('&Results Viewer...'), self.iface.mainWindow())
102+
self.resultsAction = self.resultsDock.toggleViewAction()
99103
self.resultsAction.setObjectName('resultsAction')
100-
self.resultsAction.triggered.connect(self.openResults)
104+
self.resultsAction.setIcon(
105+
QIcon(os.path.join(cmd_folder, 'images', 'results.svg')))
106+
self.resultsAction.setText(self.tr('&Results Viewer...'))
101107
self.iface.registerMainWindowAction(self.resultsAction, 'Ctrl+Alt+R')
102108
self.menu.addAction(self.resultsAction)
103109

@@ -132,6 +138,10 @@ def initGui(self):
132138
def unload(self):
133139
self.toolbox.setVisible(False)
134140
self.iface.removeDockWidget(self.toolbox)
141+
142+
self.resultsDock.setVisible(False)
143+
self.iface.removeDockWidget(self.resultsDock)
144+
135145
self.menu.deleteLater()
136146

137147
# delete temporary output files
@@ -171,9 +181,10 @@ def updateModel(self):
171181
algList.reloadProvider('model')
172182

173183
def openResults(self):
174-
dlg = ResultsDialog()
175-
dlg.show()
176-
dlg.exec_()
184+
if self.resultsDock.isVisible():
185+
self.resultsDock.hide()
186+
else:
187+
self.resultsDock.show()
177188

178189
def openHistory(self):
179190
dlg = HistoryDialog()

python/plugins/processing/core/ProcessingResults.py

+15-8
Original file line numberDiff line numberDiff line change
@@ -26,22 +26,29 @@
2626

2727
__revision__ = '$Format:%H$'
2828

29+
from qgis.PyQt.QtCore import QObject, pyqtSignal
2930

30-
class ProcessingResults(object):
31+
32+
class ProcessingResults(QObject):
33+
34+
resultAdded = pyqtSignal()
3135

3236
results = []
3337

34-
@staticmethod
35-
def addResult(name, result):
36-
ProcessingResults.results.append(Result(name, result))
38+
def addResult(self, icon, name, result):
39+
self.results.append(Result(icon, name, result))
40+
self.resultAdded.emit()
3741

38-
@staticmethod
39-
def getResults():
40-
return ProcessingResults.results
42+
def getResults(self):
43+
return self.results
4144

4245

4346
class Result(object):
4447

45-
def __init__(self, name, filename):
48+
def __init__(self, icon, name, filename):
49+
self.icon = icon
4650
self.name = name
4751
self.filename = filename
52+
53+
54+
resultsList = ProcessingResults()

python/plugins/processing/gui/Postprocessing.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@
3434
QgsProcessingFeedback)
3535

3636
from processing.core.ProcessingConfig import ProcessingConfig
37-
from processing.core.ProcessingResults import ProcessingResults
37+
from processing.core.ProcessingResults import resultsList
3838
from processing.core.ProcessingLog import ProcessingLog
3939

40-
from processing.gui.ResultsDialog import ResultsDialog
40+
#from processing.gui.ResultsDock import ResultsDock
4141
from processing.gui.RenderingStyles import RenderingStyles
4242

4343
from processing.core.outputs import OutputRaster
@@ -78,7 +78,7 @@ def handleAlgorithmResults(alg, feedback=None, showResults=True):
7878
"Error loading result layer:\n" + traceback.format_exc())
7979
wrongLayers.append(out.description)
8080
elif isinstance(out, OutputHTML):
81-
ProcessingResults.addResult(out.description, out.value)
81+
resultsList.addResult(alg.getIcon(), out.description, out.value)
8282
htmlResults = True
8383
i += 1
8484

@@ -89,8 +89,8 @@ def handleAlgorithmResults(alg, feedback=None, showResults=True):
8989
msg += "You can check the log messages to find more information about the execution of the algorithm"
9090
feedback.reportError(msg)
9191

92-
if showResults and htmlResults and not wrongLayers:
93-
dlg = ResultsDialog()
94-
dlg.exec_()
92+
#~ if showResults and htmlResults and not wrongLayers:
93+
#~ dlg = ResultsDialog()
94+
#~ dlg.exec_()
9595

9696
return len(wrongLayers) == 0

python/plugins/processing/gui/ResultsDialog.py python/plugins/processing/gui/ResultsDock.py

+22-30
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
"""
44
***************************************************************************
5-
ResultsDialog.py
5+
ResultsDock.py
66
---------------------
77
Date : August 2012
88
Copyright : (C) 2012 by Victor Olaya
@@ -30,57 +30,49 @@
3030

3131
from qgis.PyQt import uic
3232
from qgis.PyQt.QtCore import QUrl
33-
from qgis.PyQt.QtGui import QIcon
34-
from qgis.PyQt.QtWidgets import QStyle, QTreeWidgetItem
33+
from qgis.PyQt.QtGui import QDesktopServices
34+
from qgis.PyQt.QtWidgets import QTreeWidgetItem
3535

36-
from processing.core.ProcessingResults import ProcessingResults
36+
from processing.core.ProcessingResults import resultsList
3737

3838
pluginPath = os.path.split(os.path.dirname(__file__))[0]
3939
WIDGET, BASE = uic.loadUiType(
40-
os.path.join(pluginPath, 'ui', 'DlgResults.ui'))
40+
os.path.join(pluginPath, 'ui', 'resultsdockbase.ui'))
4141

4242

43-
class ResultsDialog(BASE, WIDGET):
43+
class ResultsDock(BASE, WIDGET):
4444

4545
def __init__(self):
46-
super(ResultsDialog, self).__init__(None)
46+
super(ResultsDock, self).__init__(None)
4747
self.setupUi(self)
4848

49-
self.keyIcon = QIcon()
50-
self.keyIcon.addPixmap(self.style().standardPixmap(QStyle.SP_FileIcon))
51-
52-
self.tree.currentItemChanged.connect(self.changeResult)
49+
self.treeResults.currentItemChanged.connect(self.updateDescription)
50+
self.treeResults.itemDoubleClicked.connect(self.openResult)
5351

5452
self.fillTree()
5553

56-
if self.lastUrl:
57-
self.txtResults.setHtml(self.loadResults(self.lastUrl))
58-
5954
def fillTree(self):
60-
elements = ProcessingResults.getResults()
61-
if len(elements) == 0:
62-
self.lastUrl = None
63-
return
55+
self.treeResults.blockSignals(True)
56+
self.treeResults.clear()
57+
elements = resultsList.getResults()
6458
for element in elements:
6559
item = TreeResultItem(element)
66-
item.setIcon(0, self.keyIcon)
67-
self.tree.addTopLevelItem(item)
68-
self.lastUrl = elements[-1].filename
60+
self.treeResults.addTopLevelItem(item)
61+
self.treeResults.blockSignals(False)
6962

70-
def changeResult(self):
71-
item = self.tree.currentItem()
72-
if isinstance(item, TreeResultItem):
73-
self.txtResults.setHtml(self.loadResults(item.filename))
63+
def updateDescription(self, current, previous):
64+
if isinstance(current, TreeResultItem):
65+
html = '<b>Algorithm</b>: {}<br><b>File path</b>: {}'.format(current.text(0), current.filename)
66+
self.txtDescription.setHtml(html)
7467

75-
def loadResults(self, fileName):
76-
with codecs.open(fileName, encoding='utf-8') as f:
77-
content = f.read()
78-
return content
68+
def openResult(self, item, column):
69+
QDesktopServices.openUrl(QUrl.fromLocalFile(item.filename))
7970

8071

8172
class TreeResultItem(QTreeWidgetItem):
8273

8374
def __init__(self, result):
8475
QTreeWidgetItem.__init__(self)
85-
self.filename = result.filename
76+
self.setIcon(0, result.icon)
8677
self.setText(0, result.name)
78+
self.filename = result.filename

python/plugins/processing/ui/DlgResults.ui

-82
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<ui version="4.0">
3+
<class>DockWidget</class>
4+
<widget class="QDockWidget" name="DockWidget">
5+
<property name="geometry">
6+
<rect>
7+
<x>0</x>
8+
<y>0</y>
9+
<width>274</width>
10+
<height>303</height>
11+
</rect>
12+
</property>
13+
<property name="windowTitle">
14+
<string>Processing results viewer</string>
15+
</property>
16+
<widget class="QWidget" name="dockWidgetContents">
17+
<layout class="QVBoxLayout" name="verticalLayout">
18+
<item>
19+
<widget class="QSplitter" name="splitter">
20+
<property name="orientation">
21+
<enum>Qt::Vertical</enum>
22+
</property>
23+
<widget class="QTreeWidget" name="treeResults">
24+
<property name="sizePolicy">
25+
<sizepolicy hsizetype="MinimumExpanding" vsizetype="MinimumExpanding">
26+
<horstretch>0</horstretch>
27+
<verstretch>0</verstretch>
28+
</sizepolicy>
29+
</property>
30+
<property name="editTriggers">
31+
<set>QAbstractItemView::NoEditTriggers</set>
32+
</property>
33+
<property name="alternatingRowColors">
34+
<bool>false</bool>
35+
</property>
36+
<property name="rootIsDecorated">
37+
<bool>false</bool>
38+
</property>
39+
<attribute name="headerVisible">
40+
<bool>false</bool>
41+
</attribute>
42+
<column>
43+
<property name="text">
44+
<string notr="true">1</string>
45+
</property>
46+
</column>
47+
</widget>
48+
<widget class="QTextEdit" name="txtDescription"/>
49+
</widget>
50+
</item>
51+
</layout>
52+
</widget>
53+
</widget>
54+
<resources/>
55+
<connections/>
56+
</ui>

0 commit comments

Comments
 (0)