Skip to content

Commit b40f409

Browse files
committedJun 11, 2017
Nicer formatting for log in algorithm dialog
1 parent 29f50b7 commit b40f409

File tree

3 files changed

+19
-12
lines changed

3 files changed

+19
-12
lines changed
 

‎python/plugins/processing/gui/AlgorithmDialog.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -220,9 +220,11 @@ def accept(self):
220220
QApplication.setOverrideCursor(QCursor(Qt.WaitCursor))
221221

222222
self.setInfo(
223-
self.tr('<b>Algorithm {0} starting...</b>').format(self.alg.displayName()))
223+
self.tr('<b>Algorithm \'{0}\' starting...</b>').format(self.alg.displayName()), escape_html=False)
224224

225-
feedback.pushInfo(self.tr('Input parameters:\n{}\n'.format(pformat(parameters))))
225+
feedback.pushInfo(self.tr('Input parameters:'))
226+
feedback.pushCommandInfo(pformat(parameters))
227+
feedback.pushInfo('')
226228
start_time = time.time()
227229

228230
if self.iterateParam:
@@ -239,7 +241,9 @@ def accept(self):
239241
self.buttonCancel.setEnabled(self.alg.flags() & QgsProcessingAlgorithm.FlagCanCancel)
240242
result = executeAlgorithm(self.alg, parameters, context, feedback)
241243
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))))
244+
feedback.pushInfo(self.tr('Results:'))
245+
feedback.pushCommandInfo(pformat(result))
246+
feedback.pushInfo('')
243247

244248
self.buttonCancel.setEnabled(False)
245249
self.finish(result, context, feedback)
@@ -270,7 +274,7 @@ def finish(self, result, context, feedback):
270274
return
271275

272276
self.executed = True
273-
self.setInfo(self.tr('Algorithm {0} finished').format(self.alg.displayName()))
277+
self.setInfo(self.tr('Algorithm \'{0}\' finished').format(self.alg.displayName()), escape_html=False)
274278
QApplication.restoreOverrideCursor()
275279

276280
if not keepOpen:
@@ -280,4 +284,4 @@ def finish(self, result, context, feedback):
280284
if self.alg.hasHtmlOutputs():
281285
self.setInfo(
282286
self.tr('HTML output has been generated by this algorithm.'
283-
'\nOpen the results dialog to check it.'))
287+
'\nOpen the results dialog to check it.'), escape_html=False)

‎python/plugins/processing/gui/AlgorithmDialogBase.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

2929
import os
3030
import webbrowser
31+
import html
3132

3233
from qgis.PyQt import uic
3334
from qgis.PyQt.QtCore import Qt, QCoreApplication, QByteArray, QUrl
@@ -186,26 +187,28 @@ def resetGUI(self):
186187
self.btnRun.setEnabled(True)
187188
self.btnClose.setEnabled(True)
188189

189-
def setInfo(self, msg, error=False):
190+
def setInfo(self, msg, error=False, escape_html=True):
190191
if error:
191-
self.txtLog.append('<span style="color:red"><br>%s<br></span>' % msg)
192+
self.txtLog.append('<span style="color:red"><br>{}<br></span>'.format(msg, quote=False))
193+
elif escape_html:
194+
self.txtLog.append(html.escape(msg))
192195
else:
193196
self.txtLog.append(msg)
194197
QCoreApplication.processEvents()
195198

196199
def setCommand(self, cmd):
197200
if self.showDebug:
198-
self.setInfo('<code>%s<code>' % cmd)
201+
self.txtLog.append('<code>{}<code>'.format(html.escape(cmd, quote=False)))
199202
QCoreApplication.processEvents()
200203

201204
def setDebugInfo(self, msg):
202205
if self.showDebug:
203-
self.setInfo('<span style="color:blue">%s</span>' % msg)
206+
self.txtLog.append('<span style="color:blue">{}</span>'.format(html.escape(msg, quote=False)))
204207
QCoreApplication.processEvents()
205208

206209
def setConsoleInfo(self, msg):
207210
if self.showDebug:
208-
self.setCommand('<span style="color:darkgray">%s</span>' % msg)
211+
self.txtLog.append('<code><span style="color:darkgray">{}</span></code>'.format(html.escape(msg, quote=False)))
209212
QCoreApplication.processEvents()
210213

211214
def setPercentage(self, value):

‎python/plugins/processing/gui/BatchAlgorithmDialog.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,12 +126,12 @@ def accept(self):
126126

127127
for count, parameters in enumerate(self.alg_parameters):
128128
self.setText(self.tr('\nProcessing algorithm {0}/{1}...').format(count + 1, len(self.alg_parameters)))
129-
self.setInfo(self.tr('<b>Algorithm {0} starting...</b>').format(self.alg.displayName()))
129+
self.setInfo(self.tr('<b>Algorithm {0} starting...</b>').format(self.alg.displayName()), escape_html=False)
130130
ret, results = execute(self.alg, parameters, context, self.feedback)
131131
if ret and not self.canceled:
132132
if self.load[count]:
133133
handleAlgorithmResults(self.alg, context, self.feedback, False)
134-
self.setInfo(self.tr('Algorithm {0} correctly executed...').format(self.alg.displayName()))
134+
self.setInfo(self.tr('Algorithm {0} correctly executed...').format(self.alg.displayName()), escape_html=False)
135135
else:
136136
QApplication.restoreOverrideCursor()
137137
return

0 commit comments

Comments
 (0)
Please sign in to comment.