Skip to content

Commit d927756

Browse files
committedApr 17, 2013
[sextante] Fixed iterative execution
Some additional minor fixes
1 parent 1570240 commit d927756

File tree

7 files changed

+37
-44
lines changed

7 files changed

+37
-44
lines changed
 

‎python/plugins/sextante/algs/mmqgisx/MMQGISXAlgorithms.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -906,15 +906,12 @@ def processAlgorithm(self, progress):
906906
i += 1
907907
spokex = spokepoint.geometry().boundingBox().center().x()
908908
spokey = spokepoint.geometry().boundingBox().center().y()
909-
spokeid = unicode(spokepoint.attributeMap()[spokeindex].toString())
909+
spokeid = unicode(spokepoint.attributes()[spokeindex].toString())
910910
progress.setPercentage(float(i) / len(spokepoints) * 100)
911-
# Scan hub points to find first matching hub
912-
hubpoint = QgsFeature()
913-
hublayer.dataProvider().select(hublayer.dataProvider().attributeIndexes())
914-
hublayer.dataProvider().rewind()
911+
# Scan hub points to find first matching hub
915912
hubpoints = QGisLayers.features(hublayer)
916913
for hubpoint in hubpoints:
917-
hubid = unicode(hubpoint.attributeMap()[hubindex].toString())
914+
hubid = unicode(hubpoint.attributes()[hubindex].toString())
918915
if hubid == spokeid:
919916
hubx = hubpoint.geometry().boundingBox().center().x()
920917
huby = hubpoint.geometry().boundingBox().center().y()

‎python/plugins/sextante/gui/AlgorithmExecutionDialog.py

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -213,36 +213,27 @@ def accept(self):
213213
return
214214
msg = self.alg.checkParameterValuesBeforeExecuting()
215215
if msg:
216-
#===============================================================
217-
# if keepOpen or useThread:
218-
# self.setInfo("Unable to execute algorithm: %s" % msg, True)
219-
# self.tabWidget.setCurrentIndex(1) # log tab
220-
# else:
221-
#===============================================================
222216
QMessageBox.critical(self, "Unable to execute algorithm", msg)
223217
return
224218
self.buttonBox.button(QtGui.QDialogButtonBox.Ok).setEnabled(False)
225219
self.buttonBox.button(QtGui.QDialogButtonBox.Close).setEnabled(False)
226220
buttons = self.paramTable.iterateButtons
227-
iterateParam = None
221+
self.iterateParam = None
228222

229223
for i in range(len(buttons.values())):
230224
button = buttons.values()[i]
231225
if button.isChecked():
232-
iterateParam = buttons.keys()[i]
226+
self.iterateParam = buttons.keys()[i]
233227
break
234228

235229
self.progress.setMaximum(0)
236230
self.progressLabel.setText("Processing algorithm...")
237231
QApplication.setOverrideCursor(QCursor(Qt.WaitCursor))
238-
if useThread:
239-
if iterateParam:
240-
self.algEx = AlgorithmExecutor(self.alg, iterateParam)
241-
else:
242-
command = self.alg.getAsCommand()
243-
if command:
244-
SextanteLog.addToLog(SextanteLog.LOG_ALGORITHM, command)
245-
self.algEx = AlgorithmExecutor(self.alg)
232+
if useThread and not self.iterateParam: #iterative execution on separate thread is still not working fine...
233+
command = self.alg.getAsCommand()
234+
if command:
235+
SextanteLog.addToLog(SextanteLog.LOG_ALGORITHM, command)
236+
self.algEx = AlgorithmExecutor(self.alg)
246237
self.algEx.algExecuted.connect(self.finish)
247238
self.algEx.error.connect(self.error)
248239
self.algEx.percentageChanged.connect(self.setPercentage)
@@ -258,8 +249,8 @@ def accept(self):
258249
self.buttonBox.button(QtGui.QDialogButtonBox.Cancel).setEnabled(True)
259250
else:
260251
self.setInfo("<b>Algorithm %s starting...</b>" % self.alg.name)
261-
if iterateParam:
262-
if UnthreadedAlgorithmExecutor.runalgIterating(self.alg, iterateParam, self):
252+
if self.iterateParam:
253+
if UnthreadedAlgorithmExecutor.runalgIterating(self.alg, self.iterateParam, self):
263254
self.finish()
264255
else:
265256
QApplication.restoreOverrideCursor()
@@ -294,7 +285,8 @@ def accept(self):
294285
@pyqtSlot()
295286
def finish(self):
296287
keepOpen = SextanteConfig.getSetting(SextanteConfig.KEEP_DIALOG_OPEN)
297-
SextantePostprocessing.handleAlgorithmResults(self.alg, self, not keepOpen)
288+
if self.iterateParam is None:
289+
SextantePostprocessing.handleAlgorithmResults(self.alg, self, not keepOpen)
298290
self.executed = True
299291
self.setInfo("Algorithm %s finished" % self.alg.name)
300292
QApplication.restoreOverrideCursor()
@@ -306,8 +298,7 @@ def finish(self):
306298
self.setInfo("HTML output has been generated by this algorithm.\nOpen the SEXTANTE results dialog to check it.")
307299

308300
@pyqtSlot(str)
309-
def error(self, msg):
310-
#self.algEx.finished.disconnect()
301+
def error(self, msg):
311302
QApplication.restoreOverrideCursor()
312303
keepOpen = SextanteConfig.getSetting(SextanteConfig.KEEP_DIALOG_OPEN)
313304
self.setInfo(msg, True)
@@ -316,7 +307,7 @@ def error(self, msg):
316307
self.close()
317308
else:
318309
self.resetGUI()
319-
self.setInfo(msg, True)
310+
#self.setInfo(msg, True)
320311
self.tabWidget.setCurrentIndex(1) # log tab
321312

322313
@pyqtSlot(int)

‎python/plugins/sextante/gui/AlgorithmExecutor.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@
2929
from sextante.core.GeoAlgorithmExecutionException import GeoAlgorithmExecutionException
3030
from sextante.core.QGisLayers import QGisLayers
3131
from sextante.core.SextanteUtils import SextanteUtils
32+
from sextante.tools.vector import getfeatures
33+
from sextante.gui.SextantePostprocessing import SextantePostprocessing
34+
import sextante
3235
import sys
3336

3437
class AlgorithmExecutor(QThread):
@@ -74,11 +77,9 @@ def setConsoleInfo(self, info):
7477
layerfile = alg.getParameterValue(self.parameterToIterate)
7578
layer = QGisLayers.getObjectFromUri(layerfile, False)
7679
provider = layer.dataProvider()
77-
allAttrs = provider.attributeIndexes()
78-
provider.select( allAttrs )
79-
feat = QgsFeature()
80+
features = getfeatures(layer)
8081
self.filelist = []
81-
while provider.nextFeature(feat):
82+
for feat in features:
8283
output = SextanteUtils.getTempFilename("shp")
8384
self.filelist.append(output)
8485
writer = QgsVectorFileWriter(output, systemEncoding,provider.fields(), provider.geometryType(), layer.crs() )
@@ -94,7 +95,8 @@ def raiseInternalError(self, error):
9495
def runalg(self):
9596
try:
9697
self.algorithm.execute(self.progress)
97-
self.algExecuted.emit()
98+
if not self.parameterToIterate:
99+
self.algExecuted.emit()
98100
except GeoAlgorithmExecutionException, e :
99101
self.error.emit(e.msg)
100102
except BaseException, e:
@@ -123,8 +125,10 @@ def runalgIterating(self):
123125
self.progress.setText("Executing iteration " + str(i) + "/" + str(len(self.filelist)) + "...")
124126
self.progress.setPercentage((i * 100) / len(self.filelist))
125127
self.runalg()
128+
SextantePostprocessing.handleAlgorithmResults(self.algorithm, self.progress, False)
126129
self.iterated.emit(i)
127130
i += 1
131+
self.algExecuted.emit()
128132
except BaseException, e:
129133
self.error.emit(str(e))
130134
print "Error iterating " + str(e)

‎python/plugins/sextante/gui/SextanteToolbox.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ def fillTreeUsingCategories(self):
279279
if (text != ""):
280280
self.algorithmTree.expandAll()
281281

282-
def fillTreeUsingProviders(self):
282+
def fillTreeUsingProviders(self):
283283
self.algorithmTree.clear()
284284
text = unicode(self.searchBox.text())
285285
for providerName in Sextante.algs.keys():

‎python/plugins/sextante/gui/UnthreadedAlgorithmExecutor.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
* *
1717
***************************************************************************
1818
"""
19+
from sextante.tools.vector import getfeatures
1920

2021
__author__ = 'Victor Olaya'
2122
__date__ = 'August 2012'
@@ -55,17 +56,16 @@ def runalgIterating(alg,paramToIter,progress):
5556
settings = QSettings()
5657
systemEncoding = settings.value( "/UI/encoding", "System" ).toString()
5758
layerfile = alg.getParameterValue(paramToIter)
58-
layer = QGisLayers.getObjectFromUri(layerfile, False)
59-
provider = layer.dataProvider()
60-
allAttrs = provider.attributeIndexes()
61-
provider.select( allAttrs )
59+
layer = QGisLayers.getObjectFromUri(layerfile, False)
6260
feat = QgsFeature()
6361
filelist = []
6462
outputs = {}
65-
while provider.nextFeature(feat):
63+
provider = layer.dataProvider()
64+
features = getfeatures(layer)
65+
for feat in features:
6666
output = SextanteUtils.getTempFilename("shp")
6767
filelist.append(output)
68-
writer = QgsVectorFileWriter(output, systemEncoding,provider.fields(), provider.geometryType(), layer.crs() )
68+
writer = QgsVectorFileWriter(output, systemEncoding, provider.fields(), provider.geometryType(), layer.crs() )
6969
writer.addFeature(feat)
7070
del writer
7171

‎python/plugins/sextante/modeler/ModelerParameterDefinitionDialog.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ def setupUi(self):
187187
self.defaultTextBox = QtGui.QLineEdit()
188188
self.defaultTextBox.setText("0")
189189
if self.param is not None:
190-
self.defaultTextBox.setText(self.param.default)
190+
self.defaultTextBox.setText(str(self.param.default))
191191
self.horizontalLayout3.addWidget(self.defaultTextBox)
192192
self.verticalLayout.addLayout(self.horizontalLayout3)
193193
elif self.paramType == ModelerParameterDefinitionDialog.PARAMETER_STRING \
@@ -206,16 +206,17 @@ def setupUi(self):
206206
self.fileFolderCombo.addItem("Folder")
207207
self.horizontalLayout2.addWidget(self.fileFolderCombo)
208208
if self.param is not None:
209-
self.fileFolderCombo.setCurrentIndex(1 if self.param.isFolder else 0)
209+
self.fileFolderCombo.setCurrentIndex(1 if self.param.isFolder else 0)
210210

211211
self.buttonBox = QtGui.QDialogButtonBox(self)
212212
self.buttonBox.setOrientation(QtCore.Qt.Horizontal)
213213
self.buttonBox.setStandardButtons(QtGui.QDialogButtonBox.Cancel|QtGui.QDialogButtonBox.Ok)
214214
self.buttonBox.setObjectName("buttonBox")
215215
QObject.connect(self.buttonBox, QtCore.SIGNAL("accepted()"), self.okPressed)
216216
QObject.connect(self.buttonBox, QtCore.SIGNAL("rejected()"), self.cancelPressed)
217+
217218
self.verticalLayout.addWidget(self.buttonBox)
218-
219+
219220
self.setLayout(self.verticalLayout)
220221

221222

‎python/plugins/sextante/parameters/ParameterTableField.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def setValue(self, field):
5555

5656
def serialize(self):
5757
return self.__module__.split(".")[-1] + "|" + self.name + "|" + self.description +\
58-
"|" + str(self.parent) + "|" + str(self.datatype)
58+
"|" + str(self.parent) + "|" + str(self.datatype) + "|" + str(self.optional)
5959

6060
def deserialize(self, s):
6161
tokens = s.split("|")

0 commit comments

Comments
 (0)
Please sign in to comment.