[SCM] morituri/master: * examples/gtkcrc.py: * morituri/common/task.py: Move the gtk-based progress bar to task.
js at users.alioth.debian.org
js at users.alioth.debian.org
Sun Oct 19 20:08:45 UTC 2014
The following commit has been merged in the master branch:
commit d47402af60f9b5e4ed336c6dff93fc1b181a841a
Author: Thomas Vander Stichele <thomas (at) apestaart (dot) org>
Date: Sun Apr 12 08:58:36 2009 +0000
* examples/gtkcrc.py:
* morituri/common/task.py:
Move the gtk-based progress bar to task.
diff --git a/ChangeLog b/ChangeLog
index a96f263..d8be26e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,6 +1,12 @@
2009-04-12 Thomas Vander Stichele <thomas at apestaart dot org>
* examples/gtkcrc.py:
+ * morituri/common/task.py:
+ Move the gtk-based progress bar to task.
+
+2009-04-12 Thomas Vander Stichele <thomas at apestaart dot org>
+
+ * examples/gtkcrc.py:
* morituri/common/crc.py:
* morituri/common/task.py:
* morituri/image/image.py:
diff --git a/examples/gtkcrc.py b/examples/gtkcrc.py
index 86f8caa..69ff99e 100644
--- a/examples/gtkcrc.py
+++ b/examples/gtkcrc.py
@@ -32,50 +32,6 @@ import gtk
from morituri.common import task, crc
-class TaskProgress(gtk.VBox, task.TaskRunner):
- __gsignals__ = {
- 'stop': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, ())
- }
-
- def __init__(self):
- gst.info('__init__')
- 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):
- gst.info('progressed')
- # FIXME: why is this not painting the progress bar ?
- self._progress.set_fraction(value)
-
-
path = 'test.flac'
start = 0
@@ -97,25 +53,8 @@ except:
crctask = crc.CRC32Task(path, start, end)
-# this is a Dummy task that can be used if this works at all
-class DummyTask(task.Task):
- def start(self):
- task.Task.start(self)
- gobject.timeout_add(1000L, self._wind)
-
- def _wind(self):
- self.setProgress(min(self.progress + 0.1, 1.0))
-
- if self.progress >= 1.0:
- self.stop()
- return
-
- gobject.timeout_add(1000L, self._wind)
-
-#crctask = DummyTask()
-
window = gtk.Window()
-progress = TaskProgress()
+progress = task.GtkProgressRunner()
progress.connect('stop', lambda _: gtk.main_quit())
window.add(progress)
window.show_all()
diff --git a/morituri/common/task.py b/morituri/common/task.py
index 948d35f..275b36f 100644
--- a/morituri/common/task.py
+++ b/morituri/common/task.py
@@ -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)
+
+
--
morituri packaging
More information about the pkg-multimedia-commits
mailing list