Wednesday, 7 February 2018

qgis - What happens when you press cancel on a QgsTask?


I'm trying to get the "cancel" to work for my QgsTask, I have created a simple example to illustrate, When I press the "x" i want it to print reslut: None values: False, hence it just finishes without printing anything. If I let it finish (wait for 20 seconds) its prints reslut: None values: True Test QgsTask


import time
def test_task(task):

for i in range(20):
if task.isCanceled():
return False
else:
task.setProgress(i*5)
time.sleep(1)
return True

def end_method(reslut, values):
print('reslut: {r} values: {v}'.format(r=reslut, v=values))


task = QgsTask.fromFunction('Test task', test_task, on_finished=end_method)

QgsApplication.taskManager().addTask(task)

Any thoughts on what I shall use instead of task.isCanceled()? (I'm using QGIS3.2)




No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...