Skip to content
Permalink
Browse files

Output useful logging when running algorithms from toolbox

Now outputs the input parameters, execution time, and results
  • Loading branch information
nyalldawson committed Jun 11, 2017
1 parent 1d6d4be commit cb41ef1adcf440dbad1a363c79eeba66a0b49113
Showing with 20 additions and 2 deletions.
  1. +11 −0 python/core/__init__.py
  2. +9 −2 python/plugins/processing/gui/AlgorithmDialog.py
@@ -264,3 +264,14 @@ def calculation_finished(exception, value=None):


QgsTask.fromFunction = fromFunction


# add some __repr__ methods to processing classes
def processing_source_repr(self):
return "<QgsProcessingFeatureSourceDefinition {{'source':{}, 'selectedFeaturesOnly': {}}}>".format(self.source.staticValue(), self.selectedFeaturesOnly)
QgsProcessingFeatureSourceDefinition.__repr__ = processing_source_repr


def processing_output_layer_repr(self):
return "<QgsProcessingOutputLayerDefinition {{'sink':{}, 'createOptions': {}}}>".format(self.sink.staticValue(), self.createOptions)
QgsProcessingOutputLayerDefinition.__repr__ = processing_output_layer_repr
@@ -26,6 +26,9 @@

__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 @@ def accept(self):

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 @@ def accept(self):
self.setInfo(
self.tr('<b>Algorithm {0} starting...</b>').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 @@ def accept(self):
# 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

0 comments on commit cb41ef1

Please sign in to comment.
You can’t perform that action at this time.