Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add some python docstrings to QgsTask.fromFunction
  • Loading branch information
nyalldawson committed Dec 5, 2016
1 parent feb3219 commit d03d0a5
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions python/core/__init__.py
Expand Up @@ -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)

Expand Down

0 comments on commit d03d0a5

Please sign in to comment.