Skip to content

Commit

Permalink
Nicer formatting for log in algorithm dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Jun 11, 2017
1 parent 29f50b7 commit b40f409
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 12 deletions.
14 changes: 9 additions & 5 deletions python/plugins/processing/gui/AlgorithmDialog.py
Expand Up @@ -220,9 +220,11 @@ def accept(self):
QApplication.setOverrideCursor(QCursor(Qt.WaitCursor))

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

feedback.pushInfo(self.tr('Input parameters:\n{}\n'.format(pformat(parameters))))
feedback.pushInfo(self.tr('Input parameters:'))
feedback.pushCommandInfo(pformat(parameters))
feedback.pushInfo('')
start_time = time.time()

if self.iterateParam:
Expand All @@ -239,7 +241,9 @@ def accept(self):
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))))
feedback.pushInfo(self.tr('Results:'))
feedback.pushCommandInfo(pformat(result))
feedback.pushInfo('')

self.buttonCancel.setEnabled(False)
self.finish(result, context, feedback)
Expand Down Expand Up @@ -270,7 +274,7 @@ def finish(self, result, context, feedback):
return

self.executed = True
self.setInfo(self.tr('Algorithm {0} finished').format(self.alg.displayName()))
self.setInfo(self.tr('Algorithm \'{0}\' finished').format(self.alg.displayName()), escape_html=False)
QApplication.restoreOverrideCursor()

if not keepOpen:
Expand All @@ -280,4 +284,4 @@ def finish(self, result, context, feedback):
if self.alg.hasHtmlOutputs():
self.setInfo(
self.tr('HTML output has been generated by this algorithm.'
'\nOpen the results dialog to check it.'))
'\nOpen the results dialog to check it.'), escape_html=False)
13 changes: 8 additions & 5 deletions python/plugins/processing/gui/AlgorithmDialogBase.py
Expand Up @@ -28,6 +28,7 @@

import os
import webbrowser
import html

from qgis.PyQt import uic
from qgis.PyQt.QtCore import Qt, QCoreApplication, QByteArray, QUrl
Expand Down Expand Up @@ -186,26 +187,28 @@ def resetGUI(self):
self.btnRun.setEnabled(True)
self.btnClose.setEnabled(True)

def setInfo(self, msg, error=False):
def setInfo(self, msg, error=False, escape_html=True):
if error:
self.txtLog.append('<span style="color:red"><br>%s<br></span>' % msg)
self.txtLog.append('<span style="color:red"><br>{}<br></span>'.format(msg, quote=False))
elif escape_html:
self.txtLog.append(html.escape(msg))
else:
self.txtLog.append(msg)
QCoreApplication.processEvents()

def setCommand(self, cmd):
if self.showDebug:
self.setInfo('<code>%s<code>' % cmd)
self.txtLog.append('<code>{}<code>'.format(html.escape(cmd, quote=False)))
QCoreApplication.processEvents()

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

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

def setPercentage(self, value):
Expand Down
4 changes: 2 additions & 2 deletions python/plugins/processing/gui/BatchAlgorithmDialog.py
Expand Up @@ -126,12 +126,12 @@ def accept(self):

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

0 comments on commit b40f409

Please sign in to comment.