* examples/gtkcrc.py:
* morituri/common/task.py: Move the gtk-based progress bar to task.
This commit is contained in:
@@ -23,6 +23,7 @@
|
||||
import sys
|
||||
|
||||
import gobject
|
||||
import gtk
|
||||
|
||||
class Task(object):
|
||||
"""
|
||||
@@ -95,6 +96,22 @@ class Task(object):
|
||||
for l in self._listeners:
|
||||
getattr(l, methodName)(self, *args, **kwargs)
|
||||
|
||||
# this is a Dummy task that can be used if this works at all
|
||||
class DummyTask(Task):
|
||||
def start(self, runner):
|
||||
Task.start(self, runner)
|
||||
self.runner.schedule(1.0, self._wind)
|
||||
|
||||
def _wind(self):
|
||||
self.setProgress(min(self.progress + 0.1, 1.0))
|
||||
|
||||
if self.progress >= 1.0:
|
||||
self.stop()
|
||||
return
|
||||
|
||||
self.runner.schedule(1.0, self._wind)
|
||||
|
||||
|
||||
class TaskRunner:
|
||||
"""
|
||||
I am a base class for task runners.
|
||||
@@ -181,3 +198,50 @@ class SyncRunner(TaskRunner):
|
||||
|
||||
def stopped(self, task):
|
||||
self._loop.quit()
|
||||
|
||||
|
||||
class GtkProgressRunner(gtk.VBox, TaskRunner):
|
||||
"""
|
||||
I am a widget that shows progress on a task.
|
||||
"""
|
||||
|
||||
__gsignals__ = {
|
||||
'stop': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, ())
|
||||
}
|
||||
|
||||
def __init__(self):
|
||||
gtk.VBox.__init__(self)
|
||||
self.set_border_width(6)
|
||||
self.set_spacing(6)
|
||||
|
||||
self._label = gtk.Label()
|
||||
self.add(self._label)
|
||||
|
||||
self._progress = gtk.ProgressBar()
|
||||
self.add(self._progress)
|
||||
|
||||
def run(self, task):
|
||||
self._task = task
|
||||
self._label.set_text(task.description)
|
||||
task.addListener(self)
|
||||
while gtk.events_pending():
|
||||
gtk.main_iteration()
|
||||
task.start(self)
|
||||
|
||||
def schedule(self, delta, callable, *args, **kwargs):
|
||||
def c():
|
||||
callable(*args, **kwargs)
|
||||
return False
|
||||
gobject.timeout_add(int(delta * 1000L), c)
|
||||
|
||||
def started(self, task):
|
||||
pass
|
||||
|
||||
def stopped(self, task):
|
||||
self.emit('stop')
|
||||
# self._task.removeListener(self)
|
||||
|
||||
def progressed(self, task, value):
|
||||
self._progress.set_fraction(value)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user