-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow QgsTask subclasses to defined a finished function, which is
called when the task has completed (successfully or otherwise). This allows for simpler task design when the signal/slot based approach is not required. Just implement run() with your heavy lifting, and finished() to do whatever follow up stuff should happen after the task is complete. finished is always called from the main thread, so it's safe to do GUI operations here. Python based tasks using the simplified QgsTask.fromFunction approach can now set a on_finished argument to a function to call when the task is complete. eg: def calculate(task): # pretend this is some complex maths and stuff we want # to run in the background return 5*6 def calculation_finished(result, value=None): if result == QgsTask.ResultSuccess: iface.messageBar().pushMessage( 'the magic number is {}'.format(value)) elif result == QgsTask.ResultFail: iface.messageBar().pushMessage( 'couldn\'t work it out, sorry') task = QgsTask.fromFunction('my task', calculate, on_finished=calculation_finished) QgsTaskManager.instance().addTask(task) Multiple values can also be returned, eg: def calculate(task): return (4, 8, 15) def calculation_finished(result, count=None, max=None, sum=None): # here: # count = 4 # max = 8 # sum = 15 task = QgsTask.fromFunction('my task', calculate, on_finished=calculation_finished) QgsTaskManager.instance().addTask(task)
- Loading branch information
1 parent
252f2e1
commit 6d4392a
Showing
7 changed files
with
236 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.