Skip to content

Commit

Permalink
Merge pull request #1389 from radosuav/small_processing_fixes
Browse files Browse the repository at this point in the history
[processing] Small fixes
  • Loading branch information
volaya committed Jun 12, 2014
2 parents fa88eb2 + 2ef7dcf commit 023fc00
Show file tree
Hide file tree
Showing 11 changed files with 110 additions and 44 deletions.
10 changes: 10 additions & 0 deletions python/plugins/processing/algs/grass/description/r.slope.txt
@@ -0,0 +1,10 @@
r.slope.aspect
r.slope - Generates raster maps of slope from a elevation raster map.
Raster (r.*)
ParameterRaster|elevation|Name of elevation raster map|False
ParameterSelection|format|Format for reporting the slope|degrees;percent
ParameterSelection|prec|Type of output aspect and slope maps|float;double;int
ParameterNumber|zfactor|Multiplicative factor to convert elevation units to meters|None|None|1.0
ParameterNumber|min_slp_allowed|Minimum slope val. (in percent) for which aspect is computed|None|None|0.0
ParameterBoolean|-a|Do not align the current region to the elevation layer|True
OutputRaster|slope|Name for output slope raster map
29 changes: 29 additions & 0 deletions python/plugins/processing/algs/otb/description/SplitImage.xml
@@ -0,0 +1,29 @@
<root>
<key>SplitImage</key>
<exec>otbcli_SplitImage</exec>
<longname>Split Image</longname>
<group>Image Manipulation</group>
<description>Rescale the image between two given values.</description>
<parameter>
<parameter_type source_parameter_type="ParameterType_InputImage">ParameterRaster</parameter_type>
<key>in</key>
<name>Input Image</name>
<description>Input image to be split into individual images.</description>
<optional>False</optional>
</parameter>
<parameter>
<parameter_type source_parameter_type="ParameterType_OutputImage">OutputFile</parameter_type>
<key>out</key>
<name>Output Image</name>
<description>The base filename of the split images.</description>
</parameter>
<parameter>
<parameter_type source_parameter_type="ParameterType_RAM">ParameterNumber</parameter_type>
<key>ram</key>
<name>Available RAM (Mb)</name>
<description>Available memory for processing (in MB)</description>
<minValue />
<maxValue />
<default>128</default>
</parameter>
</root>
2 changes: 1 addition & 1 deletion python/plugins/processing/algs/r/RAlgorithm.py
Expand Up @@ -239,7 +239,7 @@ def processAlgorithm(self, progress):
if self.showPlots:
htmlfilename = self.getOutputValue(RAlgorithm.RPLOTS)
f = open(htmlfilename, 'w')
f.write('<img src="' + self.plotsFilename + '"/>')
f.write('<html><img src="' + self.plotsFilename + '"/></html>')
f.close()
if self.showConsoleOutput:
htmlfilename = self.getOutputValue(RAlgorithm.R_CONSOLE_OUTPUT)
Expand Down
27 changes: 14 additions & 13 deletions python/plugins/processing/algs/r/RAlgorithmProvider.py
Expand Up @@ -88,16 +88,17 @@ def _loadAlgorithms(self):
def loadFromFolder(self, folder):
if not os.path.exists(folder):
return
for descriptionFile in os.listdir(folder):
if descriptionFile.endswith('rsx'):
try:
fullpath = os.path.join(folder, descriptionFile)
alg = RAlgorithm(fullpath)
if alg.name.strip() != '':
self.algs.append(alg)
except WrongScriptException, e:
ProcessingLog.addToLog(ProcessingLog.LOG_ERROR, e.msg)
except Exception, e:
ProcessingLog.addToLog(ProcessingLog.LOG_ERROR,
'Could not load R script:' + descriptionFile + '\n'
+ unicode(e))
for path, subdirs, files in os.walk(folder):
for descriptionFile in files:
if descriptionFile.endswith('rsx'):
try:
fullpath = os.path.join(path, descriptionFile)
alg = RAlgorithm(fullpath)
if alg.name.strip() != '':
self.algs.append(alg)
except WrongScriptException, e:
ProcessingLog.addToLog(ProcessingLog.LOG_ERROR, e.msg)
except Exception, e:
ProcessingLog.addToLog(ProcessingLog.LOG_ERROR,
'Could not load R script:' + descriptionFile + '\n'
+ unicode(e))
13 changes: 10 additions & 3 deletions python/plugins/processing/core/Processing.py
Expand Up @@ -65,6 +65,8 @@ class Processing:
listeners = []
providers = []

toolbox = None

# A dictionary of algorithms. Keys are names of providers
# and values are list with all algorithms from that provider
algs = {}
Expand All @@ -77,6 +79,10 @@ class Processing:

modeler = ModelerAlgorithmProvider()

@staticmethod
def setToolbox(toolbox):
Processing.toolbox = toolbox

@staticmethod
def addProvider(provider, updateList=False):
"""Use this method to add algorithms from external providers.
Expand All @@ -89,8 +95,8 @@ def addProvider(provider, updateList=False):
provider.initializeSettings()
Processing.providers.append(provider)
ProcessingConfig.readSettings()
if updateList:
Processing.updateAlgsList()
if updateList and Processing.toolbox:
Processing.toolbox.updateTree()
except:
ProcessingLog.addToLog(ProcessingLog.LOG_ERROR,
'Could not load provider:'
Expand All @@ -109,7 +115,8 @@ def removeProvider(provider):
provider.unload()
Processing.providers.remove(provider)
ProcessingConfig.readSettings()
Processing.updateAlgsList()
if Processing.toolbox:
Processing.toolbox.updateTree()
except:
# This try catch block is here to avoid problems if the
# plugin with a provider is unloaded after the Processing
Expand Down
5 changes: 5 additions & 0 deletions python/plugins/processing/gui/AlgorithmExecutionDialog.py
Expand Up @@ -248,6 +248,11 @@ def accept(self):
QApplication.setOverrideCursor(QCursor(Qt.WaitCursor))

self.setInfo('<b>Algorithm %s starting...</b>' % self.alg.name)
# make sure the log tab is visible before executing the algorithm
try:
self.repaint()
except:
pass
if self.iterateParam:
if UnthreadedAlgorithmExecutor.runalgIterating(self.alg,
self.iterateParam, self):
Expand Down
5 changes: 5 additions & 0 deletions python/plugins/processing/gui/BatchProcessingDialog.py
Expand Up @@ -200,6 +200,11 @@ def accept(self):
for (i, alg) in enumerate(self.algs):
self.setBaseText('Processing algorithm ' + str(i + 1) + '/'
+ str(len(self.algs)) + '...')
# make sure the log tab is visible before executing the algorithm
try:
self.repaint()
except:
pass
if UnthreadedAlgorithmExecutor.runalg(alg, self) \
and not self.canceled:
if self.load[i]:
Expand Down
1 change: 1 addition & 0 deletions python/plugins/processing/gui/ProcessingToolbox.py
Expand Up @@ -72,6 +72,7 @@ def __init__(self):
if hasattr(self.searchBox, 'setPlaceholderText'):
self.searchBox.setPlaceholderText(self.tr('Search...'))

Processing.setToolbox(self)
self.fillTree()

def textChanged(self):
Expand Down
27 changes: 14 additions & 13 deletions python/plugins/processing/modeler/ModelerAlgorithmProvider.py
Expand Up @@ -81,16 +81,17 @@ def _loadAlgorithms(self):
def loadFromFolder(self, folder):
if not os.path.exists(folder):
return
for descriptionFile in os.listdir(folder):
if descriptionFile.endswith('model'):
try:
alg = ModelerAlgorithm()
fullpath = os.path.join(folder, descriptionFile)
alg.openModel(fullpath)
if alg.name.strip() != '':
alg.provider = self
self.algs.append(alg)
except WrongModelException, e:
ProcessingLog.addToLog(ProcessingLog.LOG_ERROR,
'Could not load model ' + descriptionFile + '\n'
+ e.msg)
for path, subdirs, files in os.walk(folder):
for descriptionFile in files:
if descriptionFile.endswith('model'):
try:
alg = ModelerAlgorithm()
fullpath = os.path.join(path, descriptionFile)
alg.openModel(fullpath)
if alg.name.strip() != '':
alg.provider = self
self.algs.append(alg)
except WrongModelException, e:
ProcessingLog.addToLog(ProcessingLog.LOG_ERROR,
'Could not load model ' + descriptionFile + '\n'
+ e.msg)
8 changes: 7 additions & 1 deletion python/plugins/processing/outputs/OutputRaster.py
Expand Up @@ -35,7 +35,13 @@ class OutputRaster(Output):
compatible = None

def getFileFilter(self, alg):
exts = dataobjects.getSupportedOutputRasterLayerExtensions()
providerExts = alg.provider.getSupportedOutputRasterLayerExtensions()
if providerExts == ['tif']:
# use default extensions
exts = dataobjects.getSupportedOutputRasterLayerExtensions()
else:
# use extensions given by the algorithm provider
exts = providerExts
for i in range(len(exts)):
exts[i] = exts[i].upper() + ' files(*.' + exts[i].lower() + ')'
return ';;'.join(exts)
Expand Down
27 changes: 14 additions & 13 deletions python/plugins/processing/script/ScriptAlgorithmProvider.py
Expand Up @@ -83,16 +83,17 @@ def _loadAlgorithms(self):
def loadFromFolder(self, folder):
if not os.path.exists(folder):
return
for descriptionFile in os.listdir(folder):
if descriptionFile.endswith('py'):
try:
fullpath = os.path.join(folder, descriptionFile)
alg = ScriptAlgorithm(fullpath)
if alg.name.strip() != '':
self.algs.append(alg)
except WrongScriptException, e:
ProcessingLog.addToLog(ProcessingLog.LOG_ERROR, e.msg)
except Exception, e:
ProcessingLog.addToLog(ProcessingLog.LOG_ERROR,
'Could not load script:' + descriptionFile + '\n'
+ unicode(e))
for path, subdirs, files in os.walk(folder):
for descriptionFile in files:
if descriptionFile.endswith('py'):
try:
fullpath = os.path.join(path, descriptionFile)
alg = ScriptAlgorithm(fullpath)
if alg.name.strip() != '':
self.algs.append(alg)
except WrongScriptException, e:
ProcessingLog.addToLog(ProcessingLog.LOG_ERROR, e.msg)
except Exception, e:
ProcessingLog.addToLog(ProcessingLog.LOG_ERROR,
'Could not load script:' + descriptionFile + '\n'
+ unicode(e))

0 comments on commit 023fc00

Please sign in to comment.