mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-13 00:03:09 -04:00
Add some python docstrings to QgsTask.fromFunction
This commit is contained in:
parent
feb3219852
commit
d03d0a5b47
@ -236,6 +236,30 @@ class QgsTaskWrapper(QgsTask):
|
||||
|
||||
@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)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user