8 changes: 5 additions & 3 deletions python/plugins/processing/algs/FieldsCalculator.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
from processing.parameters.ParameterBoolean import ParameterBoolean
from processing.parameters.ParameterSelection import ParameterSelection
from processing.outputs.OutputVector import OutputVector
from processing.tools import dataobjects, vector
from processing.tools import dataobjects, vector, system

from processing.algs.ui.FieldsCalculatorDialog import FieldsCalculatorDialog

Expand Down Expand Up @@ -85,6 +85,10 @@ def processAlgorithm(self, progress):

output = self.getOutputFromName(self.OUTPUT_LAYER)

if output.value == '':
ext = output.getDefaultFileExtension(self)
output.value = system.getTempFilenameInTempFolder(output.name + '.' + ext)

provider = layer.dataProvider()
fields = layer.pendingFields()
if newField:
Expand Down Expand Up @@ -143,7 +147,6 @@ def processAlgorithm(self, progress):
'An error occured while evaluating the calculation '
'string:\n' + error)


def checkParameterValuesBeforeExecuting(self):
newField = self.getParameterValue(self.NEW_FIELD)
fieldName = self.getParameterValue(self.FIELD_NAME)
Expand All @@ -156,6 +159,5 @@ def checkParameterValuesBeforeExecuting(self):
raise GeoAlgorithmExecutionException('Output is not set. '
'Please specify valid filename')


def getCustomParametersDialog(self):
return FieldsCalculatorDialog(self)
4 changes: 4 additions & 0 deletions python/plugins/processing/algs/ui/FieldsCalculatorDialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ def __init__(self, alg):
self.manageGui()

def manageGui(self):
if hasattr(self.leOutputFile, 'setPlaceholderText'):
self.leOutputFile.setPlaceholderText(
self.tr('[Save to temporary file]'))

self.mOutputFieldTypeComboBox.blockSignals(True)
for t in self.alg.TYPE_NAMES:
self.mOutputFieldTypeComboBox.addItem(t)
Expand Down
13 changes: 7 additions & 6 deletions python/plugins/processing/grass/GrassUtils.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

import stat
import shutil
import codecs
import traceback
import subprocess
from qgis.core import QgsApplication
Expand Down Expand Up @@ -123,7 +124,7 @@ def createGrassScript(commands):
gisrc = userFolder() + os.sep + 'processing.gisrc'

# Temporary gisrc file
output = open(gisrc, 'w')
output = codecs.open(gisrc, 'w', encoding='utf-8')
location = 'temp_location'
gisdbase = GrassUtils.grassDataFolder()

Expand All @@ -133,7 +134,7 @@ def createGrassScript(commands):
output.write('GRASS_GUI: text\n')
output.close()

output = open(script, 'w')
output = codecs.open(script, 'w', encoding='utf-8')
output.write('set HOME=' + os.path.expanduser('~') + '\n')
output.write('set GISRC=' + gisrc + '\n')
output.write('set GRASS_SH=' + shell + '\\bin\\sh.exe\n')
Expand Down Expand Up @@ -171,7 +172,7 @@ def createGrassScript(commands):

@staticmethod
def createGrassBatchJobFileFromGrassCommands(commands):
fout = open(GrassUtils.grassBatchJobFilename(), 'w')
fout = codecs.open(GrassUtils.grassBatchJobFilename(), 'w', encoding='utf-8')
for command in commands:
fout.write(command + '\n')
fout.write('exit')
Expand Down Expand Up @@ -204,20 +205,20 @@ def createTempMapset():
mkdir(os.path.join(folder, 'PERMANENT', '.tmp'))
GrassUtils.writeGrassWindow(os.path.join(folder, 'PERMANENT',
'DEFAULT_WIND'))
outfile = open(os.path.join(folder, 'PERMANENT', 'MYNAME'), 'w')
outfile = codecs.open(os.path.join(folder, 'PERMANENT', 'MYNAME'), 'w', encoding='utf-8')
outfile.write(
'QGIS GRASS interface: temporary data processing location.\n')
outfile.close()
GrassUtils.writeGrassWindow(os.path.join(folder, 'PERMANENT', 'WIND'))
mkdir(os.path.join(folder, 'PERMANENT', 'dbf'))
outfile = open(os.path.join(folder, 'PERMANENT', 'VAR'), 'w')
outfile = codecs.open(os.path.join(folder, 'PERMANENT', 'VAR'), 'w', encoding='utf-8')
outfile.write('DB_DRIVER: dbf\n')
outfile.write('DB_DATABASE: $GISDBASE/$LOCATION_NAME/$MAPSET/dbf/\n')
outfile.close()

@staticmethod
def writeGrassWindow(filename):
out = open(filename, 'w')
out = codecs.open(filename, 'w', encoding='utf-8')
out.write('proj: 0\n')
out.write('zone: 0\n')
out.write('north: 1\n')
Expand Down
22 changes: 11 additions & 11 deletions python/plugins/processing/otb/OTBAlgorithm.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ def __init__(self, descriptionfile):
self.defineCharacteristicsFromFile()
self.numExportedLayers = 0
self.hasROI = None;


def __str__(self):
return( "Algo : " + self.name + " from app : " + self.cliName + " in : " + self.group )

Expand Down Expand Up @@ -114,7 +114,7 @@ def get_list_from_node(self, myet):
rebuild.append(name)
for each in parameter[4:]:
if not each.tag in ["hidden"]:
if len(each.getchildren()) == 0:
if len(list(each)) == 0:
rebuild.append(each.text)
else:
rebuild.append([item.text for item in each.iter('choice')])
Expand All @@ -131,7 +131,7 @@ def defineCharacteristicsFromFile(self):
self.name = dom_model.find('longname').text
self.group = dom_model.find('group').text

ProcessingLog.addToLog(ProcessingLog.LOG_ERROR, "Reading parameters... for %s" % self.appkey)
ProcessingLog.addToLog(ProcessingLog.LOG_INFO, "Reading parameters for %s" % self.appkey)

rebu = None
the_result = None
Expand Down Expand Up @@ -194,7 +194,7 @@ def processAlgorithm(self, progress):
else :
data = inputParameter[5:]
dataset = data

#on windows, there isn't "
#if data[-1] == '"':
if currentOs == "posix" :
Expand All @@ -209,7 +209,7 @@ def processAlgorithm(self, progress):
else :
#dataset = os.path.basename( data ) + '"' + dataset[dataset.index('://'):]
dataset = dataset[dataset.index('://'):]

#get index of the subdataset with gdal
if currentOs == "posix" :
commandgdal = "gdalinfo " + data + " | grep '" + dataset + "$'"
Expand All @@ -227,15 +227,15 @@ def processAlgorithm(self, progress):
else :
print "Error : no match of ", dataset, "$ in gdalinfo " + data
indexSubdataset = -1


if not indexSubdataset == -1 :
indexSubdataset = int(indexSubdataset) -1
newParam = "\'" + data + "?&sdataidx=" + str(indexSubdataset) + "\'"

else :
newParam = inputParameter

newparams += newParam
# no hdf5
else :
Expand Down Expand Up @@ -343,5 +343,5 @@ def processAlgorithm(self, progress):
for a_frame in frames:
frame,filename,line_number,function_name,lines,index = a_frame
ProcessingLog.addToLog(ProcessingLog.LOG_INFO, "%s %s %s %s %s %s" % (frame,filename,line_number,function_name,lines,index))

OTBUtils.executeOtb(commands, progress)