Skip to content

Commit 5a00912

Browse files
committedMay 20, 2015
[processing] more friendly error message when layers not created
This commit includes changes to the log system as well, which now logs only algorithms. Messages are logged to the QGIS logging system
1 parent 2e7f344 commit 5a00912

File tree

9 files changed

+35
-113
lines changed

9 files changed

+35
-113
lines changed
 

‎python/plugins/processing/ProcessingPlugin.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ def initGui(self):
8181

8282
self.historyAction = QAction(
8383
QIcon(os.path.join(cmd_folder, 'images', 'history.gif')),
84-
self.tr('&History and Log...'), self.iface.mainWindow())
84+
self.tr('&History...'), self.iface.mainWindow())
8585
self.historyAction.setObjectName('historyAction')
8686
self.historyAction.triggered.connect(self.openHistory)
8787
self.menu.addAction(self.historyAction)

‎python/plugins/processing/algs/grass/GrassAlgorithm.py

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -510,20 +510,3 @@ def checkParameterValuesBeforeExecuting(self):
510510
func = getattr(module, 'checkParameterValuesBeforeExecuting')
511511
return func(self)
512512

513-
def getPostProcessingErrorMessage(self, wrongLayers):
514-
html = GeoAlgorithm.getPostProcessingErrorMessage(self, wrongLayers)
515-
msg = GrassUtils.checkGrassIsInstalled(True)
516-
html += self.tr(
517-
'<p>This algorithm requires GRASS to be run. A test to check '
518-
'if GRASS is correctly installed and configured in your system '
519-
'has been performed, with the following result:</p><ul><i>')
520-
if msg is None:
521-
html += self.tr('GRASS seems to be correctly installed and '
522-
'configured</i></li></ul>')
523-
else:
524-
html += msg + '</i></li></ul>'
525-
html += self.tr(
526-
'<p><a href="http://docs.qgis.org/testing/en/docs/user_manual/processing/3rdParty.html">Click here</a> '
527-
'to know more about how to install and configure GRASS to be used with QGIS</p>')
528-
529-
return html

‎python/plugins/processing/algs/grass7/Grass7Algorithm.py

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -519,20 +519,3 @@ def checkParameterValuesBeforeExecuting(self):
519519
func = getattr(module, 'checkParameterValuesBeforeExecuting')
520520
return func(self)
521521

522-
def getPostProcessingErrorMessage(self, wrongLayers):
523-
html = GeoAlgorithm.getPostProcessingErrorMessage(self, wrongLayers)
524-
msg = Grass7Utils.checkGrass7IsInstalled(True)
525-
html += self.tr(
526-
'<p>This algorithm requires GRASS GIS 7 to be run. A test '
527-
'to check if GRASS GIS 7 is correctly installed and configured in '
528-
'your system has been performed, with the following result:</p><ul><i>')
529-
if msg is None:
530-
html += self.tr(
531-
'GRASS GIS 7 seems to be correctly installed and configured</i></li></ul>')
532-
else:
533-
html += msg + '</i></li></ul>'
534-
html += self.tr(
535-
'<p><a href="http://docs.qgis.org/testing/en/docs/user_manual/processing/3rdParty.html">Click here</a> '
536-
'to know more about how to install and configure GRASS GIS 7 to be used with QGIS</p>')
537-
538-
return html

‎python/plugins/processing/algs/r/RAlgorithm.py

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -415,27 +415,4 @@ def checkBeforeOpeningParametersDialog(self):
415415
'to know more about how to install and configure R to be used with QGIS</p>')
416416
return html
417417

418-
def getPostProcessingErrorMessage(self, wrongLayers):
419-
html = GeoAlgorithm.getPostProcessingErrorMessage(self, wrongLayers)
420-
msg = RUtils.checkRIsInstalled(True)
421-
html += self.tr(
422-
'<p>This algorithm requires R to be run. A test to check if '
423-
'R is correctly installed and configured in your system has '
424-
'been performed, with the following result:</p><ul><i>')
425-
if msg is None:
426-
html += self.tr(
427-
'R seems to be correctly installed and configured</i></li></ul>'
428-
'<p>The script you have executed needs the following packages:</p><ul>')
429-
packages = RUtils.getRequiredPackages(self.script)
430-
for p in packages:
431-
html += '<li>' + p + '</li>'
432-
html += self.tr(
433-
'</ul><p>Make sure they are installed in your R '
434-
'environment before trying to execute this script.</p>')
435-
else:
436-
html += msg + '</i></li></ul>'
437-
html += self.tr(
438-
'<p><a href= "http://docs.qgis.org/testing/en/docs/user_manual/processing/3rdParty.html">Click here</a> '
439-
'to know more about how to install and configure R to be used with QGIS</p>')
440418

441-
return html

‎python/plugins/processing/core/GeoAlgorithm.py

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -525,38 +525,6 @@ def getAsCommand(self):
525525
s = s[:-1] + ')'
526526
return s
527527

528-
def getPostProcessingErrorMessage(self, wrongLayers):
529-
"""Returns the message to be shown to the user when, after
530-
running this algorithm, there is a problem loading the
531-
resulting layer.
532-
533-
This method should analyze if the problem is caused by wrong
534-
entry data, a wrong or missing installation of a required 3rd
535-
party app, or any other cause, and create an error response
536-
accordingly.
537-
538-
Message is provided as an HTML code that will be displayed to
539-
the user, and which might contains links to installation paths
540-
for missing 3rd party apps.
541-
542-
- wrongLayers: a list of Output objects that could not be
543-
loaded.
544-
"""
545-
546-
html = self.tr('<p>Oooops! The following output layers could not be '
547-
'open</p><ul>\n')
548-
for layer in wrongLayers:
549-
html += self.tr('<li>%s: <font size=3 face="Courier New" '
550-
'color="#ff0000">%s</font></li>\n') % (
551-
layer.description, layer.value
552-
)
553-
html += self.tr('</ul><p>The above files could not be opened, which '
554-
'probably indicates that they were not correctly '
555-
'produced by the executed algorithm</p>'
556-
'<p>Checking the log information might help you see '
557-
'why those layers were not created as expected</p>')
558-
return html
559-
560528
def tr(self, string, context=''):
561529
if context == '':
562530
context = self.__class__.__name__

‎python/plugins/processing/core/ProcessingLog.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import datetime
3232
from processing.tools.system import userFolder
3333
from processing.core.ProcessingConfig import ProcessingConfig
34+
from qgis.core import *
3435

3536
class ProcessingLog:
3637

@@ -66,27 +67,29 @@ def addToLog(msgtype, msg):
6667
# added. To avoid it stopping the normal functioning of the
6768
# algorithm, we catch all errors, assuming that is better
6869
# to miss some log info that breaking the algorithm.
69-
if isinstance(msg, list):
70-
a = '|'.join(m.strip('\n') for m in msg)
71-
text = a
72-
else:
73-
text = msg.replace('\n', '|')
74-
line = msgtype + '|' + datetime.datetime.now().strftime(
75-
ProcessingLog.DATE_FORMAT).decode('utf-8') + '|' \
76-
+ text + '\n'
77-
logfile = codecs.open(ProcessingLog.logFilename(), 'a',
78-
encoding='utf-8')
79-
logfile.write(line)
80-
logfile.close()
8170
if msgtype == ProcessingLog.LOG_ALGORITHM:
82-
algname = text[len('Processing.runalg("'):]
71+
line = msgtype + '|' + datetime.datetime.now().strftime(
72+
ProcessingLog.DATE_FORMAT).decode('utf-8') + '|' \
73+
+ msg + '\n'
74+
logfile = codecs.open(ProcessingLog.logFilename(), 'a',
75+
encoding='utf-8')
76+
logfile.write(line)
77+
logfile.close()
78+
algname = msg[len('Processing.runalg("'):]
8379
algname = algname[:algname.index('"')]
8480
if algname not in ProcessingLog.recentAlgs:
8581
ProcessingLog.recentAlgs.append(algname)
8682
recentAlgsString = ';'.join(ProcessingLog.recentAlgs[-6:])
8783
ProcessingConfig.setSettingValue(
8884
ProcessingConfig.RECENT_ALGORITHMS,
8985
recentAlgsString)
86+
else:
87+
if isinstance(msg, list):
88+
msg = '\n'.join([m for m in msg])
89+
msgtypes = {ProcessingLog.LOG_ERROR: QgsMessageLog.CRITICAL,
90+
ProcessingLog.LOG_INFO: QgsMessageLog.INFO,
91+
ProcessingLog.LOG_WARNING: QgsMessageLog.WARNING,}
92+
QgsMessageLog.logMessage(msg, "Processing", msgtypes[msgtype])
9093
except:
9194
pass
9295

@@ -113,10 +116,7 @@ def getLogEntries():
113116
elif line.startswith(ProcessingLog.LOG_INFO):
114117
info.append(LogEntry(tokens[1], text))
115118

116-
entries[ProcessingLog.LOG_ERROR] = errors
117119
entries[ProcessingLog.LOG_ALGORITHM] = algorithms
118-
entries[ProcessingLog.LOG_INFO] = info
119-
entries[ProcessingLog.LOG_WARNING] = warnings
120120
return entries
121121

122122
@staticmethod

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,11 @@ def __init__(self):
5454
self.keyIcon.addPixmap(self.style().standardPixmap(QStyle.SP_FileIcon))
5555

5656
self.clearButton = QPushButton(self.tr('Clear'))
57-
self.clearButton.setToolTip(self.tr('Clear history and log'))
57+
self.clearButton.setToolTip(self.tr('Clear history'))
5858
self.buttonBox.addButton(self.clearButton, QDialogButtonBox.ActionRole)
5959

6060
self.saveButton = QPushButton(self.tr('Save As...'))
61-
self.saveButton.setToolTip(self.tr('Save history and log'))
61+
self.saveButton.setToolTip(self.tr('Save history'))
6262
self.buttonBox.addButton(self.saveButton, QDialogButtonBox.ActionRole)
6363

6464
self.tree.doubleClicked.connect(self.executeAlgorithm)
@@ -74,7 +74,7 @@ def __init__(self):
7474
def clearLog(self):
7575
reply = QMessageBox.question(self,
7676
self.tr('Confirmation'),
77-
self.tr('Are you sure you want to clear log?'),
77+
self.tr('Are you sure you want to clear the history?'),
7878
QMessageBox.Yes | QMessageBox.No,
7979
QMessageBox.No
8080
)
@@ -128,6 +128,7 @@ def createTest(self):
128128
TestTools.createTest(item.entry.text)
129129

130130
def showPopupMenu(self, point):
131+
return
131132
item = self.tree.currentItem()
132133
if isinstance(item, TreeLogEntryItem):
133134
if item.isAlg:

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@
2929

3030
from PyQt4 import uic
3131
from PyQt4.QtCore import QUrl
32-
from PyQt4.QtGui import QDesktopServices
32+
from PyQt4.QtGui import QDesktopServices, QDockWidget
33+
34+
from qgis.utils import iface
3335

3436
pluginPath = os.path.split(os.path.dirname(__file__))[0]
3537
WIDGET, BASE = uic.loadUiType(
@@ -51,4 +53,9 @@ def setMessage(self, message):
5153
self.txtMessage.setHtml(message)
5254

5355
def openLink(self, url):
54-
QDesktopServices.openUrl(QUrl(url))
56+
if url.toString() == "log":
57+
self.close()
58+
logDock = iface.mainWindow().findChild(QDockWidget, 'MessageLog')
59+
logDock.show()
60+
else:
61+
QDesktopServices.openUrl(url)

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ def handleAlgorithmResults(alg, progress=None, showResults=True):
7171
RenderingStyles.getStyle(alg.commandLineName(),
7272
out.name))
7373
except Exception, e:
74-
wrongLayers.append(out)
74+
wrongLayers.append(out.description)
7575
elif isinstance(out, OutputHTML):
7676
ProcessingResults.addResult(out.description, out.value)
7777
htmlResults = True
@@ -80,7 +80,10 @@ def handleAlgorithmResults(alg, progress=None, showResults=True):
8080
QApplication.restoreOverrideCursor()
8181
dlg = MessageDialog()
8282
dlg.setTitle(QCoreApplication.translate('Postprocessing', 'Problem loading output layers'))
83-
dlg.setMessage(alg.getPostProcessingErrorMessage(wrongLayers))
83+
msg = "The following layers were not correctly generated.<ul>"
84+
msg += "".join(["<li>%s</li>" % lay for lay in wrongLayers]) + "</ul>"
85+
msg += "You can check the <a href='log'>log messages</a> to find more information about the execution of the algorithm"
86+
dlg.setMessage(msg)
8487
dlg.exec_()
8588

8689
if showResults and htmlResults and not wrongLayers:

0 commit comments

Comments
 (0)
Please sign in to comment.