Skip to content

Commit

Permalink
Merge pull request #42541 from nirvn/processing_mini_imp
Browse files Browse the repository at this point in the history
[processing] A few UI improvements to the history dialog
  • Loading branch information
nirvn authored and github-actions[bot] committed Mar 29, 2021
1 parent 24b8998 commit 0a93406
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 10 deletions.
38 changes: 33 additions & 5 deletions python/plugins/processing/gui/HistoryDialog.py
Expand Up @@ -23,13 +23,16 @@

import os
import warnings
import re

from qgis.core import QgsApplication
from qgis.gui import QgsGui, QgsHelp
from qgis.PyQt import uic
from qgis.PyQt.QtCore import Qt, QCoreApplication
from qgis.PyQt.QtWidgets import QAction, QPushButton, QDialogButtonBox, QStyle, QMessageBox, QFileDialog, QMenu, QTreeWidgetItem
from qgis.PyQt.QtGui import QIcon
from qgis.PyQt.Qsci import QsciScintilla

from processing.gui import TestTools
from processing.core.ProcessingLog import ProcessingLog, LOG_SEPARATOR

Expand All @@ -49,6 +52,13 @@ def __init__(self):

QgsGui.instance().enableAutoGeometryRestore(self)

self.text.setReadOnly(True)
self.text.setCaretLineVisible(False)
self.text.setLineNumbersVisible(False) # NO linenumbers for the input line
self.text.setFoldingVisible(False)
self.text.setEdgeMode(QsciScintilla.EdgeNone)
self.text.setWrapMode(QsciScintilla.SC_WRAP_WORD)

self.groupIcon = QgsApplication.getThemeIcon('mIconFolder.svg')

self.keyIcon = self.style().standardIcon(QStyle.SP_FileIcon)
Expand Down Expand Up @@ -105,12 +115,29 @@ def openHelp(self):
def fillTree(self):
self.tree.clear()
entries = ProcessingLog.getLogEntries()
names = {}
icons = {}
groupItem = QTreeWidgetItem()
groupItem.setText(0, 'ALGORITHM')
groupItem.setIcon(0, self.groupIcon)
for entry in entries:
item = TreeLogEntryItem(entry, True)
item.setIcon(0, self.keyIcon)
icon = self.keyIcon
name = ''
match = re.search('processing.run\\("(.*?)"', entry.text)
if match.group:
algorithm_id = match.group(1)
if algorithm_id not in names:
algorithm = QgsApplication.processingRegistry().algorithmById(algorithm_id)
if algorithm:
names[algorithm_id] = algorithm.displayName()
icons[algorithm_id] = QgsApplication.processingRegistry().algorithmById(algorithm_id).icon()
else:
names[algorithm_id] = ''
icons[algorithm_id] = self.keyIcon
name = names[algorithm_id]
icon = icons[algorithm_id]
item = TreeLogEntryItem(entry, True, name)
item.setIcon(0, icon)
groupItem.insertChild(0, item)
self.tree.addTopLevelItem(groupItem)
groupItem.setExpanded(True)
Expand All @@ -131,7 +158,8 @@ def executeAlgorithm(self):
def changeText(self):
item = self.tree.currentItem()
if isinstance(item, TreeLogEntryItem):
self.text.setText(item.entry.text.replace(LOG_SEPARATOR, '\n'))
self.text.setText('"""\n' + self.tr('Double-click on the history item or paste the command below to re-run the algorithm') + '\n"""\n\n' +
item.entry.text.replace('processing.run(', 'processing.execAlgorithmDialog(').replace(LOG_SEPARATOR, '\n'))

def createTest(self):
item = self.tree.currentItem()
Expand All @@ -152,8 +180,8 @@ def showPopupMenu(self, point):

class TreeLogEntryItem(QTreeWidgetItem):

def __init__(self, entry, isAlg):
def __init__(self, entry, isAlg, algName):
QTreeWidgetItem.__init__(self)
self.entry = entry
self.isAlg = isAlg
self.setText(0, '[' + entry.date + '] ' + entry.text.split(LOG_SEPARATOR)[0])
self.setText(0, '[' + entry.date + '] ' + algName + ' - ' + entry.text.split(LOG_SEPARATOR)[0])
14 changes: 9 additions & 5 deletions python/plugins/processing/ui/DlgHistory.ui
Expand Up @@ -35,11 +35,7 @@
</property>
</column>
</widget>
<widget class="QTextEdit" name="text">
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
<widget class="QgsCodeEditorPython" name="text" native="true"/>
</widget>
</item>
<item>
Expand All @@ -54,6 +50,14 @@
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>QgsCodeEditorPython</class>
<extends>QWidget</extends>
<header>qgscodeeditorpython.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources/>
<connections>
<connection>
Expand Down

0 comments on commit 0a93406

Please sign in to comment.