Skip to content
Permalink
Browse files

fixed encoding problem in log

fixed problem when editing help and saving scripts (still have to apply it to R scripts)

git-svn-id: http://sextante.googlecode.com/svn/trunk/soft/bindings/qgis-plugin@229 881b9c09-3ef8-f3c2-ec3d-21d735c97f4d
  • Loading branch information
volayaf
volayaf committed Jun 7, 2012
1 parent 9718b9f commit 9c842434fa0ebe629a79d9a34de2303956265554
@@ -31,7 +31,7 @@ def addToLog(msgtype, msg):
text=""
for i in range(0, len(msg)):
text+=msg[i].strip("\n") + "|"
text = text[:-1]
text = unicode(text[:-1])
else:
text = unicode(msg).replace("\n", "|")
line = msgtype + "|" + datetime.datetime.now().strftime("%a %b %d %Y %H:%M:%S") + "|" + text + "\n"
@@ -15,7 +15,7 @@ def __init__(self, alg):
QtGui.QDialog.__init__(self)
self.setModal(True)
self.descriptions = {}
if self.alg.descriptionFile:
if self.alg.descriptionFile is not None:
helpfile = alg.descriptionFile + ".help"
if os.path.exists(helpfile):
f = open(helpfile, "rb")
@@ -88,7 +88,7 @@ def closeWindow(self):

def saveHelp(self):
self.descriptions[self.currentName] = str(self.text.toPlainText())
if self.alg.descriptionFile:
if self.alg.descriptionFile is not None:
f = open(self.alg.descriptionFile + ".help", "wb")
pickle.dump(self.descriptions, f)
f.close()
@@ -4,10 +4,15 @@
from sextante.script.ScriptUtils import ScriptUtils
from sextante.gui.HelpEditionDialog import HelpEditionDialog
import pickle
from sextante.script.ScriptAlgorithm import ScriptAlgorithm

class EditScriptDialog(QtGui.QDialog):
def __init__(self, alg):
self.alg = alg
if self.alg is not None:
self.filename = self.alg.descriptionFile
else:
self.filename = None
QtGui.QDialog.__init__(self)
self.setModal(True)
self.setupUi()
@@ -25,10 +30,10 @@ def setupUi(self):
self.buttonBox.setOrientation(QtCore.Qt.Horizontal)
if self.alg != None:
self.text.setText(self.alg.script)
self.editHelpButton = QtGui.QPushButton()
self.editHelpButton.setText("Edit model help")
self.buttonBox.addButton(self.editHelpButton, QtGui.QDialogButtonBox.ActionRole)
QObject.connect(self.editHelpButton, QtCore.SIGNAL("clicked()"), self.editHelp)
self.editHelpButton = QtGui.QPushButton()
self.editHelpButton.setText("Edit model help")
self.buttonBox.addButton(self.editHelpButton, QtGui.QDialogButtonBox.ActionRole)
QObject.connect(self.editHelpButton, QtCore.SIGNAL("clicked()"), self.editHelp)
self.saveButton = QtGui.QPushButton()
self.saveButton.setText("Save")
self.buttonBox.addButton(self.saveButton, QtGui.QDialogButtonBox.ActionRole)
@@ -44,36 +49,40 @@ def setupUi(self):


def editHelp(self):
dlg = HelpEditionDialog(self.alg)
if self.alg is None:
alg = ScriptAlgorithm(None, unicode(self.text.toPlainText()))
else:
alg = self.alg
dlg = HelpEditionDialog(alg)
dlg.exec_()
#We store the description string in case there were not saved because there was no
#filename defined yet
if self.alg.descriptionFile is None and dlg.descriptions:
if self.alg is None and dlg.descriptions:
self.help = dlg.descriptions


def saveAlgorithm(self):
if self.alg!=None:
filename = self.alg.descriptionFile
else:
filename = QtGui.QFileDialog.getSaveFileName(self, "Save Script", ScriptUtils.scriptsFolder(), "Python scripts (*.py)")
if self.filename is None:
self.filename = QtGui.QFileDialog.getSaveFileName(self, "Save Script", ScriptUtils.scriptsFolder(), "Python scripts (*.py)")

if filename:
self.alg.descriptionFile = filename
text = self.text.toPlainText()
fout = open(filename, "w")
if self.filename:
text = str(self.text.toPlainText())
if self.alg is not None:
self.alg.script = text
fout = open(self.filename, "w")
fout.write(text)
fout.close()
self.update = True
#if help strings were defined before saving the model for the first time, we do it here
if self.help:
f = open(self.alg.descriptionFile + ".help", "wb")
f = open(self.filename + ".help", "wb")
pickle.dump(self.help, f)
f.close()
self.help = None
#self.close()
QtGui.QMessageBox.information(self, "Script saving", "Script was correctly saved.")
else:
self.filename = None

def cancelPressed(self):
self.update = False
#self.update = False
self.close()
@@ -23,10 +23,16 @@

class ScriptAlgorithm(GeoAlgorithm):

def __init__(self, descriptionfile):
def __init__(self, descriptionFile, script=None):
'''The script parameter can be used to directly pass the code of the script without a file.
This is to be used from the script edition dialog, but should not be used in other cases'''
GeoAlgorithm.__init__(self)
self.descriptionFile = descriptionfile
self.defineCharacteristicsFromFile()
self.script = script
self.descriptionFile = descriptionFile
if script is not None:
self.defineCharacteristicsFromScript()
if descriptionFile is not None:
self.defineCharacteristicsFromFile()

def getCopy(self):
newone = ScriptAlgorithm(self.descriptionFile)
@@ -36,7 +42,6 @@ def getCopy(self):
def getIcon(self):
return QtGui.QIcon(os.path.dirname(__file__) + "/../images/script.png")


def defineCharacteristicsFromFile(self):
self.script=""
self.silentOutputs = []
@@ -55,6 +60,19 @@ def defineCharacteristicsFromFile(self):
line = lines.readline()
lines.close()


def defineCharacteristicsFromScript(self):
lines = self.script.split("\n")
self.silentOutputs = []
self.name = "[Unnamed algorithm]"
self.group = "User scripts"
for line in lines:
if line.startswith("##"):
try:
self.processParameterLine(line.strip("\n"))
except:
pass

def createDescriptiveName(self, s):
return s.replace("_", " ")

0 comments on commit 9c84243

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