@@ -73,6 +73,9 @@ def __init__(self, alg, in_place=False, parent=None):
73
73
self .in_place = in_place
74
74
self .active_layer = None
75
75
76
+ self .context = None
77
+ self .feedback = None
78
+
76
79
self .setAlgorithm (alg )
77
80
self .setMainWidget (self .getParametersPanel (alg , self ))
78
81
@@ -160,14 +163,14 @@ def getParameterValues(self):
160
163
return self .algorithm ().preprocessParameters (parameters )
161
164
162
165
def runAlgorithm (self ):
163
- feedback = self .createFeedback ()
164
- context = dataobjects .createContext (feedback )
166
+ self . feedback = self .createFeedback ()
167
+ self . context = dataobjects .createContext (self . feedback )
165
168
166
169
checkCRS = ProcessingConfig .getSetting (ProcessingConfig .WARN_UNMATCHING_CRS )
167
170
try :
168
171
parameters = self .getParameterValues ()
169
172
170
- if checkCRS and not self .algorithm ().validateInputCrs (parameters , context ):
173
+ if checkCRS and not self .algorithm ().validateInputCrs (parameters , self . context ):
171
174
reply = QMessageBox .question (self , self .tr ("Unmatching CRS's" ),
172
175
self .tr ('Parameters do not all use the same CRS. This can '
173
176
'cause unexpected results.\n Do you want to '
@@ -176,7 +179,7 @@ def runAlgorithm(self):
176
179
QMessageBox .No )
177
180
if reply == QMessageBox .No :
178
181
return
179
- ok , msg = self .algorithm ().checkParameterValues (parameters , context )
182
+ ok , msg = self .algorithm ().checkParameterValues (parameters , self . context )
180
183
if not ok :
181
184
QMessageBox .warning (
182
185
self , self .tr ('Unable to execute algorithm' ), msg )
@@ -198,12 +201,12 @@ def runAlgorithm(self):
198
201
self .setInfo (
199
202
QCoreApplication .translate ('AlgorithmDialog' , '<b>Algorithm \' {0}\' starting…</b>' ).format (self .algorithm ().displayName ()), escapeHtml = False )
200
203
201
- feedback .pushInfo (self .tr ('Input parameters:' ))
204
+ self . feedback .pushInfo (self .tr ('Input parameters:' ))
202
205
display_params = []
203
206
for k , v in parameters .items ():
204
- display_params .append ("'" + k + "' : " + self .algorithm ().parameterDefinition (k ).valueAsPythonString (v , context ))
205
- feedback .pushCommandInfo ('{ ' + ', ' .join (display_params ) + ' }' )
206
- feedback .pushInfo ('' )
207
+ display_params .append ("'" + k + "' : " + self .algorithm ().parameterDefinition (k ).valueAsPythonString (v , self . context ))
208
+ self . feedback .pushCommandInfo ('{ ' + ', ' .join (display_params ) + ' }' )
209
+ self . feedback .pushInfo ('' )
207
210
start_time = time .time ()
208
211
209
212
if self .iterateParam :
@@ -215,30 +218,30 @@ def runAlgorithm(self):
215
218
pass
216
219
217
220
self .cancelButton ().setEnabled (self .algorithm ().flags () & QgsProcessingAlgorithm .FlagCanCancel )
218
- if executeIterating (self .algorithm (), parameters , self .iterateParam , context , feedback ):
219
- feedback .pushInfo (
221
+ if executeIterating (self .algorithm (), parameters , self .iterateParam , self . context , self . feedback ):
222
+ self . feedback .pushInfo (
220
223
self .tr ('Execution completed in {0:0.2f} seconds' ).format (time .time () - start_time ))
221
224
self .cancelButton ().setEnabled (False )
222
- self .finish (True , parameters , context , feedback )
225
+ self .finish (True , parameters , self . context , self . feedback )
223
226
else :
224
227
self .cancelButton ().setEnabled (False )
225
228
self .resetGui ()
226
229
else :
227
- command = self .algorithm ().asPythonCommand (parameters , context )
230
+ command = self .algorithm ().asPythonCommand (parameters , self . context )
228
231
if command :
229
232
ProcessingLog .addToLog (command )
230
233
QgsGui .instance ().processingRecentAlgorithmLog ().push (self .algorithm ().id ())
231
234
self .cancelButton ().setEnabled (self .algorithm ().flags () & QgsProcessingAlgorithm .FlagCanCancel )
232
235
233
236
def on_complete (ok , results ):
234
237
if ok :
235
- feedback .pushInfo (self .tr ('Execution completed in {0:0.2f} seconds' ).format (time .time () - start_time ))
236
- feedback .pushInfo (self .tr ('Results:' ))
237
- feedback .pushCommandInfo (pformat (results ))
238
+ self . feedback .pushInfo (self .tr ('Execution completed in {0:0.2f} seconds' ).format (time .time () - start_time ))
239
+ self . feedback .pushInfo (self .tr ('Results:' ))
240
+ self . feedback .pushCommandInfo (pformat (results ))
238
241
else :
239
- feedback .reportError (
242
+ self . feedback .reportError (
240
243
self .tr ('Execution failed after {0:0.2f} seconds' ).format (time .time () - start_time ))
241
- feedback .pushInfo ('' )
244
+ self . feedback .pushInfo ('' )
242
245
243
246
if self .feedback_dialog is not None :
244
247
self .feedback_dialog .close ()
@@ -248,28 +251,31 @@ def on_complete(ok, results):
248
251
self .cancelButton ().setEnabled (False )
249
252
250
253
if not self .in_place :
251
- self .finish (ok , results , context , feedback )
254
+ self .finish (ok , results , self . context , self . feedback )
252
255
elif ok :
253
256
self .close ()
254
257
258
+ self .feedback = None
259
+ self .context = None
260
+
255
261
if not self .in_place and not (self .algorithm ().flags () & QgsProcessingAlgorithm .FlagNoThreading ):
256
262
# Make sure the Log tab is visible before executing the algorithm
257
263
self .showLog ()
258
264
259
- task = QgsProcessingAlgRunnerTask (self .algorithm (), parameters , context , feedback )
265
+ task = QgsProcessingAlgRunnerTask (self .algorithm (), parameters , self . context , self . feedback )
260
266
task .executed .connect (on_complete )
261
267
self .setCurrentTask (task )
262
268
else :
263
269
self .proxy_progress = QgsProxyProgressTask (QCoreApplication .translate ("AlgorithmDialog" , "Executing “{}”" ).format (self .algorithm ().displayName ()))
264
270
QgsApplication .taskManager ().addTask (self .proxy_progress )
265
- feedback .progressChanged .connect (self .proxy_progress .setProxyProgress )
271
+ self . feedback .progressChanged .connect (self .proxy_progress .setProxyProgress )
266
272
self .feedback_dialog = self .createProgressDialog ()
267
273
self .feedback_dialog .show ()
268
274
if self .in_place :
269
- ok , results = execute_in_place (self .algorithm (), parameters , context , feedback )
275
+ ok , results = execute_in_place (self .algorithm (), parameters , self . context , self . feedback )
270
276
else :
271
- ok , results = execute (self .algorithm (), parameters , context , feedback )
272
- feedback .progressChanged .disconnect ()
277
+ ok , results = execute (self .algorithm (), parameters , self . context , self . feedback )
278
+ self . feedback .progressChanged .disconnect ()
273
279
self .proxy_progress .finalize (ok )
274
280
on_complete (ok , results )
275
281
0 commit comments