Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[processing] better error handling and some minor fixes
solved issue with trailing characters when calling mkdir
solved issue with non-ascii characters in help files
  • Loading branch information
volaya committed Sep 23, 2013
1 parent c55c2ab commit e4c60ad
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 24 deletions.
16 changes: 11 additions & 5 deletions python/plugins/processing/core/Processing.py
Expand Up @@ -16,6 +16,7 @@
* *
***************************************************************************
"""
import sys

__author__ = 'Victor Olaya'
__date__ = 'August 2012'
Expand Down Expand Up @@ -71,11 +72,16 @@ def addProvider(provider, updateList = False):
'''Adding a new provider automatically initializes it, so there is no need to do it in advance'''
#Note: this might slow down the initialization process if there are many new providers added.
#Should think of a different solution
provider.initializeSettings()
Processing.providers.append(provider)
ProcessingConfig.loadSettings()
if updateList:
Processing.updateAlgsList()
try:
provider.initializeSettings()
Processing.providers.append(provider)
ProcessingConfig.loadSettings()
if updateList:
Processing.updateAlgsList()
except:
ProcessingLog.addToLog(ProcessingLog.LOG_ERROR, "Could not load provider:"
+ provider.getDescription() + "\n" + sys.exc_info()[0])
Processing.removeProvider(provider)

@staticmethod
def removeProvider(provider):
Expand Down
25 changes: 11 additions & 14 deletions python/plugins/processing/gui/AlgorithmExecutionDialog.py
Expand Up @@ -96,7 +96,7 @@ def __init__(self, alg, mainWidget):
html = None
try:
if self.alg.helpFile():
helpFile = self.alg.helpFile()
helpFile = self.alg.helpFile()
else:
html = "<h2>Sorry, no help is available for this algorithm.</h2>"
except WrongHelpFileException, e:
Expand Down Expand Up @@ -249,8 +249,7 @@ def accept(self):
return
except:
QMessageBox.critical(self, "Unable to execute algorithm", "Wrong or missing parameter values")

@pyqtSlot()

def finish(self):
keepOpen = ProcessingConfig.getSetting(ProcessingConfig.KEEP_DIALOG_OPEN)
if self.iterateParam is None:
Expand All @@ -265,7 +264,7 @@ def finish(self):
if self.alg.getHTMLOutputsCount() > 0:
self.setInfo("HTML output has been generated by this algorithm.\nOpen the results dialog to check it.")

@pyqtSlot(str)

def error(self, msg):
QApplication.restoreOverrideCursor()
keepOpen = ProcessingConfig.getSetting(ProcessingConfig.KEEP_DIALOG_OPEN)
Expand All @@ -274,15 +273,14 @@ def error(self, msg):
QMessageBox.critical(self, "Error", msg)
self.close()
else:
self.resetGUI()
#self.setInfo(msg, True)
self.resetGUI()
self.tabWidget.setCurrentIndex(1) # log tab

@pyqtSlot(int)

def iterate(self, i):
self.setInfo("<b>Algorithm %s iteration #%i completed</b>" % (self.alg.name, i))

@pyqtSlot()

def cancel(self):
self.setInfo("<b>Algorithm %s canceled</b>" % self.alg.name)
try:
Expand All @@ -295,31 +293,30 @@ def cancel(self):
def resetGUI(self):
QApplication.restoreOverrideCursor()
self.progressLabel.setText("")
self.progress.setMaximum(100)
self.progress.setValue(0)
self.runButton.setEnabled(True)
self.buttonBox.button(QtGui.QDialogButtonBox.Close).setEnabled(True)
self.buttonBox.button(QtGui.QDialogButtonBox.Cancel).setEnabled(False)


@pyqtSlot(str)
@pyqtSlot(str, bool)

def setInfo(self, msg, error = False):
if error:
self.logText.append('<span style="color:red">' + msg + '</span>')
else:
self.logText.append(msg)

@pyqtSlot(str)

def setCommand(self, cmd):
if self.showDebug:
self.setInfo('<tt>' + cmd + '<tt>')

@pyqtSlot(str)

def setDebugInfo(self, msg):
if self.showDebug:
self.setInfo('<span style="color:blue">' + msg + '</span>')

@pyqtSlot(str)

def setConsoleInfo(self, msg):
if self.showDebug:
self.setCommand('<span style="color:darkgray">' + msg + '</span>')
Expand Down
7 changes: 5 additions & 2 deletions python/plugins/processing/gui/Help2Html.py
Expand Up @@ -26,6 +26,7 @@
import pickle
from processing.tools.system import *
import os
import codecs

class Help2Html():

Expand All @@ -39,7 +40,7 @@ def getHtmlFile(self, alg, helpFile):
self.alg = alg
f = open(helpFile, "rb")
self.descriptions = pickle.load(f)
s = "<h2>Algorithm description</h2>\n"
s = "<html><body><h2>Algorithm description</h2>\n"
s += "<p>" + self.getDescription(self.ALG_DESC) + "</p>\n"
s += "<h2>Input parameters</h2>\n"
for param in self.alg.parameters:
Expand All @@ -49,9 +50,11 @@ def getHtmlFile(self, alg, helpFile):
for out in self.alg.outputs:
s += "<h3>" + out.description + "</h3>\n"
s += "<p>" + self.getDescription(out.name) + "</p>\n"
s += "</body></html>"
filename = tempFolder() + os.sep + "temphelp.html"
tempHtml = open(filename, "w")
tempHtml = codecs.open(filename, "w", encoding = 'utf-8')
tempHtml.write(s)
tempHtml.close()

return filename

Expand Down
8 changes: 5 additions & 3 deletions python/plugins/processing/gui/UnthreadedAlgorithmExecutor.py
Expand Up @@ -46,12 +46,14 @@ def runalg(alg, progress):
return True
except GeoAlgorithmExecutionException, e :
ProcessingLog.addToLog(sys.exc_info()[0], ProcessingLog.LOG_ERROR)
QMessageBox.critical(None, "Error", e.msg)
progress.error(e.msg)
#QMessageBox.critical(None, "Error", e.msg)
return False
except Exception:
msg = "Error executing " + str(alg.name) + "\nSee log for more information"
msg = "Uncaught error executing " + str(alg.name) + "\nSee log for more information"
ProcessingLog.addToLog(sys.exc_info()[0], ProcessingLog.LOG_ERROR)
QMessageBox.critical(None, "Uncaught error", msg)
progress.error(e.msg)
#QMessageBox.critical(None, "Uncaught error", msg)
return False

@staticmethod
Expand Down
1 change: 1 addition & 0 deletions python/plugins/processing/tools/system.py
Expand Up @@ -85,6 +85,7 @@ def getNumExportedLayers():
return numExported

def mkdir(newdir):
newdir = newdir.strip("\n\r ")
if os.path.isdir(newdir):
pass
else:
Expand Down

0 comments on commit e4c60ad

Please sign in to comment.