Skip to content

Commit d933f2b

Browse files
author
volayaf
committedApr 23, 2012
added more functionality to iterative execution
fixed minor bugs git-svn-id: http://sextante.googlecode.com/svn/trunk/soft/bindings/qgis-plugin@145 881b9c09-3ef8-f3c2-ec3d-21d735c97f4d
1 parent 12d6f65 commit d933f2b

File tree

7 files changed

+78
-37
lines changed

7 files changed

+78
-37
lines changed
 

‎src/sextante/core/GeoAlgorithm.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ def resolveTemporaryOutputs(self):
144144
def setOutputCRSFromInputLayers(self):
145145
layers = QGisLayers.getAllLayers()
146146
for param in self.parameters:
147-
if isinstance(param, (ParameterRaster, ParameterVector ,ParameterMultipleInput)):
147+
if isinstance(param, (ParameterRaster, ParameterVector, ParameterMultipleInput)):
148148
inputlayers = param.value.split(";")
149149
for inputlayer in inputlayers:
150150
for layer in layers:
@@ -166,7 +166,7 @@ def addParameter(self, param):
166166
def setParameterValue(self, paramName, value):
167167
for param in self.parameters:
168168
if param.name == paramName:
169-
param.value = value
169+
return param.setValue(value)
170170

171171
def setOutputValue(self, outputName, value):
172172
for out in self.outputs:

‎src/sextante/gui/AlgorithmExecutor.py

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
from PyQt4.QtGui import *
22
from sextante.core.GeoAlgorithmExecutionException import GeoAlgorithmExecutionException
3+
from sextante.core.QGisLayers import QGisLayers
4+
from sextante.core.SextanteUtils import SextanteUtils
35

46
class AlgorithmExecutor:
57

@@ -16,8 +18,44 @@ def runalg(alg, progress):
1618
return False
1719

1820
@staticmethod
19-
def runalgIterating(alg,paramtoIter,progress):
20-
return False
21+
def runalgIterating(alg,paramToIter,progress):
22+
#generate all single-feature layers
23+
settings = QSettings()
24+
systemEncoding = settings.value( "/UI/encoding", "System" ).toString()
25+
layerfile = alg.getParameterFromName(paramToIter)
26+
layer = QGisLayers.getObjectFromUri(layerfile, False)
27+
provider = layer.dataProvider()
28+
allAttrs = provider.attributeIndexes()
29+
provider.select( allAttrs )
30+
feat = QgsFeature()
31+
filelist = []
32+
outputs = {}
33+
while provider.nextFeature(feat):
34+
output = SextanteUtils.getTempFilename("shp")
35+
filelist.append(output)
36+
writer = QgsVectorFileWriter(output, systemEncoding,provider.fields(), provider.geometryType(), provider.crs() )
37+
writer.addFeature(feat)
38+
del writer
39+
#now run all the algorithms
40+
for out in alg.outputs:
41+
output[out.name] = out.value
42+
43+
i = 1
44+
for f in filelist:
45+
alg.setOutputValue(paramToIter, f)
46+
for out in alg.outputs:
47+
filename = outputs[out.name]
48+
if filename:
49+
filename = filename[:filename.rfind(".")] + "_" + str(i) + filename[filename.rfind("."):]
50+
out.value = filename
51+
if AlgorithmExecutor.runalg(alg, SilentProgress()):
52+
progress.setValue(i/len(f))
53+
i+=1
54+
else:
55+
return False;
56+
57+
return True
58+
2159

2260
class SilentProgress():
2361

‎src/sextante/gui/ParametersDialog.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ def setParamValue(self, param, widget):
135135
def accept(self):
136136
try:
137137
if self.setParamValues():
138+
keepOpen = SextanteConfig.getSetting(SextanteConfig.KEEP_DIALOG_OPEN)
138139
self.buttonBox.button(QtGui.QDialogButtonBox.Ok).setEnabled(False)
139140
buttons = self.paramTable.iterateButtons
140141
iterateParam = None
@@ -154,10 +155,10 @@ def accept(self):
154155
ret = AlgorithmExecutor.runalg(self.alg, self)
155156
QApplication.restoreOverrideCursor()
156157
if ret:
157-
SextantePostprocessing.handleAlgorithmResults(self.alg)
158+
SextantePostprocessing.handleAlgorithmResults(self.alg, not keepOpen)
158159

159160
self.dialog.executed = True
160-
if not SextanteConfig.getSetting(SextanteConfig.KEEP_DIALOG_OPEN):
161+
if not keepOpen:
161162
self.dialog.close()
162163
else:
163164
self.progressLabel.setText("")

‎src/sextante/gui/SextantePostprocessing.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,11 @@
99
from PyQt4.QtGui import *
1010
from sextante.core.SextanteConfig import SextanteConfig
1111
import os
12-
from sextante.outputs.OutputFile import OutputFile
1312
class SextantePostprocessing:
1413

1514
@staticmethod
16-
def handleAlgorithmResults(alg):
17-
showResults = False;
15+
def handleAlgorithmResults(alg, showResults = True):
16+
htmlResults = False;
1817
for out in alg.outputs:
1918
if out.hidden:
2019
continue
@@ -29,7 +28,7 @@ def handleAlgorithmResults(alg):
2928
QMessageBox.critical(None, "Error", str(e))
3029
elif isinstance(out, OutputHTML):
3130
SextanteResults.addResult(out.description, out.value)
32-
showResults = True
33-
if showResults:
31+
htmlResults = True
32+
if showResults and htmlResults:
3433
dlg = ResultsDialog()
3534
dlg.exec_()

‎src/sextante/modeler/ModelerDialog.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -179,22 +179,23 @@ def saveModel(self):
179179
filename = self.alg.descriptionFile
180180
else:
181181
filename = str(QtGui.QFileDialog.getSaveFileName(self, "Save Model", ModelerUtils.modelsFolder(), "SEXTANTE models (*.model)"))
182-
if not filename.endswith(".model"):
183-
filename += ".model"
184-
self.alg.descriptionFile = filename
182+
if filename:
183+
if not filename.endswith(".model"):
184+
filename += ".model"
185+
self.alg.descriptionFile = filename
185186
if filename:
186187
text = self.alg.serialize()
187188
fout = open(filename, "w")
188189
fout.write(text)
189190
fout.close()
190191
self.update = True
191-
192-
#if help strings were defined before saving the model for the first time, we do it here
193-
if self.help:
194-
f = open(self.alg.descriptionFile + ".help", "wb")
195-
pickle.dump(self.help, f)
196-
f.close()
197-
self.help = None
192+
#if help strings were defined before saving the model for the first time, we do it here
193+
if self.help:
194+
f = open(self.alg.descriptionFile + ".help", "wb")
195+
pickle.dump(self.help, f)
196+
f.close()
197+
self.help = None
198+
QtGui.QMessageBox.information(self, "Model saving", "Model was correctly saved.")
198199

199200
def openModel(self):
200201
filename = QtGui.QFileDialog.getOpenFileName(self, "Open Model", ModelerUtils.modelsFolder(), "SEXTANTE models (*.model)")

‎src/sextante/r/EditRScriptDialog.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from PyQt4.QtGui import *
44
from sextante.r.RUtils import RUtils
55
import pickle
6+
from sextante.gui.HelpEditionDialog import HelpEditionDialog
67

78
class EditRScriptDialog(QtGui.QDialog):
89
def __init__(self, alg):
@@ -51,14 +52,14 @@ def saveAlgorithm(self):
5152
fout.write(text)
5253
fout.close()
5354
self.update = True
54-
self.close()
55-
56-
#if help strings were defined before saving the model for the first time, we do it here
57-
if self.help:
58-
f = open(self.alg.descriptionFile + ".help", "wb")
59-
pickle.dump(self.help, f)
60-
f.close()
61-
self.help = None
55+
#if help strings were defined before saving the model for the first time, we do it here
56+
if self.help:
57+
f = open(self.alg.descriptionFile + ".help", "wb")
58+
pickle.dump(self.help, f)
59+
f.close()
60+
self.help = None
61+
QtGui.QMessageBox.information(self, "Script saving", "Script was correctly saved.")
62+
#self.close()
6263

6364
def cancelPressed(self):
6465
self.update = False

‎src/sextante/script/EditScriptDialog.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,20 +57,21 @@ def saveAlgorithm(self):
5757
filename = self.alg.descriptionFile
5858
else:
5959
filename = QtGui.QFileDialog.getSaveFileName(self, "Save Script", ScriptUtils.scriptsFolder(), "Python scripts (*.py)")
60+
6061
if filename:
6162
text = self.text.toPlainText()
6263
fout = open(filename, "w")
6364
fout.write(text)
6465
fout.close()
6566
self.update = True
66-
self.close()
67-
68-
#if help strings were defined before saving the model for the first time, we do it here
69-
if self.help:
70-
f = open(self.alg.descriptionFile + ".help", "wb")
71-
pickle.dump(self.help, f)
72-
f.close()
73-
self.help = None
67+
#if help strings were defined before saving the model for the first time, we do it here
68+
if self.help:
69+
f = open(self.alg.descriptionFile + ".help", "wb")
70+
pickle.dump(self.help, f)
71+
f.close()
72+
self.help = None
73+
#self.close()
74+
QtGui.QMessageBox.information(self, "Script saving", "Script was correctly saved.")
7475

7576
def cancelPressed(self):
7677
self.update = False

0 commit comments

Comments
 (0)
Please sign in to comment.