From f5d3ebdc108980580569f32352cdb9c6de3a401c Mon Sep 17 00:00:00 2001 From: Aleksey Lim Date: Mon, 02 Feb 2009 10:39:23 +0000 Subject: Rename files --- diff --git a/Activity.py b/activity.py index bfa66a3..b272763 100644 --- a/Activity.py +++ b/activity.py @@ -24,13 +24,13 @@ from gettext import gettext as _ from sugar.activity.activity import get_activity_root -import Montage -import Lessons -import Document -import Char -import Ground -import Sound -from Toolbars import * +import montage +import lessons +import document +import char +import ground +import sound +from toolbars import * SERVICE = 'org.freedesktop.Telepathy.Tube.Connect' IFACE = SERVICE @@ -46,11 +46,13 @@ class CartoonBuilderActivity(activity.Activity): self.notebook.show() self.notebook.props.show_border = False self.notebook.props.show_tabs = False + # XXX do it after(possible) read_file() invoking + # have to rely on calling read_file() from map_cb in sugar-toolkit self.notebook.connect_after('map', self._map_cb) - self.montage = Montage.View() + self.montage = montage.View() self.notebook.append_page(self.montage) - self.lessons = Lessons.View() + self.lessons = lessons.View() self.lessons.show() self.notebook.append_page(self.lessons) @@ -99,13 +101,13 @@ class CartoonBuilderActivity(activity.Activity): """ def read_file(self, filepath): - Document.load(filepath) - Char.load() - Ground.load() - Sound.load() + document.load(filepath) + char.load() + ground.load() + sound.load() def write_file(self, filepath): - Document.save(filepath) + document.save(filepath) def _map_cb(self, widget): self.montage.restore() diff --git a/activity/activity.info b/activity/activity.info index ca1c51d..a754f9a 100644 --- a/activity/activity.info +++ b/activity/activity.info @@ -1,7 +1,7 @@ [Activity] name = CartoonBuilder service_name = com.ywwg.CartoonBuilderActivity -class = Activity.CartoonBuilderActivity +class = activity.CartoonBuilderActivity icon = activity-cartoonbuilder activity_version = 1 show_launcher = yes diff --git a/Char.py b/char.py index d7c9efe..de43e0f 100644 --- a/Char.py +++ b/char.py @@ -17,8 +17,8 @@ import gtk import glob from gettext import gettext as _ -import Theme -from Document import Document +import theme +from document import Document PREINSTALLED = 0 CUSTOM = 1 @@ -28,33 +28,33 @@ def load(): index = 0 loaded = {} - for i in range(Theme.TAPE_COUNT): + for i in range(theme.TAPE_COUNT): orig = Document.tape[i].orig if Document.tape[i].filename or loaded.has_key(orig): continue loaded[orig] = True custom._origs[index] = orig - custom._thumbs[index] = Theme.scale(orig) + custom._thumbs[index] = theme.scale(orig) index += 1 class Char: def __init__(self, name, file, dir, type): self.name = name - self._thumb = Theme.pixbuf(file, Theme.THUMB_SIZE) + self._thumb = theme.pixbuf(file, theme.THUMB_SIZE) self._type = type self._thumbs = {} self._origs = {} self._filenames = [] if type != CUSTOM: - for i in sorted(glob.glob(Theme.path(dir, '*'))): + for i in sorted(glob.glob(theme.path(dir, '*'))): self._filenames.append(os.path.join(dir, os.path.basename(i))) def filename(self, index): if self._type == CUSTOM: return None elif index >= len(self._filenames): - return Theme.EMPTY_FILENAME + return theme.EMPTY_FILENAME else: return self._filenames[index] @@ -69,9 +69,9 @@ class Char: pix = self._thumb else: if index < len(self._filenames): - pix = Theme.pixbuf(self._filenames[index], Theme.THUMB_SIZE) + pix = theme.pixbuf(self._filenames[index], theme.THUMB_SIZE) else: - pix = Theme.EMPTY_THUMB + pix = theme.EMPTY_THUMB self._thumbs[index] = pix return pix @@ -81,16 +81,16 @@ class Char: if pix == None: if self._type == CUSTOM: - pix = Theme.choose(lambda t, file: Theme.pixbuf(file)) + pix = theme.choose(lambda t, file: theme.pixbuf(file)) if pix: - self._thumbs[index] = Theme.scale(pix) + self._thumbs[index] = theme.scale(pix) self._origs[index] = pix else: if index < len(self._filenames): - pix = Theme.pixbuf(self._filenames[index]) + pix = theme.pixbuf(self._filenames[index]) self._origs[index] = pix else: - pix = Theme.EMPTY_ORIG + pix = theme.EMPTY_ORIG return pix diff --git a/Document.py b/document.py index a700f75..e7c3ba8 100644 --- a/Document.py +++ b/document.py @@ -16,8 +16,8 @@ import os import gtk from xml.etree.ElementTree import Element, SubElement, tostring, fromstring -import Theme -import Utils +import theme +from utils import * class Document: tape = [] @@ -34,14 +34,14 @@ class Document: self.clean() def clean(self): - self.orig = Theme.EMPTY_ORIG - self.filename = Theme.EMPTY_FILENAME + self.orig = theme.EMPTY_ORIG + self.filename = theme.EMPTY_FILENAME - for i in range(Theme.TAPE_COUNT): + for i in range(theme.TAPE_COUNT): tape.append(Tape()) def save(filepath): - zip = Utils.Zip(filepath, 'w') + zip = Zip(filepath, 'w') manifest = Element('memorize') ground = SubElement(manifest, 'ground') @@ -66,7 +66,7 @@ def save(filepath): saved = {} tape = SubElement(manifest, 'tape') - for i in range(Theme.TAPE_COUNT): + for i in range(theme.TAPE_COUNT): frame = SubElement(tape, 'frame') if Document.tape[i].filename: frame.attrib['preinstalled'] = '1' @@ -83,12 +83,12 @@ def save(filepath): zip.close() def load(filepath): - zip = Utils.Zip(filepath, 'r') + zip = Zip(filepath, 'r') manifest = fromstring(zip.read('MANIFEST.xml')) ground = manifest.find('ground') if int(ground.attrib['preinstalled']): - Document.ground_orig = Theme.pixbuf(ground.attrib['filename']) + Document.ground_orig = theme.pixbuf(ground.attrib['filename']) Document.ground_filename = ground.attrib['filename'] else: Document.ground_orig = zip.read_pixbuf(ground.attrib['filename']) @@ -99,20 +99,20 @@ def load(filepath): Document.sound_filename = sound.attrib['filename'] else: arcfile = sound.attrib['filename'] - sndfile = os.path.join(Theme.SESSION_PATH, 'sound.001') + sndfile = os.path.join(theme.SESSION_PATH, 'sound.001') file(sndfile, 'w').write(zip.read(arcfile)) Document.sound_filename = sndfile Document.sound_name = sound.text loaded = {} for i, frame in enumerate(manifest.findall('tape/frame')): - if i >= Theme.TAPE_COUNT: + if i >= theme.TAPE_COUNT: continue if int(frame.attrib['preinstalled']): - if frame.attrib['filename'] == Theme.EMPTY_FILENAME: - Document.tape[i].orig = Theme.EMPTY_ORIG + if frame.attrib['filename'] == theme.EMPTY_FILENAME: + Document.tape[i].orig = theme.EMPTY_ORIG else: - Document.tape[i].orig = Theme.pixbuf(frame.attrib['filename']) + Document.tape[i].orig = theme.pixbuf(frame.attrib['filename']) Document.tape[i].filename = frame.attrib['filename'] else: pixbuf = loaded.get(frame.attrib['filename']) diff --git a/Ground.py b/ground.py index a200281..95e1b4b 100644 --- a/Ground.py +++ b/ground.py @@ -17,8 +17,8 @@ from gettext import gettext as _ from sugar.graphics.objectchooser import ObjectChooser -import Theme -from Document import Document +import theme +from document import Document PREINSTALLED = 0 CUSTOM = 1 @@ -34,7 +34,7 @@ class Ground: def __init__(self, name, file, type): self.name = name self._file = file - if file: self._pixbuf = Theme.pixbuf(file) + if file: self._pixbuf = theme.pixbuf(file) self._type = type self._thumb = None @@ -46,7 +46,7 @@ class Ground: def thumb(self): if not self._thumb: - self._thumb = Theme.scale(self._pixbuf) + self._thumb = theme.scale(self._pixbuf) return self._thumb def orig(self): @@ -55,7 +55,7 @@ class Ground: def change(self): if self._type != CUSTOM: return self - return Theme.choose(lambda title, file: Ground(title, file, TEMPORARY)) + return theme.choose(lambda title, file: Ground(title, file, TEMPORARY)) THEMES = [ Ground(_('Saturn'), 'images/backpics/bigbg01.gif', PREINSTALLED), diff --git a/Lessons.py b/lessons.py index 060db1e..2766e0b 100644 --- a/Lessons.py +++ b/lessons.py @@ -18,7 +18,7 @@ import locale import logging from glob import glob -import Theme +import theme THEMES = [] @@ -51,12 +51,12 @@ class View(gtk.EventBox): view_box = gtk.EventBox() view_box.add(view) - view_box.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse(Theme.WHITE)) + view_box.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse(theme.WHITE)) view_box.props.border_width = 10 border_box = gtk.EventBox() border_box.add(view_box) - border_box.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse(Theme.WHITE)) + border_box.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse(theme.WHITE)) scrolled_window = gtk.ScrolledWindow() scrolled_window.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC) @@ -68,9 +68,9 @@ class View(gtk.EventBox): _lang = locale.getdefaultlocale()[0].split('_')[0] -if not os.path.isdir(Theme.path('lessons', _lang)): +if not os.path.isdir(theme.path('lessons', _lang)): logging.info('Cannot find lessons for language %s, thus use en' % _lang) _lang = 'en' -for i, filename in enumerate(sorted(glob(Theme.path('lessons', _lang, '*')))): +for i, filename in enumerate(sorted(glob(theme.path('lessons', _lang, '*')))): THEMES.append(Lesson(i, filename)) diff --git a/Montage.py b/montage.py index e9608c1..c080ac2 100644 --- a/Montage.py +++ b/montage.py @@ -21,12 +21,12 @@ import gtk import gobject -import Theme -import Char -import Ground -import Sound -from Document import Document -from Utils import * +import theme +import char +import ground +import sound +from document import Document +from utils import * def play(): View.play_tape_num = 0 @@ -44,7 +44,7 @@ def set_tempo(tempo): def clear_tape(): for i in range(TAPE_COUNT): Document.tape[i].clean() - View.tape[i].child.set_from_pixbuf(Theme.EMPTY_THUMB) + View.tape[i].child.set_from_pixbuf(theme.EMPTY_THUMB) View.screen.fgpixbuf = Document.tape[View.tape_selected].orig View.screen.draw() @@ -56,11 +56,11 @@ def _play_tape(): View.screen.fgpixbuf = Document.tape[View.play_tape_num].orig View.screen.draw() - for i in range(Theme.TAPE_COUNT): + for i in range(theme.TAPE_COUNT): View.play_tape_num += 1 if View.play_tape_num == TAPE_COUNT: View.play_tape_num = 0 - if Document.tape[View.play_tape_num].orig == Theme.EMPTY_ORIG: + if Document.tape[View.play_tape_num].orig == theme.EMPTY_ORIG: continue return True @@ -91,13 +91,13 @@ class View(gtk.EventBox): if self.bgpixbuf: pixbuf = self.bgpixbuf if pixbuf.get_width != self.width: - pixbuf = Theme.scale(pixbuf, self.width) + pixbuf = theme.scale(pixbuf, self.width) widget.window.draw_pixbuf(self.gc, pixbuf, 0, 0, 0, 0, -1, -1, 0, 0) if self.fgpixbuf: pixbuf = self.fgpixbuf if pixbuf.get_width != self.width: - pixbuf = Theme.scale(pixbuf, self.width) + pixbuf = theme.scale(pixbuf, self.width) widget.window.draw_pixbuf(self.gc, pixbuf, 0, 0, 0, 0, -1, -1, 0, 0) def draw(self): @@ -123,21 +123,21 @@ class View(gtk.EventBox): rows = max((DESKTOP_HEIGHT - THUMB_SIZE*3) / THUMB_SIZE, int(ceil(float(FRAME_COUNT) / FRAME_COLS))) - self.table = gtk.Table(rows, columns=Theme.FRAME_COLS, homogeneous=False) + self.table = gtk.Table(rows, columns=theme.FRAME_COLS, homogeneous=False) for y in range(rows): - for x in range(Theme.FRAME_COLS): + for x in range(theme.FRAME_COLS): image = gtk.Image() self._frames.append(image) image_box = gtk.EventBox() image_box.set_events(gtk.gdk.BUTTON_PRESS_MASK) image_box.connect('button_press_event', self._frame_cb, - y * Theme.FRAME_COLS + x) + y * theme.FRAME_COLS + x) image_box.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse(BLACK)) image_box.modify_bg(gtk.STATE_PRELIGHT, gtk.gdk.color_parse(BLACK)) image_box.props.border_width = 2 - image_box.set_size_request(Theme.THUMB_SIZE, Theme.THUMB_SIZE) + image_box.set_size_request(theme.THUMB_SIZE, theme.THUMB_SIZE) image_box.add(image) self.table.attach(image_box, x, x+1, y, y+1) @@ -157,7 +157,7 @@ class View(gtk.EventBox): yellow_frames.add(table_frames) yelow_arrow = gtk.Image() - yelow_arrow.set_from_file(Theme.path('icons', 'yellow_arrow.png')) + yelow_arrow.set_from_file(theme.path('icons', 'yellow_arrow.png')) frames_box = gtk.VBox() frames_box.pack_start(yellow_frames, True, True) @@ -182,7 +182,7 @@ class View(gtk.EventBox): frame_box = gtk.VBox() filmstrip_pixbuf = gtk.gdk.pixbuf_new_from_file_at_scale( - Theme.path('icons', 'filmstrip.png'), THUMB_SIZE, -1, False) + theme.path('icons', 'filmstrip.png'), THUMB_SIZE, -1, False) filmstrip = gtk.Image() filmstrip.set_from_pixbuf(filmstrip_pixbuf); @@ -194,12 +194,12 @@ class View(gtk.EventBox): frame.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse(BLACK)) frame.modify_bg(gtk.STATE_PRELIGHT, gtk.gdk.color_parse(BLACK)) frame.props.border_width = 2 - frame.set_size_request(Theme.THUMB_SIZE, Theme.THUMB_SIZE) + frame.set_size_request(theme.THUMB_SIZE, theme.THUMB_SIZE) frame_box.pack_start(frame) View.tape.append(frame) frame_image = gtk.Image() - frame_image.set_from_pixbuf(Theme.EMPTY_THUMB) + frame_image.set_from_pixbuf(theme.EMPTY_THUMB) frame.add(frame_image) filmstrip = gtk.Image() @@ -216,7 +216,7 @@ class View(gtk.EventBox): leftbox = gtk.VBox() logo = gtk.Image() - logo.set_from_file(Theme.path('icons', 'logo.png')) + logo.set_from_file(theme.path('icons', 'logo.png')) leftbox.set_size_request(logo.props.pixbuf.get_width(), -1) leftbox.pack_start(logo, False, False) leftbox.pack_start(self.controlbox, True, True) @@ -242,7 +242,7 @@ class View(gtk.EventBox): gtk.gdk.color_parse(BUTTON_BACKGROUND)) arrow = gtk.Image() - arrow.set_from_file(Theme.path('icons', 'pink_arrow.png')) + arrow.set_from_file(theme.path('icons', 'pink_arrow.png')) animborder = gtk.EventBox() animborder.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse(PINK)) animframe = gtk.EventBox() @@ -274,12 +274,12 @@ class View(gtk.EventBox): combo = ComboBox() sel = 0 - for i, theme in enumerate(themes): - if theme: - combo.append_item(theme, text = theme.name, - size = (Theme.THUMB_SIZE, Theme.THUMB_SIZE), - pixbuf = theme.thumb()) - if theme.name == selname: + for i, o in enumerate(themes): + if o: + combo.append_item(o, text = o.name, + size = (theme.THUMB_SIZE, theme.THUMB_SIZE), + pixbuf = o.thumb()) + if o.name == selname: sel = i else: combo.append_separator() @@ -290,15 +290,15 @@ class View(gtk.EventBox): return combo - self.controlbox.pack_start(new_combo(Char.THEMES, self._char_cb), + self.controlbox.pack_start(new_combo(char.THEMES, self._char_cb), True, False) - self.controlbox.pack_start(new_combo(Ground.THEMES, self._combo_cb, + self.controlbox.pack_start(new_combo(ground.THEMES, self._combo_cb, Document.ground_name, self._ground_cb), True, False) - self.controlbox.pack_start(new_combo(Sound.THEMES, self._combo_cb, + self.controlbox.pack_start(new_combo(sound.THEMES, self._combo_cb, Document.sound_name, self._sound_cb), True, False) - for i in range(Theme.TAPE_COUNT): - View.tape[i].child.set_from_pixbuf(Theme.scale(Document.tape[i].orig)) + for i in range(theme.TAPE_COUNT): + View.tape[i].child.set_from_pixbuf(theme.scale(Document.tape[i].orig)) self._tape_cb(None, None, 0) return False @@ -306,7 +306,7 @@ class View(gtk.EventBox): def _tape_cb(self, widget, event, index): if event and event.button == 3: Document.tape[index].clean() - View.tape[index].child.set_from_pixbuf(Theme.EMPTY_THUMB) + View.tape[index].child.set_from_pixbuf(theme.EMPTY_THUMB) tape = View.tape[index] tape.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse(YELLOW)) @@ -355,7 +355,7 @@ class View(gtk.EventBox): if id(choice) != id(widget.props.value): pos = widget.get_active() widget.append_item(choice, text = choice.name, - size = (Theme.THUMB_SIZE, Theme.THUMB_SIZE), + size = (theme.THUMB_SIZE, theme.THUMB_SIZE), pixbuf = choice.thumb(), position = pos) widget.set_active(pos) diff --git a/Sound.py b/sound.py index 12b5ede..22be221 100644 --- a/Sound.py +++ b/sound.py @@ -18,9 +18,9 @@ import gst from glob import glob from gettext import gettext as _ -import Theme -from Document import Document -from Utils import * +import theme +from document import Document +from utils import * from sugar.activity.activity import get_bundle_path PREISTALLED = 0 @@ -41,12 +41,12 @@ class Sound: def __init__(self, name, imgfile, soundfile, type): self.name = name - self._thumb = Theme.pixbuf(imgfile, THUMB_SIZE) + self._thumb = theme.pixbuf(imgfile, THUMB_SIZE) self._type = type if type == JOURNAL: - l = sorted(glob(os.path.join(Theme.SESSION_PATH, 'sound*'))) - self._soundfile = os.path.join(Theme.SESSION_PATH, + l = sorted(glob(os.path.join(theme.SESSION_PATH, 'sound*'))) + self._soundfile = os.path.join(theme.SESSION_PATH, 'sound.%03d' % (len(l)+1)) os.rename(soundfile, self._soundfile) else: @@ -62,7 +62,7 @@ class Sound: out = self if self._type == CUSTOM: - out = Theme.choose( + out = theme.choose( lambda title, file: Sound(title, 'images/sounds/speaker.png', file, JOURNAL)) if not out: @@ -73,7 +73,7 @@ class Sound: Sound.player.set_state(gst.STATE_NULL) if len(out._soundfile) == 0: return out - Sound.player.set_property('uri', 'file://' + Theme.path(out._soundfile)) + Sound.player.set_property('uri', 'file://' + theme.path(out._soundfile)) Sound.player.set_state(gst.STATE_NULL) Sound.player.set_state(gst.STATE_PLAYING) diff --git a/Theme.py b/theme.py index c3b76f9..c3b76f9 100644 --- a/Theme.py +++ b/theme.py diff --git a/Toolbars.py b/toolbars.py index 406cc55..98e1bbb 100644 --- a/Toolbars.py +++ b/toolbars.py @@ -18,10 +18,10 @@ from gettext import gettext as _ from sugar.graphics.toolbutton import ToolButton from sugar.graphics.toggletoolbutton import ToggleToolButton -import Montage -import Lessons -import Sound -from Utils import * +import montage +import lessons +import sound +from utils import * class MontageToolbar(gtk.Toolbar): def __init__(self): @@ -61,27 +61,27 @@ class MontageToolbar(gtk.Toolbar): self.show_all() def _clear_tape_cb(self, widget): - Montage.clear_tape() + montage.clear_tape() def _tempo_cb(self, widget): - Montage.set_tempo(widget.value) + montage.set_tempo(widget.value) def _play_cb(self, widget): if widget.get_active(): widget.set_icon_widget(self.pauseButtonImg) - Sound.play() - Montage.play() + sound.play() + montage.play() else: widget.set_icon_widget(self.playButtonImg) - Sound.stop() - Montage.stop() + sound.stop() + montage.stop() class LessonsToolbar(gtk.Toolbar): def __init__(self): gtk.Toolbar.__init__(self) self._mask = False - for lesson in Lessons.THEMES: + for lesson in lessons.THEMES: button = gtk.ToggleToolButton() button.set_label(lesson.name) button.connect('clicked', self._lessons_cb, lesson) @@ -95,7 +95,7 @@ class LessonsToolbar(gtk.Toolbar): return self._mask = True - for i, j in enumerate(Lessons.THEMES): + for i, j in enumerate(lessons.THEMES): if j != lesson: self.get_nth_item(i).set_active(False) diff --git a/Utils.py b/utils.py index f64d015..6793455 100644 --- a/Utils.py +++ b/utils.py @@ -18,12 +18,12 @@ import pango import zipfile import cStringIO -from Theme import * -import sugar.graphics +import sugar from sugar.graphics import style -from sugar.graphics.toolbutton import ToolButton from sugar.graphics.icon import Icon +from theme import * + class Zip(zipfile.ZipFile): def __init__(self, *args): zipfile.ZipFile.__init__(self, *args) -- cgit v0.9.1