Skip to content
Permalink
Browse files

added unicode support in modeler

git-svn-id: http://sextante.googlecode.com/svn/trunk/soft/bindings/qgis-plugin@269 881b9c09-3ef8-f3c2-ec3d-21d735c97f4d
  • Loading branch information
volayaf
volayaf committed Jun 28, 2012
1 parent 6cc27c7 commit 8acc5179a10374968f669a22e9d5fd64931133ca
@@ -16,6 +16,7 @@
from sextante.parameters.ParameterVector import ParameterVector
from sextante.parameters.ParameterTableField import ParameterTableField
from sextante.gui.Help2Html import Help2Html
import codecs

class ModelerAlgorithm(GeoAlgorithm):

@@ -68,7 +69,7 @@ def openModel(self, filename):
self.paramValues = {}

self.descriptionFile = filename
lines = open(filename)
lines = codecs.open(filename, "r", encoding='utf-8')
line = lines.readline().strip("\n")
iAlg = 0
try:
@@ -262,8 +263,8 @@ def getPositionForParameterItem(self):
return QtCore.QPointF(MARGIN + BOX_WIDTH / 2 + len(self.paramPos) * (BOX_WIDTH + MARGIN), MARGIN + BOX_HEIGHT / 2)

def serialize(self):
s="NAME:" + str(self.name) + "\n"
s +="GROUP:" + str(self.group) + "\n"
s="NAME:" + unicode(self.name) + "\n"
s +="GROUP:" + unicode(self.group) + "\n"

i = 0
for param in self.parameters:
@@ -285,7 +286,7 @@ def serialize(self):
else:
s+=str(None) + "\n"
for out in alg.outputs:
s+=str(self.algOutputs[i][out.name]) + "\n"
s+=unicode(self.algOutputs[i][out.name]) + "\n"
return s


@@ -14,6 +14,7 @@
import pickle
from sextante.gui.ParametersDialog import ParametersDialog
from sextante.core.SextanteUtils import SextanteUtils
import codecs

class ModelerDialog(QtGui.QDialog):
def __init__(self, alg=None):
@@ -200,12 +201,12 @@ def runModel(self):
dlg.exec_()

def saveModel(self):
if str(self.textGroup.text()).strip() == "" or str(self.textName.text()).strip() == "":
if unicode(self.textGroup.text()).strip() == "" or unicode(self.textName.text()).strip() == "":
QMessageBox.warning(self, "Warning", "Please enter group and model names before saving")
return
self.alg.setPositions(self.scene.getParameterPositions(), self.scene.getAlgorithmPositions())
self.alg.name = str(self.textName.text())
self.alg.group = str(self.textGroup.text())
self.alg.name = unicode(self.textName.text())
self.alg.group = unicode(self.textGroup.text())
if self.alg.descriptionFile != None:
filename = self.alg.descriptionFile
else:
@@ -216,7 +217,8 @@ def saveModel(self):
self.alg.descriptionFile = filename
if filename:
text = self.alg.serialize()
fout = open(filename, "w")
fout = codecs.open(filename, "a", encoding='utf-8')
#fout = open(filename, "w")
fout.write(text)
fout.close()
self.update = True
@@ -157,12 +157,14 @@ def setupUi(self):


def okPressed(self):
description = str(self.nameTextBox.text())
description = unicode(self.nameTextBox.text())
if description.strip() == "":
QMessageBox.critical(self, "Unable to define parameter", "Invalid parameter name")
return
if self.param is None:
name = self.paramType.upper().replace(" ","") + "_" + description.upper().replace(" ","")
validChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
safeName = ''.join(c for c in description if c in validChars)
name = self.paramType.upper().replace(" ","") + "_" + safeName.upper()
else:
name = self.param.name
if self.paramType == ModelerParameterDefinitionDialog.PARAMETER_BOOLEAN or isinstance(self.param, ParameterBoolean):
@@ -405,7 +405,7 @@ def setParamValues(self):
for output in outputs:
if output.hidden:
continue
name= str(self.valueItems[output.name].text())
name= unicode(self.valueItems[output.name].text())
if name.strip()!="" and name != ModelerParametersDialog.ENTER_NAME:
self.outputs[output.name]=name
else:

0 comments on commit 8acc517

Please sign in to comment.
You can’t perform that action at this time.