Skip to content

Commit

Permalink
[sextante] improved error messages when algorithm execution fails
Browse files Browse the repository at this point in the history
  • Loading branch information
volaya committed Mar 30, 2013
1 parent 7e30da2 commit d48efd8
Show file tree
Hide file tree
Showing 5 changed files with 116 additions and 38 deletions.
17 changes: 16 additions & 1 deletion python/plugins/sextante/core/AlgorithmProvider.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,22 @@ def getDescription(self):
'''Returns the full name of the provider'''
return "Generic algorithm provider"


def getPostProcessingErrorMessage(self, wrongLayers):
'''Returns the message to be shown to the user when after running an algorithm for this provider,
there is a problem loading the resulting layer.
This method should analyze if the problem is caused by wrong entry data, a wrong or missing
installation of a required 3rd party app, or any other cause, and create an error response accordingly.
Message is provided as an HTML code that will be displayed to the user, and which might contains
links to installation paths for missing 3rd party apps.
- wrongLayers: a list of Output objects that could not be loaded.'''

html ="<p>Oooops! SEXTANTE could not open the following output layers</p><ul>\n"
for layer in wrongLayers:
html += '<li>' + layer.description + ': <font size=3 face="Courier New" color="ff0000">' + layer.value + "</font></li>\n"
html +="</ul><p>The above files could not be opened, which probably indicates that they were not correctly produced by the executed algorithm</p>"
html +="<p>Checking the log information might help you see why those layers were not created as expected</p>"
return html

def getIcon(self):
return QtGui.QIcon(os.path.dirname(__file__) + "/../images/alg.png")

Expand Down
59 changes: 59 additions & 0 deletions python/plugins/sextante/gui/CouldNotLoadResultsDialog.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# -*- coding: utf-8 -*-

"""
***************************************************************************
CouldNotLoadResultsDialog.py
---------------------
Date : August 2012
Copyright : (C) 2012 by Victor Olaya
Email : volayaf at gmail dot com
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************
"""
import webbrowser

__author__ = 'Victor Olaya'
__date__ = 'August 2012'
__copyright__ = '(C) 2012, Victor Olaya'
# This will get replaced with a git SHA1 when you do a git archive
__revision__ = '$Format:%H$'

from PyQt4 import QtCore, QtGui, QtWebKit
from PyQt4.QtCore import *
from PyQt4.QtGui import *

class CouldNotLoadResultsDialog(QtGui.QDialog):
def __init__(self, wrongLayers, alg):
QtGui.QDialog.__init__(self, None, QtCore.Qt.WindowSystemMenuHint | QtCore.Qt.WindowTitleHint)
self.alg = alg
self.wrongLayers = wrongLayers
self.setupUi()

def setupUi(self):
self.resize(800,400)
self.setWindowTitle("Problem loading output layers")
layout = QVBoxLayout()
webView = QtWebKit.QWebView()
webView.page().setLinkDelegationPolicy(QtWebKit.QWebPage.DelegateAllLinks)
webView.connect(webView, SIGNAL("linkClicked(const QUrl&)"), self.linkClicked)
html = self.alg.provider.getPostProcessingErrorMessage(self.wrongLayers)
webView.setHtml(html)
closeButton = QtGui.QPushButton()
closeButton.setText("Close")
QObject.connect(closeButton, QtCore.SIGNAL("clicked()"), self.closeButtonPressed)
layout.addWidget(webView)
layout.addWidget(closeButton)
self.setLayout(layout)
QtCore.QMetaObject.connectSlotsByName(self)

def linkClicked(self, url):
webbrowser.open(str(url.toString()))

def closeButtonPressed(self):
self.close()
20 changes: 15 additions & 5 deletions python/plugins/sextante/gui/SextantePostprocessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
# This will get replaced with a git SHA1 when you do a git archive
__revision__ = '$Format:%H$'

import os
from PyQt4.QtGui import *
from qgis.core import *
from sextante.core.QGisLayers import QGisLayers
from sextante.outputs.OutputRaster import OutputRaster
from sextante.outputs.OutputVector import OutputVector
Expand All @@ -31,14 +34,14 @@
from sextante.gui.ResultsDialog import ResultsDialog
from sextante.gui.RenderingStyles import RenderingStyles
from sextante.outputs.OutputHTML import OutputHTML
from PyQt4.QtGui import *
from qgis.core import *
from sextante.gui.CouldNotLoadResultsDialog import CouldNotLoadResultsDialog
from sextante.core.SextanteConfig import SextanteConfig
import os

class SextantePostprocessing:

@staticmethod
def handleAlgorithmResults(alg, progress, showResults = True):
wrongLayers = []
htmlResults = False;
progress.setText("Loading resulting layers")
i = 0
Expand All @@ -58,12 +61,19 @@ def handleAlgorithmResults(alg, progress, showResults = True):
name = out.description
QGisLayers.load(out.value, name, alg.crs, RenderingStyles.getStyle(alg.commandLineName(),out.name))
except Exception, e:
QMessageBox.critical(None, "Error", str(e))
wrongLayers.append(out)
#QMessageBox.critical(None, "Error", str(e))
elif isinstance(out, OutputHTML):
SextanteResults.addResult(out.description, out.value)
htmlResults = True
i += 1
if showResults and htmlResults:
if wrongLayers:
QApplication.restoreOverrideCursor()
dlg = CouldNotLoadResultsDialog(wrongLayers, alg)
dlg.exec_()

if showResults and htmlResults and not wrongLayers:
QApplication.restoreOverrideCursor()
dlg = ResultsDialog()
dlg.exec_()

21 changes: 17 additions & 4 deletions python/plugins/sextante/saga/SagaAlgorithmProvider.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
* *
***************************************************************************
"""
from sextante.saga.SplitRGBBands import SplitRGBBands

__author__ = 'Victor Olaya'
__date__ = 'August 2012'
Expand All @@ -25,10 +24,11 @@
__revision__ = '$Format:%H$'

import os
from sextante.saga.SagaAlgorithm import SagaAlgorithm
from sextante.saga.SagaUtils import SagaUtils
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from sextante.saga.SagaAlgorithm import SagaAlgorithm
from sextante.saga.SplitRGBBands import SplitRGBBands
from sextante.saga.SagaUtils import SagaUtils
from sextante.core.SextanteConfig import SextanteConfig, Setting
from sextante.core.AlgorithmProvider import AlgorithmProvider
from sextante.core.SextanteLog import SextanteLog
Expand Down Expand Up @@ -91,7 +91,20 @@ def getDescription(self):

def getName(self):
return "saga"


def getPostProcessingErrorMessage(self, wrongLayers):
html = AlgorithmProvider.getPostProcessingErrorMessage(self, wrongLayers)
msg = SagaUtils.checkSagaIsInstalled(True)
html += ("<p>This algorithm requires SAGA to be run. A test to check if SAGA is correctly installed "
"and configured in your system has been performed, with the following result:</p><ul><i>")
if msg is None:
html += "Saga seems to be correctly installed and configured</li></ul>"
else:
html += msg + "</i></li></ul>"
html += '<p><a href= "http://docs.qgis.org/html/en/docs/user_manual/sextante/3rdParty.html">Click here</a> to know more about how to install and configure SAGA to be used with SEXTANTE</p>'

return html

def getSupportedOutputVectorLayerExtensions(self):
return ["shp"]

Expand Down
37 changes: 9 additions & 28 deletions python/plugins/sextante/saga/SagaUtils.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,8 @@ def executeSaga(progress):
SextanteLog.addToLog(SextanteLog.LOG_INFO, loglines)


@classmethod
def checkSagaIsInstalled(cls):
@staticmethod
def checkSagaIsInstalled(ignoreRegistrySettings=False):
if SextanteUtils.isWindows():
path = SagaUtils.sagaPath()
if path == "":
Expand All @@ -127,31 +127,13 @@ def checkSagaIsInstalled(cls):
+ "Please, go to the SEXTANTE settings dialog, and check that the SAGA\n"
+ "folder is correctly configured")

SAGA_INSTALLED = "/SextanteQGIS/SagaInstalled"
settings = QSettings()
if settings.contains(SAGA_INSTALLED):
return

try:
#===================================================================
# qgis = QGisLayers.iface
# crs = qgis.mapCanvas().mapRenderer().destinationCrs()
# fields = []
# fields.append(QgsField("NUM_FIELD", QVariant.Int))
# filename = SextanteUtils.getTempFilename("shp")
# writer = SextanteVectorWriter(filename, None, fields, QGis.WKBPoint, crs)
# for x in range(5):
# for y in range(5):
# attrs = []
# attrs.append(QVariant(x))
# outFeat = QgsFeature()
# pt = QgsPoint(x, y)
# outFeat.setGeometry(QgsGeometry.fromPoint(pt))
# outFeat.setAttributes(attrs)
# writer.addFeature(outFeat)
# del writer.writer
# del writer
#===================================================================
if not ignoreRegistrySettings:
SAGA_INSTALLED = "/SextanteQGIS/SagaInstalled"
settings = QSettings()
if settings.contains(SAGA_INSTALLED):
return

try:
from sextante.core.Sextante import runalg
result = runalg("saga:thiessenpolygons", points(), None)
if not os.path.exists(result['POLYGONS']):
Expand All @@ -160,5 +142,4 @@ def checkSagaIsInstalled(cls):
s = traceback.format_exc()
return "Error while checking SAGA installation. SAGA might not be correctly configured.\n" + s;


settings.setValue("/SextanteQGIS/SagaInstalled", True)

0 comments on commit d48efd8

Please sign in to comment.