* morituri/common/task.py:

Update the docs.
This commit is contained in:
Thomas Vander Stichele
2009-04-12 08:34:44 +00:00
parent 28bd15952b
commit 10647d18a1
2 changed files with 18 additions and 0 deletions

View File

@@ -1,3 +1,8 @@
2009-04-12 Thomas Vander Stichele <thomas at apestaart dot org>
* morituri/common/task.py:
Update the docs.
2009-04-12 Thomas Vander Stichele <thomas at apestaart dot org>
* morituri/test/test_image_image.py (added):

View File

@@ -43,6 +43,8 @@ class Task(object):
### subclass methods
def start(self):
"""
Start the task.
Subclasses should chain up to me at the beginning.
"""
self.progress = 0.0
@@ -51,6 +53,8 @@ class Task(object):
def stop(self):
"""
Stop the task.
Subclasses should chain up to me at the end.
"""
self.debug('stopping')
@@ -64,12 +68,21 @@ class Task(object):
sys.stdout.flush()
def setProgress(self, value):
"""
Notify about progress changes bigger than the increment.
Called by subclass implementations as the task progresses.
"""
if value - self.progress > self.increment or value >= 1.0:
self.progress = value
self._notifyListeners('progressed', value)
self.debug('notifying progress', value)
def addListener(self, listener):
"""
Add a listener for task status changes.
Listeners should implement started, stopped, and progressed.
"""
if not self._listeners:
self._listeners = []
self._listeners.append(listener)