From cb41ef1adcf440dbad1a363c79eeba66a0b49113 Mon Sep 17 00:00:00 2001 From: Nyall Dawson Date: Sun, 11 Jun 2017 19:35:43 +1000 Subject: [PATCH] Output useful logging when running algorithms from toolbox Now outputs the input parameters, execution time, and results --- python/core/__init__.py | 11 +++++++++++ python/plugins/processing/gui/AlgorithmDialog.py | 11 +++++++++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/python/core/__init__.py b/python/core/__init__.py index a659fb88d28..a55558ade37 100644 --- a/python/core/__init__.py +++ b/python/core/__init__.py @@ -264,3 +264,14 @@ def fromFunction(description, function, *args, on_finished=None, flags=QgsTask.A QgsTask.fromFunction = fromFunction + + +# add some __repr__ methods to processing classes +def processing_source_repr(self): + return "".format(self.source.staticValue(), self.selectedFeaturesOnly) +QgsProcessingFeatureSourceDefinition.__repr__ = processing_source_repr + + +def processing_output_layer_repr(self): + return "".format(self.sink.staticValue(), self.createOptions) +QgsProcessingOutputLayerDefinition.__repr__ = processing_output_layer_repr diff --git a/python/plugins/processing/gui/AlgorithmDialog.py b/python/plugins/processing/gui/AlgorithmDialog.py index d50ae31ce82..16c92a575eb 100644 --- a/python/plugins/processing/gui/AlgorithmDialog.py +++ b/python/plugins/processing/gui/AlgorithmDialog.py @@ -26,6 +26,9 @@ __copyright__ = '(C) 2012, Victor Olaya' __revision__ = '$Format:%H$' +from pprint import pformat +import time + from qgis.PyQt.QtCore import Qt from qgis.PyQt.QtWidgets import QMessageBox, QApplication, QPushButton, QWidget, QVBoxLayout, QSizePolicy from qgis.PyQt.QtGui import QCursor, QColor, QPalette @@ -168,8 +171,6 @@ class AlgorithmDialog(AlgorithmDialogBase): parameters = self.getParamValues() - QgsMessageLog.logMessage(str(parameters), 'Processing', QgsMessageLog.CRITICAL) - if checkCRS and not self.alg.validateInputCrs(parameters, context): reply = QMessageBox.question(self, self.tr("Unmatching CRS's"), self.tr('Layers do not all use the same CRS. This can ' @@ -221,6 +222,9 @@ class AlgorithmDialog(AlgorithmDialogBase): self.setInfo( self.tr('Algorithm {0} starting...').format(self.alg.displayName())) + feedback.pushInfo(self.tr('Input parameters:\n{}\n'.format(pformat(parameters)))) + start_time = time.time() + if self.iterateParam: if executeIterating(self.alg, parameters, self.iterateParam, context, feedback): self.finish(parameters, context, feedback) @@ -234,6 +238,9 @@ class AlgorithmDialog(AlgorithmDialogBase): # ProcessingLog.addToLog(command) self.buttonCancel.setEnabled(self.alg.flags() & QgsProcessingAlgorithm.FlagCanCancel) result = executeAlgorithm(self.alg, parameters, context, feedback) + feedback.pushInfo(self.tr('Execution completed in {0:0.2f} seconds'.format(time.time() - start_time))) + feedback.pushInfo(self.tr('Results:\n{}\n'.format(pformat(result)))) + self.buttonCancel.setEnabled(False) self.finish(result, context, feedback) #TODO