Skip to content

Commit

Permalink
[processing] i18n support for SAGA provider
Browse files Browse the repository at this point in the history
  • Loading branch information
alexbruy committed Jan 17, 2015
1 parent e1d8710 commit 07462f5
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 46 deletions.
22 changes: 9 additions & 13 deletions python/plugins/processing/algs/saga/SagaAlgorithm212.py
Expand Up @@ -125,7 +125,7 @@ def processAlgorithm(self, progress):
self.exportedLayers[param.value] = filename
elif not param.value.endswith('shp'):
raise GeoAlgorithmExecutionException(
'Unsupported file format')
self.tr('Unsupported file format'))
if isinstance(param, ParameterTable):
if param.value is None:
continue
Expand All @@ -135,7 +135,7 @@ def processAlgorithm(self, progress):
self.exportedLayers[param.value] = filename
elif not param.value.endswith('shp'):
raise GeoAlgorithmExecutionException(
'Unsupported file format')
self.tr('Unsupported file format'))
if isinstance(param, ParameterMultipleInput):
if param.value is None:
continue
Expand All @@ -156,7 +156,7 @@ def processAlgorithm(self, progress):
self.exportedLayers[layerfile] = filename
elif not layerfile.endswith('shp'):
raise GeoAlgorithmExecutionException(
'Unsupported file format')
self.tr('Unsupported file format'))

# 2: Set parameters and outputs
command = self.undecoratedGroup + ' "' + self.cmdname + '"'
Expand Down Expand Up @@ -246,8 +246,8 @@ def processAlgorithm(self, progress):

if self.cmdname == 'RGB Composite':
commands.append('io_grid_image 0 -IS_RGB -GRID:"' + filename2
+ '" -FILE:"' + filename
+ '"')
+ '" -FILE:"' + filename
+ '"')
else:
commands.append('io_gdal 1 -GRIDS "' + filename2
+ '" -FORMAT ' + str(formatIndex)
Expand All @@ -258,7 +258,7 @@ def processAlgorithm(self, progress):
commands = self.editCommands(commands)
SagaUtils.createSagaBatchJobFileFromSagaCommands(commands)
loglines = []
loglines.append('SAGA execution commands')
loglines.append(self.tr('SAGA execution commands'))
for line in commands:
progress.setCommand(line)
loglines.append(line)
Expand Down Expand Up @@ -340,18 +340,15 @@ def checkParameterValuesBeforeExecuting(self):
if layer is None:
continue
if layer.bandCount() > 1:
return 'Input layer ' + str(layer.name()) \
+ ' has more than one band.\n' \
+ 'Multiband layers are not supported by SAGA'
return self.tr('Input layer %s has more than one band.\n'
'Multiband layers are not supported by SAGA' % str(layer.name()))
if not self.allowUnmatchingGridExtents:
if extent is None:
extent = (layer.extent(), layer.height(), layer.width())
else:
extent2 = (layer.extent(), layer.height(), layer.width())
if extent != extent2:
return "Input layers do not have the same grid extent."


return self.tr("Input layers do not have the same grid extent.")

def help(self):
name = self.cmdname.lower()
Expand All @@ -364,4 +361,3 @@ def help(self):
imgpath = os.path.join(os.path.dirname(__file__),os.pardir, os.pardir, 'images', 'saga100x100.jpg')
html = ('<img src="%s"/>' % imgpath) + html
return True, html

18 changes: 6 additions & 12 deletions python/plugins/processing/algs/saga/SagaAlgorithm213.py
Expand Up @@ -79,7 +79,7 @@ def processAlgorithm(self, progress):
self.exportedLayers[param.value] = filename
elif not param.value.endswith('shp'):
raise GeoAlgorithmExecutionException(
'Unsupported file format')
self.tr('Unsupported file format'))
if isinstance(param, ParameterTable):
if param.value is None:
continue
Expand All @@ -89,7 +89,7 @@ def processAlgorithm(self, progress):
self.exportedLayers[param.value] = filename
elif not param.value.endswith('shp'):
raise GeoAlgorithmExecutionException(
'Unsupported file format')
self.tr('Unsupported file format'))
if isinstance(param, ParameterMultipleInput):
if param.value is None:
continue
Expand All @@ -110,7 +110,7 @@ def processAlgorithm(self, progress):
self.exportedLayers[layerfile] = filename
elif not layerfile.endswith('shp'):
raise GeoAlgorithmExecutionException(
'Unsupported file format')
self.tr('Unsupported file format'))

# 2: Set parameters and outputs
command = self.undecoratedGroup + ' "' + self.cmdname + '"'
Expand Down Expand Up @@ -202,8 +202,8 @@ def processAlgorithm(self, progress):

if self.cmdname == 'RGB Composite':
commands.append('io_grid_image 0 -IS_RGB -GRID:"' + filename2
+ '" -FILE:"' + filename
+ '"')
+ '" -FILE:"' + filename
+ '"')
else:
commands.append('io_gdal 1 -GRIDS "' + filename2
+ '" -FORMAT ' + str(formatIndex)
Expand All @@ -214,15 +214,14 @@ def processAlgorithm(self, progress):
commands = self.editCommands(commands)
SagaUtils.createSagaBatchJobFileFromSagaCommands(commands)
loglines = []
loglines.append('SAGA execution commands')
loglines.append(self.tr('SAGA execution commands'))
for line in commands:
progress.setCommand(line)
loglines.append(line)
if ProcessingConfig.getSetting(SagaUtils.SAGA_LOG_COMMANDS):
ProcessingLog.addToLog(ProcessingLog.LOG_INFO, loglines)
SagaUtils.executeSaga(progress)


def exportRasterLayer(self, source):
global sessionExportedLayers
if source in sessionExportedLayers:
Expand All @@ -242,8 +241,3 @@ def exportRasterLayer(self, source):
self.exportedLayers[source] = destFilename
sessionExportedLayers[source] = destFilename
return 'io_gdal 0 -TRANSFORM -INTERPOL 0 -GRIDS "' + destFilename + '" -FILES "' + source + '"'





26 changes: 11 additions & 15 deletions python/plugins/processing/algs/saga/SagaAlgorithmProvider.py
Expand Up @@ -51,17 +51,16 @@ def initializeSettings(self):
AlgorithmProvider.initializeSettings(self)
if isWindows() or isMac():
ProcessingConfig.addSetting(Setting("SAGA",
SagaUtils.SAGA_FOLDER, 'SAGA folder', ''))
SagaUtils.SAGA_FOLDER, self.tr('SAGA folder'), ''))
ProcessingConfig.addSetting(Setting("SAGA",
SagaUtils.SAGA_IMPORT_EXPORT_OPTIMIZATION,
'Enable SAGA Import/Export optimizations',
False))
SagaUtils.SAGA_IMPORT_EXPORT_OPTIMIZATION,
self.tr('Enable SAGA Import/Export optimizations'), False))
ProcessingConfig.addSetting(Setting("SAGA",
SagaUtils.SAGA_LOG_COMMANDS,
'Log execution commands', True))
SagaUtils.SAGA_LOG_COMMANDS,
self.tr('Log execution commands'), True))
ProcessingConfig.addSetting(Setting("SAGA",
SagaUtils.SAGA_LOG_CONSOLE,
'Log console output', True))
SagaUtils.SAGA_LOG_CONSOLE,
self.tr('Log console output'), True))

def unload(self):
AlgorithmProvider.unload(self)
Expand All @@ -71,17 +70,16 @@ def unload(self):
ProcessingConfig.removeSetting(SagaUtils.SAGA_LOG_CONSOLE)
ProcessingConfig.removeSetting(SagaUtils.SAGA_LOG_COMMANDS)


def _loadAlgorithms(self):
self.algs = []
version = SagaUtils.getSagaInstalledVersion(True)
if version is None:
ProcessingLog.addToLog(ProcessingLog.LOG_ERROR,
'Problem with SAGA installation: SAGA was not found or is not correctly installed')
self.tr('Problem with SAGA installation: SAGA was not found or is not correctly installed'))
return
if version not in self.supportedVersions:
ProcessingLog.addToLog(ProcessingLog.LOG_ERROR,
'Problem with SAGA installation: installed SAGA version (%s) is not supported' % version)
self.tr('Problem with SAGA installation: installed SAGA version (%s) is not supported' % version))
return

folder = SagaUtils.sagaDescriptionPath()
Expand All @@ -99,12 +97,10 @@ def _loadAlgorithm(self, descriptionFile):
self.algs.append(alg)
else:
ProcessingLog.addToLog(ProcessingLog.LOG_ERROR,
'Could not open SAGA algorithm: '
+ descriptionFile)
self.tr('Could not open SAGA algorithm: %s' % descriptionFile))
except Exception, e:
ProcessingLog.addToLog(ProcessingLog.LOG_ERROR,
'Could not open SAGA algorithm: '
+ descriptionFile + '\n' + str(e))
self.tr('Could not open SAGA algorithm: %s\n%s' % (descriptionFile, str(e))))
def getDescription(self):
return 'SAGA (%s)' % SagaUtils.getSagaInstalledVersion()

Expand Down
2 changes: 1 addition & 1 deletion python/plugins/processing/algs/saga/SagaUtils.py
Expand Up @@ -137,7 +137,7 @@ def executeSaga(progress):
| stat.S_IREAD | stat.S_IWRITE)
command = [sagaBatchJobFilename()]
loglines = []
loglines.append('SAGA execution console output')
loglines.append(QCoreApplication.translate('SagaUtils', 'SAGA execution console output'))
proc = subprocess.Popen(
command,
shell=True,
Expand Down
13 changes: 8 additions & 5 deletions python/plugins/processing/algs/saga/SplitRGBBands.py
Expand Up @@ -47,11 +47,14 @@ def getIcon(self):
def defineCharacteristics(self):
self.name = 'Split RGB bands'
self.group = 'Grid - Tools'
self.addParameter(ParameterRaster(SplitRGBBands.INPUT, 'Input layer',
False))
self.addOutput(OutputRaster(SplitRGBBands.R, 'Output R band layer'))
self.addOutput(OutputRaster(SplitRGBBands.G, 'Output G band layer'))
self.addOutput(OutputRaster(SplitRGBBands.B, 'Output B band layer'))
self.addParameter(ParameterRaster(SplitRGBBands.INPUT,
self.tr('Input layer'), False))
self.addOutput(OutputRaster(SplitRGBBands.R,
self.tr('Output R band layer')))
self.addOutput(OutputRaster(SplitRGBBands.G,
self.tr('Output G band layer')))
self.addOutput(OutputRaster(SplitRGBBands.B,
self.tr('Output B band layer')))

def processAlgorithm(self, progress):
# TODO: check correct num of bands
Expand Down

0 comments on commit 07462f5

Please sign in to comment.