Skip to content
Permalink
Browse files
Improvements to QgsTaskWrapper
  • Loading branch information
nyalldawson committed Dec 5, 2016
1 parent 4291904 commit b065edeed725550a4c834bab84308530cee3ffb1
Showing with 9 additions and 35 deletions.
  1. +9 −35 python/core/__init__.py
@@ -185,51 +185,25 @@ def __exit__(self, ex_type, ex_value, traceback):
return False


class QgsTaskException(Exception):

def __init__(self, msg):
self.msg = msg

def __str__(self):
return self.msg


class QgsTaskResult(Exception):

def __init__(self, r):
self.r = r

def result(self):
return self.r


class QgsTaskWrapper(QgsTask):

def __init__(self, description, function, *extraArgs):
QgsTask.__init__(self, description, QgsTask.ProgressReport)
QgsTask.__init__(self, description)
self.extraArgs = extraArgs
self.function = function
self.task_result = None
self.task_error = None
self.result = None
self.exception = None

def run(self):
try:
for status in self.function(*self.extraArgs):
self.setProgress(status)
except QgsTaskException as e:
self.task_error = e.msg
self.function(self, *self.extraArgs)
except Exception as ex:
# report error
self.exception = ex
self.stopped()
except QgsTaskResult as r:
self.task_result = r.result()
self.completed()
else:
self.completed()

def result(self):
return self.task_result
return

def error(self):
return self.task_error
self.completed()


def fromFunction(cls, description, function, extraArgs):

0 comments on commit b065ede

Please sign in to comment.