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

79 lines
2.6 KiB
Python
Raw Normal View History

2012-10-05 23:28:47 +02:00
# -*- coding: utf-8 -*-
"""
***************************************************************************
ResultsDock.py
2012-10-05 23:28:47 +02:00
---------------------
Date : August 2012
Copyright : (C) 2012 by Victor Olaya
Email : volayaf at gmail dot com
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************
"""
__author__ = 'Victor Olaya'
__date__ = 'August 2012'
__copyright__ = '(C) 2012, Victor Olaya'
2012-10-05 23:28:47 +02:00
# This will get replaced with a git SHA1 when you do a git archive
2012-10-05 23:28:47 +02:00
__revision__ = '$Format:%H$'
2015-05-18 21:04:20 +03:00
import os
import codecs
2015-05-18 21:04:20 +03:00
2016-04-29 11:39:26 +02:00
from qgis.PyQt import uic
2016-04-22 10:38:48 +02:00
from qgis.PyQt.QtCore import QUrl
from qgis.PyQt.QtGui import QDesktopServices
from qgis.PyQt.QtWidgets import QTreeWidgetItem
2012-10-30 15:07:24 +02:00
from processing.core.ProcessingResults import resultsList
2012-09-15 18:25:25 +03:00
2015-05-18 21:04:20 +03:00
pluginPath = os.path.split(os.path.dirname(__file__))[0]
WIDGET, BASE = uic.loadUiType(
os.path.join(pluginPath, 'ui', 'resultsdockbase.ui'))
2012-10-30 15:07:24 +02:00
class ResultsDock(BASE, WIDGET):
2012-09-15 18:25:25 +03:00
def __init__(self):
super(ResultsDock, self).__init__(None)
2012-10-30 15:07:24 +02:00
self.setupUi(self)
2012-12-10 00:12:07 +01:00
self.treeResults.currentItemChanged.connect(self.updateDescription)
self.treeResults.itemDoubleClicked.connect(self.openResult)
2012-09-15 18:25:25 +03:00
self.fillTree()
2012-10-30 15:07:24 +02:00
2012-09-15 18:25:25 +03:00
def fillTree(self):
self.treeResults.blockSignals(True)
self.treeResults.clear()
elements = resultsList.getResults()
2012-09-15 18:25:25 +03:00
for element in elements:
item = TreeResultItem(element)
self.treeResults.addTopLevelItem(item)
self.treeResults.blockSignals(False)
2012-09-15 18:25:25 +03:00
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 openResult(self, item, column):
QDesktopServices.openUrl(QUrl.fromLocalFile(item.filename))
2012-09-15 18:25:25 +03:00
2012-10-30 15:07:24 +02:00
class TreeResultItem(QTreeWidgetItem):
2012-09-15 18:25:25 +03:00
def __init__(self, result):
QTreeWidgetItem.__init__(self)
self.setIcon(0, result.icon)
2012-09-15 18:25:25 +03:00
self.setText(0, result.name)
self.filename = result.filename