Skip to content

Commit

Permalink
Output useful logging when running algorithms from toolbox
Browse files Browse the repository at this point in the history
Now outputs the input parameters, execution time, and results
  • Loading branch information
nyalldawson committed Jun 11, 2017
1 parent 1d6d4be commit cb41ef1
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
11 changes: 11 additions & 0 deletions python/core/__init__.py
Expand Up @@ -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
11 changes: 9 additions & 2 deletions python/plugins/processing/gui/AlgorithmDialog.py
Expand Up @@ -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
Expand Down Expand Up @@ -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 '
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down

0 comments on commit cb41ef1

Please sign in to comment.