diff options
author | Aleksey Lim <alsroot@member.fsf.org> | 2009-01-20 04:08:48 (GMT) |
---|---|---|
committer | Aleksey Lim <alsroot@member.fsf.org> | 2009-01-21 11:51:12 (GMT) |
commit | 3978a402ba1bdef5bf21772e6fa59364807c8c97 (patch) | |
tree | 995d4e23c5e9db7a2a6a3e06c1cbfcdc1818d9b1 | |
parent | e9e55bfa06421753ff2f8c5cbc59328628c69fd4 (diff) |
...
-rw-r--r-- | Char.py | 34 | ||||
-rw-r--r-- | Document.py | 2 | ||||
-rw-r--r-- | Ground.py | 125 | ||||
-rw-r--r-- | Main.py | 25 | ||||
-rw-r--r-- | Sound.py | 96 | ||||
-rw-r--r-- | Theme.py | 15 |
6 files changed, 134 insertions, 163 deletions
@@ -17,24 +17,26 @@ from gettext import gettext as _ import Theme +class Char: + def __init__(self, name, file, dir, custom): + self.name = name + self.pixbuf = Theme.pixbuf(file, Theme.THUMB_SIZE) + self.dir = dir + self.custom = custom + + def thumb(self): + return self.pixbuf + THEMES = ( - { 'name' : _('Elephant'), - 'pixbuf': Theme.pixmap('images/pics/Elephant/bigelephant0.gif'), - 'dir' : 'images/pics/Elephant', - 'custom': None }, - { 'name' : _('Space Blob'), - 'pixbuf': Theme.pixmap('images/pics/SpaceBlob/bigblob8.gif'), - 'dir' : 'images/pics/SpaceBlob', - 'custom': None }, - { 'name' : _('Turkey'), - 'pixbuf': Theme.pixmap('images/pics/Turkey/bigturkey1.gif'), - 'dir' : 'images/pics/Turkey', - 'custom': None }, + Char(_('Elephant'), 'images/pics/Elephant/bigelephant0.gif', + 'images/pics/Elephant', None), + Char(_('Space Blob'), 'images/pics/SpaceBlob/bigblob8.gif', + 'images/pics/SpaceBlob', None), + Char(_('Turkey'), 'images/pics/Turkey/bigturkey1.gif', + 'images/pics/Turkey', None), None, - { 'name' : _('Custom'), - 'pixbuf': Theme.pixmap('images/pics/custom.png'), - 'dir' : None, - 'custom': True } ) + Char(_('Custom'), 'images/pics/custom.png', + None, True) ) diff --git a/Document.py b/Document.py index 5d01dc2..0ddd3c7 100644 --- a/Document.py +++ b/Document.py @@ -29,7 +29,7 @@ def get_screen(index): def get_tape(index): return gtk.gdk.pixbuf_new_from_file_at_size( Theme.path('images/pics/Elephant/bigelephant0.gif'), - Theme.FRAME_SIZE, Theme.FRAME_SIZE) + Theme.THUMB_SIZE, Theme.THUMB_SIZE) def clean(index): pass @@ -19,80 +19,59 @@ from sugar.graphics.objectchooser import ObjectChooser import Theme -THEMES = ( - { 'name' : _('Saturn'), - 'pixbuf': Theme.pixmap('images/backpics/bigbg01.gif'), - 'custom': None }, - { 'name' : _('Snowflakes'), - 'pixbuf': Theme.pixmap('images/backpics/bigbg02.gif'), - 'custom': None }, - { 'name' : _('Eye'), - 'pixbuf': Theme.pixmap('images/backpics/bigbg03.gif'), - 'custom': None }, - { 'name' : _('Blobs'), - 'pixbuf': Theme.pixmap('images/backpics/bigbg04.gif'), - 'custom': None }, - { 'name' : _('Star Night'), - 'pixbuf': Theme.pixmap('images/backpics/bigbg05.gif'), - 'custom': None }, - { 'name' : _('Forest'), - 'pixbuf': Theme.pixmap('images/backpics/bigbg06.gif'), - 'custom': None }, - { 'name' : _('Spiral'), - 'pixbuf': Theme.pixmap('images/backpics/bigbg07.gif'), - 'custom': None }, - { 'name' : _('Beam'), - 'pixbuf': Theme.pixmap('images/backpics/bigbg08.gif'), - 'custom': None }, - { 'name' : _('Cloth'), - 'pixbuf': Theme.pixmap('images/backpics/bigbg09.gif'), - 'custom': None }, - { 'name' : _('Faces'), - 'pixbuf': Theme.pixmap('images/backpics/bigbg10.gif'), - 'custom': None }, - { 'name' : _('Leaves'), - 'pixbuf': Theme.pixmap('images/backpics/bigbg11.gif'), - 'custom': None }, - { 'name' : _('Vegetables'), - 'pixbuf': Theme.pixmap('images/backpics/bigbg12.gif'), - 'custom': None }, - { 'name' : _('Spotlight'), - 'pixbuf': Theme.pixmap('images/backpics/bigbg13.gif'), - 'custom': None }, - { 'name' : _('Strips'), - 'pixbuf': Theme.pixmap('images/backpics/bigbg14.gif'), - 'custom': None }, - { 'name' : _('Scene'), - 'pixbuf': Theme.pixmap('images/backpics/bigbg15.gif'), - 'custom': None }, - { 'name' : _('Rhombs'), - 'pixbuf': Theme.pixmap('images/backpics/bigbg16.gif'), - 'custom': None }, - { 'name' : _('Milky Way'), - 'pixbuf': Theme.pixmap('images/backpics/bigbg17.gif'), - 'custom': None }, - None, - { 'name' : _('Custom'), - 'pixbuf': Theme.pixmap('images/backpics/custom.png'), - 'custom': True } ) +class Ground: + def __init__(self, name, file, custom): + self.name = name + self._pixbuf = Theme.pixbuf(file) + self._custom = custom + self._thumb = None + + def thumb(self): + if not self._thumb: + self._thumb = self._pixbuf.scale_simple(Theme.THUMB_SIZE, + Theme.THUMB_SIZE, gtk.gdk.INTERP_BILINEAR) + return self._thumb + + def orig(self): + return self._pixbuf -def change(theme): - if theme['custom'] == None or theme['custom'] == False: - return theme + def change(self): + if self._custom in (None, False): + return self - chooser = ObjectChooser(_('Choose background image'), None, - gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT) - try: - result = chooser.run() + chooser = ObjectChooser(_('Choose background image'), None, + gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT) + try: + result = chooser.run() - if result == gtk.RESPONSE_ACCEPT: - jobject = chooser.get_selected_object() - if jobject and jobject.file_path: - return { 'name' : jobject.metadata['title'], - 'pixbuf': Theme.pixmap(jobject.file_path), - 'custom': False } - finally: - chooser.destroy() - del chooser + if result == gtk.RESPONSE_ACCEPT: + jobject = chooser.get_selected_object() + if jobject and jobject.file_path: + return Ground(jobject.metadata['title'], + jobject.file_path, False) + finally: + chooser.destroy() + del chooser - return None + return None + +THEMES = ( + Ground(_('Saturn'), 'images/backpics/bigbg01.gif', None), + Ground(_('Snowflakes'), 'images/backpics/bigbg02.gif', None), + Ground(_('Eye'), 'images/backpics/bigbg03.gif', None), + Ground(_('Blobs'), 'images/backpics/bigbg04.gif', None), + Ground(_('Star Night'), 'images/backpics/bigbg05.gif', None), + Ground(_('Forest'), 'images/backpics/bigbg06.gif', None), + Ground(_('Spiral'), 'images/backpics/bigbg07.gif', None), + Ground(_('Beam'), 'images/backpics/bigbg08.gif', None), + Ground(_('Cloth'), 'images/backpics/bigbg09.gif', None), + Ground(_('Faces'), 'images/backpics/bigbg10.gif', None), + Ground(_('Leaves'), 'images/backpics/bigbg11.gif', None), + Ground(_('Vegetables'), 'images/backpics/bigbg12.gif', None), + Ground(_('Spotlight'), 'images/backpics/bigbg13.gif', None), + Ground(_('Strips'), 'images/backpics/bigbg14.gif', None), + Ground(_('Scene'), 'images/backpics/bigbg15.gif', None), + Ground(_('Rhombs'), 'images/backpics/bigbg16.gif', None), + Ground(_('Milky Way'), 'images/backpics/bigbg17.gif', None), + None, + Ground(_('Custom'), 'images/backpics/custom.png', True) ) @@ -120,7 +120,7 @@ class CartoonBuilder: self.screen.draw() def _ground_cb(self, widget, combo): - choice = Ground.change(widget.props.value) + choice = widget.props.value.change() if not choice: widget.set_active(self._prev_ground) @@ -128,18 +128,18 @@ class CartoonBuilder: if id(choice) != id(widget.props.value): pos = combo.get_active() - combo.append_item(choice, text = choice['name'], - size = (Theme.FRAME_SIZE, Theme.FRAME_SIZE), - pixbuf = choice['pixbuf'], position = pos) + combo.append_item(choice, text = choice.name, + size = (Theme.THUMB_SIZE, Theme.THUMB_SIZE), + pixbuf = choice.thumb(), position = pos) combo.set_active(pos) self._prev_ground = widget.get_active() - self.screen.bgpixbuf = choice['pixbuf'] + self.screen.bgpixbuf = choice.orig() self.screen.draw() def _sound_cb(self, widget, combo): - Sound.change(widget.props.value) + widget.props.value.change() def _char_cb(self, widget): return @@ -384,7 +384,7 @@ class CartoonBuilder: frame_box.show() filmstrip_pixbuf = gtk.gdk.pixbuf_new_from_file_at_scale( - Theme.path('icons/filmstrip.png'), FRAME_SIZE, -1, False) + Theme.path('icons/filmstrip.png'), THUMB_SIZE, -1, False) filmstrip = gtk.Image() filmstrip.set_from_pixbuf(filmstrip_pixbuf); @@ -398,7 +398,7 @@ class CartoonBuilder: 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.FRAME_SIZE, Theme.FRAME_SIZE) + frame.set_size_request(Theme.THUMB_SIZE, Theme.THUMB_SIZE) frame_box.pack_start(frame, False, False) self.tape.append(frame) @@ -427,12 +427,9 @@ class CartoonBuilder: combo.append_separator() continue - pixbuf = i['pixbuf'].scale_simple(Theme.FRAME_SIZE, - Theme.FRAME_SIZE, gtk.gdk.INTERP_BILINEAR) - - combo.append_item(i, text = i['name'], - size = (Theme.FRAME_SIZE, Theme.FRAME_SIZE), - pixbuf = pixbuf) + combo.append_item(i, text = i.name, + size = (Theme.THUMB_SIZE, Theme.THUMB_SIZE), + pixbuf = i.thumb()) combo.connect('changed', cb, combo) combo.set_active(0) @@ -21,74 +21,64 @@ import Theme from Utils import * from sugar.activity.activity import get_bundle_path -speaker = Theme.pixmap('images/sounds/speaker.png') +class Sound: + playing = False + current = None + player = None -THEMES = ( - { 'name' : _('Gobble'), - 'pixbuf': speaker, - 'sound' : 'sounds/gobble.wav' }, - { 'name' : _('Funk'), - 'pixbuf': speaker, - 'sound' : 'sounds/funk.wav' }, - { 'name' : _('Giggle'), - 'pixbuf': speaker, - 'sound' : 'sounds/giggle.wav' }, - { 'name' : _('Jungle'), - 'pixbuf': speaker, - 'sound' : 'sounds/jungle.wav' }, - { 'name' : _('Mute'), - 'pixbuf': Theme.pixmap('images/sounds/mute.png'), - 'sound' : None }, - None, - { 'name' : _('Custom'), - 'pixbuf': Theme.pixmap('images/sounds/custom.png'), - 'sound' : None } ) - -theme = FileInstanceVariable(THEMES[0]) -playing = FileInstanceVariable(False) - -def play(): - playing.set(True) - change(theme.get()) - -def stop(): - playing.set(False) - player.set_state(gst.STATE_NULL) + def __init__(self, name, file, sound): + self.name = name + self.pixbuf = Theme.pixbuf(file, THUMB_SIZE) + self.sound = sound -def change(a_theme): - if not a_theme: return - theme.set(a_theme) + def thumb(self): + return self.pixbuf + def change(self): + Sound.current = self + if not Sound.playing: return + Sound.player.set_state(gst.STATE_NULL) + if not self.sound: return - import logging - logging.error(theme['name']) + Sound.player.set_property('uri', 'file://' + Theme.path(self.sound)) + Sound.player.set_state(gst.STATE_NULL) + Sound.player.set_state(gst.STATE_PLAYING) - if not playing.get(): return +THEMES = ( + Sound(_('Gobble'), 'images/sounds/speaker.png', 'sounds/gobble.wav'), + Sound(_('Funk'), 'images/sounds/speaker.png', 'sounds/funk.wav'), + Sound(_('Giggle'), 'images/sounds/speaker.png', 'sounds/giggle.wav'), + Sound(_('Jungle'), 'images/sounds/speaker.png', 'sounds/jungle.wav'), + Sound(_('Mute'), 'images/sounds/mute.png', None), + None, + Sound(_('Custom'), 'images/sounds/custom.png', None) ) - player.set_state(gst.STATE_NULL) +Sound.current = THEMES[0] - sound = theme['sound'] - if not sound: return +def play(): + Sound.playing = True + Sound.current.change() - player.set_property('uri', 'file://' + Theme.path(sound)) - player.set_state(gst.STATE_NULL) - player.set_state(gst.STATE_PLAYING) +def stop(): + Sound.playing = False + Sound.player.set_state(gst.STATE_NULL) # GSTREAMER STUFF def _gstmessage_cb(bus, message): - t = message.type - if t == gst.MESSAGE_EOS: + type = message.type + + if type == gst.MESSAGE_EOS: # END OF SOUND FILE - player.set_state(gst.STATE_NULL) - player.set_state(gst.STATE_PLAYING) - elif t == gst.MESSAGE_ERROR: - player.set_state(gst.STATE_NULL) + Sound.player.set_state(gst.STATE_NULL) + Sound.player.set_state(gst.STATE_PLAYING) + elif type == gst.MESSAGE_ERROR: + Sound.player.set_state(gst.STATE_NULL) -player = gst.element_factory_make("playbin", "player") +Sound.player = gst.element_factory_make("playbin", "player") fakesink = gst.element_factory_make('fakesink', "my-fakesink") -player.set_property("video-sink", fakesink) +Sound.player.set_property("video-sink", fakesink) -bus = player.get_bus() +bus = Sound.player.get_bus() bus.add_signal_watch() bus.connect('message', _gstmessage_cb) @@ -23,11 +23,11 @@ TRANSIMG = '50x50blank-trans.png' DESKTOP_WIDTH = gtk.gdk.screen_width() DESKTOP_HEIGHT = gtk.gdk.screen_height() - style.LARGE_ICON_SIZE -FRAME_SIZE = min(100, min(DESKTOP_WIDTH, DESKTOP_HEIGHT) / 8) -SCREEN_SIZE = min(DESKTOP_WIDTH - 275, DESKTOP_HEIGHT) - FRAME_SIZE*2 +THUMB_SIZE = min(100, min(DESKTOP_WIDTH, DESKTOP_HEIGHT) / 8) +SCREEN_SIZE = min(DESKTOP_WIDTH - 275, DESKTOP_HEIGHT) - THUMB_SIZE*2 -FRAME_COUNT = DESKTOP_HEIGHT / FRAME_SIZE*2 -TAPE_COUNT = (DESKTOP_WIDTH - FRAME_SIZE) / FRAME_SIZE +FRAME_COUNT = DESKTOP_HEIGHT / THUMB_SIZE*2 +TAPE_COUNT = (DESKTOP_WIDTH - THUMB_SIZE) / THUMB_SIZE BORDER_LEFT = 1 BORDER_RIGHT = 2 @@ -79,8 +79,11 @@ def path(file): else: return os.path.join(get_bundle_path(), file) -def pixmap(file, numberr_in_set = None): - out = gtk.gdk.pixbuf_new_from_file(path(file)) +def pixbuf(file, size = None): + if size: + out = gtk.gdk.pixbuf_new_from_file_at_size(path(file), size, size) + else: + out = gtk.gdk.pixbuf_new_from_file(path(file)) return out # customize theme |