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

98 lines
3.4 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 time
2015-05-18 21:04:20 +03:00
2016-04-29 11:39:26 +02:00
from qgis.PyQt import uic
from qgis.PyQt.QtCore import (QUrl,
QFileInfo,
QDir)
from qgis.gui import QgsDockWidget
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(QgsDockWidget, 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
resultsList.resultAdded.connect(self.addResult)
self.treeResults.currentItemChanged.connect(self.updateDescription)
self.treeResults.itemDoubleClicked.connect(self.openResult)
2012-09-15 18:25:25 +03:00
self.txtDescription.setOpenLinks(False)
self.txtDescription.anchorClicked.connect(self.openLink)
2012-09-15 18:25:25 +03:00
self.fillTree()
2012-10-30 15:07:24 +02:00
def addResult(self):
self.fillTree()
# Automatically open the panel for users to see output
self.setUserVisible(True)
self.treeResults.setCurrentItem(self.treeResults.topLevelItem(0))
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.insertTopLevelItem(0, 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>: <a href="{}">{}</a>'.format(current.algorithm, QUrl.fromLocalFile(current.filename).toString(), QDir.toNativeSeparators(current.filename))
self.txtDescription.setHtml(html)
def openLink(self, url):
QDesktopServices.openUrl(url)
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)
self.setText(0, '{0} [{1}]'.format(result.name, time.strftime('%I:%M:%S%p', result.timestamp)))
self.algorithm = result.name
self.filename = result.filename