Skip to content

Commit

Permalink
Merge pull request #2804 from Gustry/processing-error
Browse files Browse the repository at this point in the history
[Bugfix] [Processing] Catch some python errors in batch mode
  • Loading branch information
volaya committed Mar 3, 2016
2 parents 193fedf + 3039f13 commit b3b4101
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 24 deletions.
55 changes: 32 additions & 23 deletions python/plugins/processing/gui/BatchPanel.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

from PyQt4 import uic
from PyQt4.QtGui import (QWidget, QIcon, QTableWidgetItem, QComboBox, QLineEdit,
QHeaderView, QFileDialog)
QHeaderView, QFileDialog, QMessageBox)

from qgis.core import QgsApplication

Expand Down Expand Up @@ -184,30 +184,39 @@ def load(self):
if filename:
with open(filename) as f:
values = json.load(f)
else:
# If the user clicked on the cancel button.
return

self.tblParameters.setRowCount(0)
for row, alg in enumerate(values):
self.addRow()
params = alg[self.PARAMETERS]
outputs = alg[self.OUTPUTS]
column = 0
for param in self.alg.parameters:
if param.hidden:
continue
widget = self.tblParameters.cellWidget(row, column)
if param.name in params:
value = params[param.name]
self.setValueInWidget(widget, value)
column += 1

for out in self.alg.outputs:
if out.hidden:
continue
widget = self.tblParameters.cellWidget(row, column)
if out.name in outputs:
value = outputs[out.name]
self.setValueInWidget(widget, value)
column += 1
try:
for row, alg in enumerate(values):
self.addRow()
params = alg[self.PARAMETERS]
outputs = alg[self.OUTPUTS]
column = 0
for param in self.alg.parameters:
if param.hidden:
continue
widget = self.tblParameters.cellWidget(row, column)
if param.name in params:
value = params[param.name]
self.setValueInWidget(widget, value)
column += 1

for out in self.alg.outputs:
if out.hidden:
continue
widget = self.tblParameters.cellWidget(row, column)
if out.name in outputs:
value = outputs[out.name]
self.setValueInWidget(widget, value)
column += 1
except TypeError:
QMessageBox.critical(
self,
self.tr('Error'),
self.tr('An error occured while reading your file.'))

def setValueInWidget(self, widget, value):
if isinstance(widget, (BatchInputSelectionPanel, QLineEdit, FileSelectionPanel)):
Expand Down
4 changes: 3 additions & 1 deletion python/plugins/processing/modeler/ModelerAlgorithm.py
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,9 @@ def prepareAlgorithm(self, alg):
if not param.setValue(value) and not isinstance(param,
ParameterDataObject):
raise GeoAlgorithmExecutionException(
self.tr('Wrong value: %s', 'ModelerAlgorithm') % value)
self.tr('Wrong value %s for %s %s', 'ModelerAlgorithm')
% (value, param.__class__.__name__, param.name))

for out in algInstance.outputs:
if not out.hidden:
if out.name in alg.outputs:
Expand Down

0 comments on commit b3b4101

Please sign in to comment.