Skip to content

Commit

Permalink
Improvements to QgsTaskWrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Dec 5, 2016
1 parent 4291904 commit b065ede
Showing 1 changed file with 9 additions and 35 deletions.
44 changes: 9 additions & 35 deletions python/core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit b065ede

Please sign in to comment.