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_()

13 changes: 7 additions & 6 deletions python/plugins/sextante/modeler/ModelerAlgorithm.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ def getCopy(self):
newone = ModelerAlgorithm()
newone.openModel(self.descriptionFile)
newone.provider = self.provider
newone.deactivated = self.deactivate
return newone

def __init__(self):
Expand Down Expand Up @@ -113,7 +114,7 @@ def openModel(self, filename):

self.descriptionFile = filename
lines = codecs.open(filename, "r", encoding='utf-8')
line = lines.readline().strip("\n")
line = lines.readline().strip("\n").strip("\r")
iAlg = 0
try:
while line != "":
Expand Down Expand Up @@ -141,11 +142,11 @@ def openModel(self, filename):
algLine = line[len("ALGORITHM:"):]
alg = ModelerUtils.getAlgorithm(algLine)
if alg is not None:
posline = lines.readline().strip("\n")
posline = lines.readline().strip("\n").strip("\r")
tokens = posline.split(",")
self.algPos.append(QtCore.QPointF(float(tokens[0]), float(tokens[1])))
self.algs.append(alg)
dependenceline = lines.readline().strip("\n")
dependenceline = lines.readline().strip("\n").strip("\r")
dependencies = [];
if dependenceline != str(None):
for index in dependenceline.split(","):
Expand All @@ -154,14 +155,14 @@ def openModel(self, filename):
except:
pass #a quick fix fwhile I figure out how to solve problems when parsing this
for param in alg.parameters:
line = lines.readline().strip("\n")
line = lines.readline().strip("\n").strip("\r")
if line==str(None):
algParams[param.name] = None
else:
tokens = line.split("|")
algParams[param.name] = AlgorithmAndParameter(int(tokens[0]), tokens[1])
for out in alg.outputs:
line = lines.readline().strip("\n")
line = lines.readline().strip("\n").strip("\r")
if str(None)!=line:
algOutputs[out.name] = line
#we add the output to the algorithm, with a name indicating where it comes from
Expand All @@ -178,7 +179,7 @@ def openModel(self, filename):
iAlg += 1
else:
raise WrongModelException("Error in algorithm name: " + algLine)
line = lines.readline().strip("\n")
line = lines.readline().strip("\n").strip("\r")
except Exception, e:
if isinstance (e, WrongModelException):
raise e
Expand Down
37 changes: 16 additions & 21 deletions python/plugins/sextante/modeler/ModelerDialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,11 @@ def __init__(self, alg=None):
self.openButton.setToolTip(self.tr("Open existing model"))
self.buttonBox.addButton(self.openButton, QDialogButtonBox.ActionRole)
self.saveButton = QPushButton(self.tr("Save"))
self.saveButton.setToolTip(self.tr("Save current model"))
self.saveButton.setToolTip(self.tr("Save current model"))
self.buttonBox.addButton(self.saveButton, QDialogButtonBox.ActionRole)
self.saveAsButton = QPushButton(self.tr("Save as ..."))
self.saveAsButton.setToolTip(self.tr("Save current model as"))
self.buttonBox.addButton(self.saveAsButton, QDialogButtonBox.ActionRole)

# fill trees with inputs and algorithms
self.fillInputsTree()
Expand All @@ -94,7 +97,8 @@ def __init__(self, alg=None):
self.algorithmTree.doubleClicked.connect(self.addAlgorithm)

self.openButton.clicked.connect(self.openModel)
self.saveButton.clicked.connect(self.saveModel)
self.saveButton.clicked.connect(self.save)
self.saveAsButton.clicked.connect(self.saveAs)
self.runButton.clicked.connect(self.runModel)
self.editHelpButton.clicked.connect(self.editHelp)

Expand All @@ -120,20 +124,6 @@ def editHelp(self):
if self.alg.descriptionFile is None and dlg.descriptions:
self.help = dlg.descriptions

#===========================================================================
# def createScript(self):
# if str(self.textGroup.text()).strip() == "":
# QMessageBox.warning(self, "Warning", "Please enter group name before saving")
# return
# filename = QtGui.QFileDialog.getSaveFileName(self, "Save Script", ScriptUtils.scriptsFolder(), "Python scripts (*.py)")
# if filename:
# fout = open(filename, "w")
# fout.write(str(self.textGroup.text()) + "=group")
# fout.write(self.alg.getAsPythonCode())
# fout.close()
# self.update = True
#===========================================================================

def runModel(self):
##TODO: enable alg cloning without saving to file
if self.alg.descriptionFile is None:
Expand All @@ -154,8 +144,14 @@ def runModel(self):
alg = self.alg.getCopy()
dlg = ParametersDialog(alg)
dlg.exec_()

def saveModel(self):

def save(self):
self.saveModel(False)

def saveAs(self):
self.saveModel(True)

def saveModel(self, saveAs):
if unicode(self.textGroup.text()).strip() == "" or unicode(self.textName.text()).strip() == "":
QMessageBox.warning(self,
self.tr("Warning"),
Expand All @@ -165,7 +161,7 @@ def saveModel(self):
self.alg.setPositions(self.scene.getParameterPositions(), self.scene.getAlgorithmPositions())
self.alg.name = unicode(self.textName.text())
self.alg.group = unicode(self.textGroup.text())
if self.alg.descriptionFile != None:
if self.alg.descriptionFile != None and not saveAs:
filename = self.alg.descriptionFile
else:
filename = unicode(QFileDialog.getSaveFileName(self, self.tr("Save Model"), ModelerUtils.modelsFolder(), self.tr("SEXTANTE models (*.model)")))
Expand Down Expand Up @@ -214,8 +210,7 @@ def repaintModel(self):
self.scene = ModelerScene()
self.scene.setSceneRect(QRectF(0, 0, ModelerAlgorithm.CANVAS_SIZE, ModelerAlgorithm.CANVAS_SIZE))
self.scene.paintModel(self.alg)
self.view.setScene(self.scene)
#self.pythonText.setText(self.alg.getAsPythonCode())
self.view.setScene(self.scene)

def addInput(self):
item = self.inputsTree.currentItem()
Expand Down
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)
Loading