Skip to content
Permalink
Browse files
Add some python docstrings to QgsTask.fromFunction
  • Loading branch information
nyalldawson committed Dec 5, 2016
1 parent feb3219 commit d03d0a5b474d3955a20405ea0b9bc93a78227a24
Showing with 24 additions and 0 deletions.
  1. +24 −0 python/core/__init__.py
@@ -236,6 +236,30 @@ def finished(self, result):

@staticmethod
def fromFunction(description, function, *args, on_finished=None, flags=QgsTask.AllFlags, **kwargs):
"""
Creates a new QgsTask task from a python function.
Example:
def calculate(task):
# pretend this is some complex maths and stuff we want
# to run in the background
return 5*6
def calculation_finished(exception, value=None):
if not exception:
iface.messageBar().pushMessage(
'the magic number is {}'.format(value))
else:
iface.messageBar().pushMessage(
str(exception))
task = QgsTask.fromFunction('my task', calculate,
on_finished=calculation_finished)
QgsTaskManager.instance().addTask(task)
"""

assert function
return QgsTaskWrapper(description, flags, function, on_finished, *args, **kwargs)

0 comments on commit d03d0a5

Please sign in to comment.