[processing] offer hyperlink to file path in the results viewer

because users don't always get that there is a dbl-click action
against the tree view items.
This commit is contained in:
nirvn 2018-02-12 16:58:15 +07:00 committed by Mathieu Pellerin
parent a9d61ff508
commit 207a94738d
2 changed files with 11 additions and 3 deletions

View File

@ -29,7 +29,9 @@ import os
import time
from qgis.PyQt import uic
from qgis.PyQt.QtCore import QUrl
from qgis.PyQt.QtCore import (QUrl,
QFileInfo,
QDir)
from qgis.PyQt.QtGui import QDesktopServices
from qgis.PyQt.QtWidgets import QTreeWidgetItem
@ -49,6 +51,9 @@ class ResultsDock(BASE, WIDGET):
self.treeResults.currentItemChanged.connect(self.updateDescription)
self.treeResults.itemDoubleClicked.connect(self.openResult)
self.txtDescription.setOpenLinks(False)
self.txtDescription.anchorClicked.connect(self.openLink)
self.fillTree()
def fillTree(self):
@ -62,9 +67,12 @@ class ResultsDock(BASE, WIDGET):
def updateDescription(self, current, previous):
if isinstance(current, TreeResultItem):
html = '<b>Algorithm</b>: {}<br><b>File path</b>: {}'.format(current.algorithm, current.filename)
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))

View File

@ -45,7 +45,7 @@
</property>
</column>
</widget>
<widget class="QTextEdit" name="txtDescription"/>
<widget class="QTextBrowser" name="txtDescription"/>
</widget>
</item>
</layout>