mt3.diff
src/sextante/gui/AlgorithmExecutor.py (working copy) | ||
---|---|---|
7 | 7 |
from sextante.gui.SextantePostprocessing import SextantePostprocessing |
8 | 8 |
import traceback |
9 | 9 |
|
10 |
class AlgorithmExecutor: |
|
10 |
class AlgorithmExecutor(QThread): |
|
11 |
percentageChanged = pyqtSignal(int) |
|
12 |
textChanged = pyqtSignal(QString) |
|
13 |
cancelled = pyqtSignal() |
|
14 |
error = pyqtSignal() |
|
15 |
iterated = pyqtSignal(int) |
|
16 |
#started & finished inherited from QThread |
|
11 | 17 |
|
12 |
@staticmethod |
|
13 |
def runalg(alg, progress): |
|
14 |
'''executes a given algorithm, showing its progress in the progress object passed along. |
|
15 |
Return true if everything went OK, false if the algorithm was canceled or there was |
|
16 |
any problem and could not be completed''' |
|
18 |
def __init__(self, alg, iterParam = None, parent = None): |
|
19 |
QThread.__init__(self, parent) |
|
20 |
self.algorithm = alg |
|
21 |
self.parameterToIterate = iterParam |
|
22 |
|
|
23 |
class Progress: |
|
24 |
def __init__(self, algex): |
|
25 |
self.algorithmExecutor = algex |
|
26 |
def setText(self, text): |
|
27 |
self.algorithmExecutor.textChanged.emit(text) |
|
28 |
def setPercentage(self, p): |
|
29 |
self.algorithmExecutor.percentageChanged.emit(p) |
|
30 |
self.progress = Progress(self) |
|
31 |
if self.parameterToIterate: |
|
32 |
self.run = self.runalgIterating |
|
33 |
|
|
34 |
#generate all single-feature layers |
|
35 |
settings = QSettings() |
|
36 |
systemEncoding = settings.value( "/UI/encoding", "System" ).toString() |
|
37 |
layerfile = alg.getParameterValue(self.parameterToIterate) |
|
38 |
layer = QGisLayers.getObjectFromUri(layerfile, False) |
|
39 |
provider = layer.dataProvider() |
|
40 |
allAttrs = provider.attributeIndexes() |
|
41 |
provider.select( allAttrs ) |
|
42 |
feat = QgsFeature() |
|
43 |
self.filelist = [] |
|
44 |
outputs = {} |
|
45 |
while provider.nextFeature(feat): |
|
46 |
output = SextanteUtils.getTempFilename("shp") |
|
47 |
self.filelist.append(output) |
|
48 |
writer = QgsVectorFileWriter(output, systemEncoding,provider.fields(), provider.geometryType(), provider.crs() ) |
|
49 |
writer.addFeature(feat) |
|
50 |
del writer |
|
51 |
|
|
52 |
#store output values to use them later as basenames for all outputs |
|
53 |
for out in self.algorithm.outputs: |
|
54 |
outputs[out.name] = out.value |
|
55 |
else: |
|
56 |
self.run = self.runalg |
|
57 |
|
|
58 |
def runalg(self): |
|
17 | 59 |
try: |
18 |
alg.execute(progress) |
|
19 |
return not alg.canceled |
|
60 |
self.algorithm.execute(self.progress) |
|
61 |
if self.algorithm.canceled: |
|
62 |
self.canceled.emit() |
|
20 | 63 |
except GeoAlgorithmExecutionException, e : |
21 |
QMessageBox.critical(None, "Error", e.msg) |
|
22 |
return False |
|
23 |
except Exception: |
|
24 |
QMessageBox.critical(None, "Error", traceback.format_exc()) |
|
25 |
return False |
|
64 |
self.error.emit() |
|
65 |
except: |
|
66 |
self.error.emit() |
|
26 | 67 |
|
27 |
@staticmethod |
|
28 |
def runalgIterating(alg,paramToIter,progress): |
|
29 |
#generate all single-feature layers |
|
30 |
settings = QSettings() |
|
31 |
systemEncoding = settings.value( "/UI/encoding", "System" ).toString() |
|
32 |
layerfile = alg.getParameterValue(paramToIter) |
|
33 |
layer = QGisLayers.getObjectFromUri(layerfile, False) |
|
34 |
provider = layer.dataProvider() |
|
35 |
allAttrs = provider.attributeIndexes() |
|
36 |
provider.select( allAttrs ) |
|
37 |
feat = QgsFeature() |
|
38 |
filelist = [] |
|
39 |
outputs = {} |
|
40 |
while provider.nextFeature(feat): |
|
41 |
output = SextanteUtils.getTempFilename("shp") |
|
42 |
filelist.append(output) |
|
43 |
writer = QgsVectorFileWriter(output, systemEncoding,provider.fields(), provider.geometryType(), provider.crs() ) |
|
44 |
writer.addFeature(feat) |
|
45 |
del writer |
|
46 |
|
|
47 |
#store output values to use them later as basenames for all outputs |
|
48 |
for out in alg.outputs: |
|
49 |
outputs[out.name] = out.value |
|
50 |
|
|
51 |
#now run all the algorithms |
|
68 |
def runalgIterating(self): |
|
52 | 69 |
i = 1 |
53 |
for f in filelist: |
|
54 |
alg.setParameterValue(paramToIter, f)
|
|
55 |
for out in alg.outputs:
|
|
70 |
for f in self.filelist:
|
|
71 |
self.algorithm.setParameterValue(self.parameterToIterate, f)
|
|
72 |
for out in self.algorithm.outputs:
|
|
56 | 73 |
filename = outputs[out.name] |
57 | 74 |
if filename: |
58 | 75 |
filename = filename[:filename.rfind(".")] + "_" + str(i) + filename[filename.rfind("."):] |
59 | 76 |
out.value = filename |
60 |
progress.setText("Executing iteration " + str(i) + "/" + str(len(filelist)) + "...") |
|
61 |
progress.setPercentage((i * 100) / len(filelist)) |
|
62 |
if AlgorithmExecutor.runalg(alg, SilentProgress()): |
|
63 |
SextantePostprocessing.handleAlgorithmResults(alg, False) |
|
64 |
i+=1 |
|
65 |
else: |
|
66 |
return False; |
|
67 |
|
|
68 |
return True |
|
69 |
|
|
70 |
|
|
71 |
class SilentProgress(): |
|
72 |
|
|
73 |
def setText(self, text): |
|
74 |
pass |
|
75 |
|
|
76 |
def setPercentage(self, i): |
|
77 |
pass |
|
77 |
self.progress.setText("Executing iteration " + str(i) + "/" + str(len(filelist)) + "...") |
|
78 |
self.progress.setPercentage((i * 100) / len(filelist)) |
|
79 |
self.runalg() |
|
80 |
if self.algorithm.canceled: |
|
81 |
return |
|
82 |
#~ SextantePostprocessing.handleAlgorithmResults(self.algorithm, False) |
|
83 |
self.iterated.emit(i) |
|
84 |
i += 1 |
src/sextante/gui/BatchProcessingDialog.py (working copy) | ||
---|---|---|
12 | 12 |
from sextante.parameters.ParameterMultipleInput import ParameterMultipleInput |
13 | 13 |
import copy |
14 | 14 |
from sextante.gui.BatchOutputSelectionPanel import BatchOutputSelectionPanel |
15 |
from sextante.gui.AlgorithmExecutor import AlgorithmExecutor, SilentProgress
|
|
15 |
from sextante.gui.AlgorithmExecutor import AlgorithmExecutor |
|
16 | 16 |
from sextante.outputs.OutputHTML import OutputHTML |
17 | 17 |
from sextante.core.SextanteResults import SextanteResults |
18 | 18 |
from sextante.gui.ResultsDialog import ResultsDialog |
... | ... | |
102 | 102 |
i=1 |
103 | 103 |
self.progress.setMaximum(len(self.algs)) |
104 | 104 |
for alg in self.algs: |
105 |
if AlgorithmExecutor.runalg(alg, SilentProgress()): |
|
106 |
self.progress.setValue(i) |
|
107 |
self.loadHTMLResults(alg, i) |
|
108 |
i+=1 |
|
109 |
else: |
|
110 |
QApplication.restoreOverrideCursor() |
|
111 |
return |
|
105 |
algEx = AlgorithmExecutor(alg); |
|
106 |
algEx.start() |
|
107 |
|
|
112 | 108 |
QApplication.restoreOverrideCursor() |
113 | 109 |
QMessageBox.information(self, "Batch processing", "Batch processing successfully completed!") |
114 | 110 |
self.close() |
src/sextante/gui/ParametersDialog.py (working copy) | ||
---|---|---|
52 | 52 |
dialog.resize(650, 450) |
53 | 53 |
self.buttonBox = QtGui.QDialogButtonBox() |
54 | 54 |
self.buttonBox.setOrientation(QtCore.Qt.Horizontal) |
55 |
self.buttonBox.setStandardButtons(QtGui.QDialogButtonBox.Cancel|QtGui.QDialogButtonBox.Ok) |
|
55 |
self.buttonBox.setStandardButtons( |
|
56 |
QtGui.QDialogButtonBox.Cancel|QtGui.QDialogButtonBox.Close|QtGui.QDialogButtonBox.Ok) |
|
57 |
self.buttonBox.button(QtGui.QDialogButtonBox.Cancel).setEnabled(False) |
|
58 |
|
|
56 | 59 |
self.paramTable = ParametersPanel(self.alg, self.dialog) |
57 | 60 |
self.scrollArea = QtGui.QScrollArea() |
58 | 61 |
self.scrollArea.setWidget(self.paramTable) |
... | ... | |
93 | 96 |
self.verticalLayout.addWidget(self.progress) |
94 | 97 |
self.verticalLayout.addWidget(self.buttonBox) |
95 | 98 |
dialog.setLayout(self.verticalLayout) |
96 |
QtCore.QObject.connect(self.buttonBox, QtCore.SIGNAL(_fromUtf8("accepted()")), self.accept) |
|
97 |
QtCore.QObject.connect(self.buttonBox, QtCore.SIGNAL(_fromUtf8("rejected()")), self.reject) |
|
99 |
self.buttonBox.accepted.connect(self.accept) |
|
100 |
self.buttonBox.rejected.connect(self.dialog.close) |
|
101 |
self.buttonBox.button(QtGui.QDialogButtonBox.Cancel).clicked.connect(self.cancel) |
|
98 | 102 |
QtCore.QMetaObject.connectSlotsByName(dialog) |
99 | 103 |
|
100 | 104 |
|
... | ... | |
148 | 152 |
else: |
149 | 153 |
return param.setValue(str(widget.text())) |
150 | 154 |
|
151 |
|
|
155 |
@pyqtSlot() |
|
152 | 156 |
def accept(self): |
153 |
try: |
|
154 |
keepOpen = SextanteConfig.getSetting(SextanteConfig.KEEP_DIALOG_OPEN) |
|
155 |
if self.setParamValues(): |
|
156 |
msg = self.alg.checkParameterValuesBeforeExecuting() |
|
157 |
if msg: |
|
158 |
QMessageBox.critical(self.dialog, "Unable to execute algorithm", msg) |
|
159 |
return |
|
160 |
keepOpen = SextanteConfig.getSetting(SextanteConfig.KEEP_DIALOG_OPEN) |
|
161 |
self.buttonBox.button(QtGui.QDialogButtonBox.Ok).setEnabled(False) |
|
162 |
buttons = self.paramTable.iterateButtons |
|
163 |
iterateParam = None |
|
164 |
for i in range(len(buttons.values())): |
|
165 |
button = buttons.values()[i] |
|
166 |
if button.isChecked(): |
|
167 |
iterateParam = buttons.keys()[i] |
|
168 |
break |
|
157 |
#~ try: |
|
158 |
if self.setParamValues(): |
|
159 |
msg = self.alg.checkParameterValuesBeforeExecuting() |
|
160 |
if msg: |
|
161 |
QMessageBox.critical(self.dialog, "Unable to execute algorithm", msg) |
|
162 |
return |
|
163 |
self.buttonBox.button(QtGui.QDialogButtonBox.Ok).setEnabled(False) |
|
164 |
buttons = self.paramTable.iterateButtons |
|
165 |
iterateParam = None |
|
166 |
|
|
167 |
for i in range(len(buttons.values())): |
|
168 |
button = buttons.values()[i] |
|
169 |
if button.isChecked(): |
|
170 |
iterateParam = buttons.keys()[i] |
|
171 |
break |
|
169 | 172 |
|
173 |
self.progress.setMaximum(0) |
|
174 |
self.progressLabel.setText("Processing algorithm...") |
|
175 |
QApplication.setOverrideCursor(QCursor(Qt.WaitCursor)) |
|
176 |
if iterateParam: |
|
177 |
self.algEx = AlgorithmExecutor(self.alg, iterateParam) |
|
178 |
else: |
|
179 |
command = self.alg.getAsCommand() |
|
180 |
if command: |
|
181 |
SextanteLog.addToLog(SextanteLog.LOG_ALGORITHM, command) |
|
182 |
self.algEx = AlgorithmExecutor(self.alg) |
|
183 |
self.algEx.finished.connect(self.finish) |
|
184 |
self.algEx.percentageChanged.connect(self.setPercentage) |
|
185 |
self.algEx.textChanged.connect(self.setText) |
|
186 |
self.algEx.start() |
|
187 |
self.buttonBox.button(QtGui.QDialogButtonBox.Cancel).setEnabled(True) |
|
188 |
else: |
|
189 |
QMessageBox.critical(self.dialog, "Unable to execute algorithm", "Wrong or missing parameter values") |
|
170 | 190 |
|
171 |
self.progress.setMaximum(0) |
|
172 |
self.progressLabel.setText("Processing algorithm...") |
|
173 |
if iterateParam: |
|
174 |
QApplication.setOverrideCursor(QCursor(Qt.WaitCursor)) |
|
175 |
AlgorithmExecutor.runalgIterating(self.alg, iterateParam, self) |
|
176 |
QApplication.restoreOverrideCursor() |
|
177 |
else: |
|
178 |
QApplication.setOverrideCursor(QCursor(Qt.WaitCursor)) |
|
179 |
command = self.alg.getAsCommand() |
|
180 |
if command: |
|
181 |
SextanteLog.addToLog(SextanteLog.LOG_ALGORITHM, command) |
|
182 |
ret = AlgorithmExecutor.runalg(self.alg, self) |
|
183 |
QApplication.restoreOverrideCursor() |
|
184 |
if ret: |
|
185 |
SextantePostprocessing.handleAlgorithmResults(self.alg, not keepOpen) |
|
191 |
@pyqtSlot() |
|
192 |
def finish(self): |
|
193 |
self.dialog.executed = True |
|
194 |
QApplication.restoreOverrideCursor() |
|
186 | 195 |
|
187 |
self.dialog.executed = True |
|
188 |
if not keepOpen: |
|
189 |
self.dialog.close() |
|
190 |
else: |
|
191 |
self.progressLabel.setText("") |
|
192 |
self.progress.setValue(0) |
|
193 |
self.buttonBox.button(QtGui.QDialogButtonBox.Ok).setEnabled(True) |
|
196 |
keepOpen = SextanteConfig.getSetting(SextanteConfig.KEEP_DIALOG_OPEN) |
|
197 |
|
|
198 |
if not keepOpen: |
|
199 |
self.dialog.close() |
|
200 |
else: |
|
201 |
self.progressLabel.setText("") |
|
202 |
self.progress.setValue(0) |
|
203 |
self.buttonBox.button(QtGui.QDialogButtonBox.Ok).setEnabled(True) |
|
204 |
self.buttonBox.button(QtGui.QDialogButtonBox.Cancel).setEnabled(False) |
|
205 |
SextantePostprocessing.handleAlgorithmResults(self.alg, not keepOpen) |
|
194 | 206 |
|
195 |
else: |
|
196 |
QMessageBox.critical(self.dialog, "Unable to execute algorithm", "Wrong or missing parameter values") |
|
197 |
return |
|
198 |
except GeoAlgorithmExecutionException, e : |
|
199 |
QApplication.restoreOverrideCursor() |
|
200 |
QMessageBox.critical(self, "Error",e.msg) |
|
201 |
SextanteLog.addToLog(SextanteLog.LOG_ERROR, e.msg) |
|
202 |
if not keepOpen: |
|
203 |
self.dialog.close() |
|
204 |
else: |
|
205 |
self.progressLabel.setText("") |
|
206 |
self.progress.setValue(0) |
|
207 |
self.buttonBox.button(QtGui.QDialogButtonBox.Ok).setEnabled(True) |
|
207 |
#~ except GeoAlgorithmExecutionException, e : |
|
208 |
#~ QApplication.restoreOverrideCursor() |
|
209 |
#~ QMessageBox.critical(self, "Error",e.msg) |
|
210 |
#~ SextanteLog.addToLog(SextanteLog.LOG_ERROR, e.msg) |
|
211 |
#~ if not keepOpen: |
|
212 |
#~ self.dialog.close() |
|
213 |
#~ else: |
|
214 |
#~ self.progressLabel.setText("") |
|
215 |
#~ self.progress.setValue(0) |
|
216 |
#~ self.buttonBox.button(QtGui.QDialogButtonBox.Ok).setEnabled(True) |
|
208 | 217 |
|
218 |
@pyqtSlot() |
|
219 |
def cancel(self): |
|
220 |
try: |
|
221 |
self.algEx.finished.disconnect() |
|
222 |
self.buttonBox.button(QtGui.QDialogButtonBox.Cancel).setEnabled(False) |
|
223 |
except: |
|
224 |
pass |
|
209 | 225 |
|
210 |
def reject(self): |
|
211 |
self.dialog.close() |
|
212 |
|
|
213 | 226 |
def setPercentage(self, i): |
214 | 227 |
if self.progress.maximum() == 0: |
215 | 228 |
self.progress.setMaximum(100) |
... | ... | |
217 | 230 |
|
218 | 231 |
def setText(self, text): |
219 | 232 |
self.progressLabel.setText(text) |
220 |
|
|
221 |
|
src/sextante/core/GeoAlgorithm.py (working copy) | ||
---|---|---|
112 | 112 |
self.resolveTemporaryOutputs() |
113 | 113 |
self.checkOutputFileExtensions() |
114 | 114 |
try: |
115 |
#~ import pdb; pdb.set_trace() |
|
115 | 116 |
self.processAlgorithm(progress) |
116 | 117 |
return not self.canceled |
117 | 118 |
except GeoAlgorithmExecutionException, gaee: |
src/sextante/core/Sextante.py (working copy) | ||
---|---|---|
3 | 3 |
from sextante.saga.SagaAlgorithmProvider import SagaAlgorithmProvider |
4 | 4 |
from sextante.script.ScriptAlgorithmProvider import ScriptAlgorithmProvider |
5 | 5 |
from sextante.core.QGisLayers import QGisLayers |
6 |
from sextante.gui.AlgorithmExecutor import AlgorithmExecutor, SilentProgress
|
|
6 |
from sextante.gui.AlgorithmExecutor import AlgorithmExecutor |
|
7 | 7 |
from sextante.core.SextanteConfig import SextanteConfig |
8 | 8 |
from sextante.core.SextanteLog import SextanteLog |
9 | 9 |
from sextante.modeler.ModelerAlgorithmProvider import ModelerAlgorithmProvider |
... | ... | |
281 | 281 |
SextanteLog.addToLog(SextanteLog.LOG_ALGORITHM, alg.getAsCommand()) |
282 | 282 |
|
283 | 283 |
QApplication.setOverrideCursor(QCursor(Qt.WaitCursor)) |
284 |
AlgorithmExecutor.runalg(alg, SilentProgress()) |
|
284 |
algEx = AlgorithmExecutor(alg) |
|
285 |
algEx.start() |
|
285 | 286 |
QApplication.restoreOverrideCursor() |
286 | 287 |
return alg.getOutputValuesAsDictionary() |
287 | 288 |
|
... | ... | |
336 | 337 |
return |
337 | 338 |
|
338 | 339 |
QApplication.setOverrideCursor(QCursor(Qt.WaitCursor)) |
339 |
ret = AlgorithmExecutor.runalg(alg, SilentProgress()) |
|
340 |
#~ ret = AlgorithmExecutor.runalg(alg, SilentProgress()) |
|
341 |
algex = AlgorithmExecutor(alg, SilentProgress()) |
|
342 |
algex.start() |
|
340 | 343 |
QApplication.restoreOverrideCursor() |
341 | 344 |
if ret: |
342 | 345 |
SextantePostprocessing.handleAlgorithmResults(alg) |