From 729280ef427fe3f1af013d4f6e002b501e553021 Mon Sep 17 00:00:00 2001 From: Thomas Vander Stichele Date: Sun, 12 Apr 2009 11:15:45 +0000 Subject: [PATCH] * examples/ARcue.py: Add option to run either command-line or gtk. --- ChangeLog | 5 +++++ examples/ARcue.py | 55 ++++++++++++++++++++++++++++++++++++----------- 2 files changed, 48 insertions(+), 12 deletions(-) diff --git a/ChangeLog b/ChangeLog index 6a898c6..a9037db 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2009-04-12 Thomas Vander Stichele + + * examples/ARcue.py: + Add option to run either command-line or gtk. + 2009-04-12 Thomas Vander Stichele * morituri/image/image.py: diff --git a/examples/ARcue.py b/examples/ARcue.py index df6915c..c87dcdc 100644 --- a/examples/ARcue.py +++ b/examples/ARcue.py @@ -21,29 +21,60 @@ # along with morituri. If not, see . import sys +import optparse import gobject gobject.threads_init() +import gtk from morituri.image import image from morituri.common import task, crc -def main(path): +def gtkmain(taskk): + progress = task.GtkProgressRunner() + progress.connect('stop', lambda _: gtk.main_quit()) + + window = gtk.Window() + window.add(progress) + window.show_all() + + progress.run(taskk) + + gtk.main() + +def climain(taskk): runner = task.SyncRunner() - cueImage = image.Image(path) + runner.run(taskk) + +def main(argv): + parser = optparse.OptionParser() + + default = 'cli' + parser.add_option('-r', '--runner', + action="store", dest="runner", + help="runner ('cli' or 'gtk', defaults to %s)" % default, + default=default) + + options, args = parser.parse_args(argv[1:]) + + path = 'test.cue' + + try: + path = sys.argv[1] + except IndexError: + pass + + cueImage = image.Image(path) cuetask = image.AudioRipCRCTask(cueImage) - runner.run(cuetask) + + if options.runner == 'cli': + climain(cuetask) + elif options.runner == 'gtk': + gtkmain(cuetask) for i, crc in enumerate(cuetask.crcs): - print "Track %2d: %08x" % (i, crc) + print "Track %2d: %08x" % (i + 1, crc) -path = 'test.cue' - -try: - path = sys.argv[1] -except IndexError: - pass - -main(path) +main(sys.argv)