Skip to content

Commit cb41ef1

Browse files
committed
Output useful logging when running algorithms from toolbox
Now outputs the input parameters, execution time, and results
1 parent 1d6d4be commit cb41ef1

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

python/core/__init__.py

+11
Original file line numberDiff line numberDiff line change
@@ -264,3 +264,14 @@ def calculation_finished(exception, value=None):
264264

265265

266266
QgsTask.fromFunction = fromFunction
267+
268+
269+
# add some __repr__ methods to processing classes
270+
def processing_source_repr(self):
271+
return "<QgsProcessingFeatureSourceDefinition {{'source':{}, 'selectedFeaturesOnly': {}}}>".format(self.source.staticValue(), self.selectedFeaturesOnly)
272+
QgsProcessingFeatureSourceDefinition.__repr__ = processing_source_repr
273+
274+
275+
def processing_output_layer_repr(self):
276+
return "<QgsProcessingOutputLayerDefinition {{'sink':{}, 'createOptions': {}}}>".format(self.sink.staticValue(), self.createOptions)
277+
QgsProcessingOutputLayerDefinition.__repr__ = processing_output_layer_repr

python/plugins/processing/gui/AlgorithmDialog.py

+9-2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@
2626

2727
__revision__ = '$Format:%H$'
2828

29+
from pprint import pformat
30+
import time
31+
2932
from qgis.PyQt.QtCore import Qt
3033
from qgis.PyQt.QtWidgets import QMessageBox, QApplication, QPushButton, QWidget, QVBoxLayout, QSizePolicy
3134
from qgis.PyQt.QtGui import QCursor, QColor, QPalette
@@ -168,8 +171,6 @@ def accept(self):
168171

169172
parameters = self.getParamValues()
170173

171-
QgsMessageLog.logMessage(str(parameters), 'Processing', QgsMessageLog.CRITICAL)
172-
173174
if checkCRS and not self.alg.validateInputCrs(parameters, context):
174175
reply = QMessageBox.question(self, self.tr("Unmatching CRS's"),
175176
self.tr('Layers do not all use the same CRS. This can '
@@ -221,6 +222,9 @@ def accept(self):
221222
self.setInfo(
222223
self.tr('<b>Algorithm {0} starting...</b>').format(self.alg.displayName()))
223224

225+
feedback.pushInfo(self.tr('Input parameters:\n{}\n'.format(pformat(parameters))))
226+
start_time = time.time()
227+
224228
if self.iterateParam:
225229
if executeIterating(self.alg, parameters, self.iterateParam, context, feedback):
226230
self.finish(parameters, context, feedback)
@@ -234,6 +238,9 @@ def accept(self):
234238
# ProcessingLog.addToLog(command)
235239
self.buttonCancel.setEnabled(self.alg.flags() & QgsProcessingAlgorithm.FlagCanCancel)
236240
result = executeAlgorithm(self.alg, parameters, context, feedback)
241+
feedback.pushInfo(self.tr('Execution completed in {0:0.2f} seconds'.format(time.time() - start_time)))
242+
feedback.pushInfo(self.tr('Results:\n{}\n'.format(pformat(result))))
243+
237244
self.buttonCancel.setEnabled(False)
238245
self.finish(result, context, feedback)
239246
#TODO

0 commit comments

Comments
 (0)