From 5a6b5821d3403bfd0ee41781bf3fe6e645d7a027 Mon Sep 17 00:00:00 2001 From: Aleksey Lim Date: Mon, 19 Jan 2009 19:20:15 +0000 Subject: ... --- diff --git a/Char.py b/Char.py index 6a2e1eb..c47b79e 100644 --- a/Char.py +++ b/Char.py @@ -19,7 +19,7 @@ class Char: pixbuf = None #gtk.gdk.Pixbuf() def themes(): - return [Char()] + return [None] """ diff --git a/ComboBox.py b/ComboBox.py deleted file mode 100644 index 1ff3362..0000000 --- a/ComboBox.py +++ /dev/null @@ -1,45 +0,0 @@ -import pygtk -import gtk - -from Theme import * -from sugar.graphics.combobox import * - -class BigComboBox(ComboBox): - - def __init__(self): - ComboBox.__init__(self) - - self.set_name('fubar') - - - def append_item(self, action_id, text = None, icon_name = None, size = None, - pixbuf = None): - - if not self._icon_renderer and (icon_name or pixbuf): - self._icon_renderer = gtk.CellRendererPixbuf() - - settings = self.get_settings() - w, h = gtk.icon_size_lookup_for_settings(settings, gtk.ICON_SIZE_MENU) - self._icon_renderer.props.stock_size = w - - self.pack_start(self._icon_renderer, False) - self.add_attribute(self._icon_renderer, 'pixbuf', 2) - - if not self._text_renderer and text: - self._text_renderer = gtk.CellRendererText() - self.pack_end(self._text_renderer, True) - self.add_attribute(self._text_renderer, 'text', 1) - - if not pixbuf: - if icon_name: - if not size: - size = gtk.ICON_SIZE_LARGE_TOOLBAR - width, height = gtk.icon_size_lookup(size) - else: - width, height = size - pixbuf = gtk.gdk.pixbuf_new_from_file_at_size(icon_name, - width, height) - else: - pixbuf = None - - self._model.append([action_id, text, pixbuf, False]) diff --git a/Ground.py b/Ground.py index 7fb1d85..ae6a666 100644 --- a/Ground.py +++ b/Ground.py @@ -13,10 +13,86 @@ # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA import gtk +from gettext import gettext as _ -class Ground: - id = 0 - pixbuf = None #gtk.gdk.Pixbuf() +from sugar.graphics.objectchooser import ObjectChooser -def themes(): - return [Ground()] +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' : _('Yye'), + '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' : _('Spotlight'), + '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' : _('Another 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 } ) + +def change(theme): + if theme['custom'] == None or theme['custom'] == False: + return theme + + 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 + + return None diff --git a/Main.py b/Main.py index b11be9c..bb8af0b 100644 --- a/Main.py +++ b/Main.py @@ -27,11 +27,11 @@ import os import textwrap import Theme -from ComboBox import * -from Shared import * import Char import Ground import Sound +from Utils import * +from Shared import * class FrameWidget(gtk.DrawingArea): def __init__(self,bgpixbuf,fgpixbuf): @@ -121,21 +121,24 @@ class CartoonBuilder: self.fgpixbuf = fgpixbuf self.drawmain() - def _ground_cb(self, widget): - if self.backnum == 0: - self.backnum = len(self.backpicpaths)-1 - else: - self.backnum -= 1 - bgimgpath = self.backpicpaths[self.backnum] - self.setback(bgimgpath) - - def setback(self,imgpath): - #self.mfdraw.queue_draw() - #pixbuf = gtk.gdk.pixbuf_new_from_file(self.bgimgpath) - pixbuf = gtk.gdk.pixbuf_new_from_file(imgpath) - self.bgpixbuf = pixbuf.scale_simple(BGWIDTH,BGHEIGHT,gtk.gdk.INTERP_BILINEAR) - scaled_buf = pixbuf.scale_simple(IMGWIDTH,IMGHEIGHT,gtk.gdk.INTERP_BILINEAR) - self.bgsmall.set_from_pixbuf(scaled_buf) + def _ground_cb(self, widget, combo): + choice = Ground.change(widget.props.value) + + if not choice: + widget.set_active(self._prev_ground) + return + + if id(choice) != id(widget.props.value): + pos = combo.get_active() + combo.append_item(choice, text = choice['name'], + size = Theme.IMGSIZE, pixbuf = choice['pixbuf'], + position = pos) + combo.set_active(pos) + + self.bgpixbuf = choice['pixbuf'].scale_simple(BGWIDTH, BGHEIGHT, + gtk.gdk.INTERP_BILINEAR) + + self._prev_ground = widget.get_active() self.drawmain() def _char_cb(self, widget): @@ -149,7 +152,7 @@ class CartoonBuilder: self.loadimages() self.drawmain() - def _sound_cb(self, widget): + def _sound_cb(self, widget, combo): Sound.change(widget.props.value) def oldplayframe(self): @@ -268,18 +271,9 @@ class CartoonBuilder: def __init__(self,insugar,toplevel_window,mdirpath): self.mdirpath = mdirpath - self.iconsdir = os.path.join(self.mdirpath,'icons') + self.iconsdir = os.path.join(self.mdirpath, 'images', 'icons') self.playing = False - self.backnum = 0 - self.backpicpaths = [] - bpfile = file(os.path.join(self.mdirpath,'config.backpics')) - for line in bpfile: - bpfilepath = line.strip() - if bpfilepath[0] != '/': - bpfilepath = os.path.join(self.mdirpath,line.strip()) - if os.path.isfile(bpfilepath): - self.backpicpaths.append(bpfilepath) - bpfile.close() + self.waittime = 3*150 self.imgdirs = [] imgdirfile = file(os.path.join(self.mdirpath,'config.imgdirs')) @@ -558,34 +552,25 @@ class CartoonBuilder: self.controlbox = gtk.VBox() self.controlbox.show() - - # CHARACTER CONTROLS - char_box = BigComboBox() - char_box.show() - for i in Char.themes(): - char_box.append_item(i.id, size = Theme.IMGSIZE, - pixbuf = i.pixbuf) - char_box.connect('changed', self._char_cb) - self.controlbox.pack_start(char_box, False, False, 5) - - # BACKGROUND CONTROLS - bg_box = BigComboBox() - bg_box.show() - for i in Ground.themes(): - bg_box.append_item(i.id, size = Theme.IMGSIZE, - pixbuf = i.pixbuf) - bg_box.connect('changed', self._ground_cb) - self.controlbox.pack_start(bg_box, False, False, 5) - - # SOUND CONTROLS - sound_box = BigComboBox() - sound_box.show() - for i in Sound.THEMES: - sound_box.append_item(i, text = i['name'], size = Theme.IMGSIZE, - pixbuf = i['pixbuf']) - sound_box.connect('changed', self._sound_cb) - self.controlbox.pack_start(sound_box, False, False, 5) - sound_box.set_active(0) + def new_combo(themes, cb): + combo = ComboBox() + combo.show() + for i in themes: + if not i: + combo.append_separator() + else: + combo.append_item(i, text = i['name'], + size = Theme.IMGSIZE, pixbuf = i['pixbuf']) + combo.connect('changed', cb, combo) + combo.set_active(0) + return combo + + self.controlbox.pack_start(new_combo(Char.themes(), self._char_cb), + False, False, 5) + self.controlbox.pack_start(new_combo(Ground.THEMES, self._ground_cb), + False, False, 5) + self.controlbox.pack_start(new_combo(Sound.THEMES, self._sound_cb), + False, False, 5) diff --git a/Sound.py b/Sound.py index aec6e87..db52810 100644 --- a/Sound.py +++ b/Sound.py @@ -21,31 +21,27 @@ import Theme from Utils import * from sugar.activity.activity import get_bundle_path -sound_icon = Theme.pixmap('icons/sound_icon.png') +speaker = Theme.pixmap('images/sounds/speaker.png') THEMES = ( - { 'name' : _('Custom'), - 'pixbuf': sound_icon, - 'sound' : None }, - { 'name' : _('Gobble'), - 'pixbuf': sound_icon, + 'pixbuf': speaker, 'sound' : 'sounds/gobble.wav' }, - { 'name' : _('Funk'), - 'pixbuf': sound_icon, + 'pixbuf': speaker, 'sound' : 'sounds/funk.wav' }, - { 'name' : _('Giggle'), - 'pixbuf': sound_icon, + 'pixbuf': speaker, 'sound' : 'sounds/giggle.wav' }, - { 'name' : _('Jungle'), - 'pixbuf': sound_icon, + 'pixbuf': speaker, 'sound' : 'sounds/jungle.wav' }, - { 'name' : _('Mute'), - 'pixbuf': sound_icon, + '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]) @@ -63,6 +59,10 @@ def change(a_theme): if not a_theme: return theme.set(a_theme) + + import logging + logging.error(theme['name']) + if not playing.get(): return player.set_state(gst.STATE_NULL) diff --git a/Toolbar.py b/Toolbar.py index c022d6c..d6d0f4b 100644 --- a/Toolbar.py +++ b/Toolbar.py @@ -17,7 +17,6 @@ from gettext import gettext as _ from sugar.graphics.toolbutton import ToolButton from sugar.graphics.toggletoolbutton import ToggleToolButton -from sugar.graphics.objectchooser import ObjectChooser import Sound @@ -52,19 +51,3 @@ class Toolbar(gtk.Toolbar): widget.set_icon_widget(self.playButtonImg) Sound.stop() self.app.stop() - - -""" - def image_cb(self, button): - chooser = ObjectChooser('Choose Image',self.activity, - 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: - self.app.setback(jobject.file_path) - finally: - chooser.destroy() - del chooser -""" diff --git a/Utils.py b/Utils.py index 1e539c0..d16b605 100644 --- a/Utils.py +++ b/Utils.py @@ -12,6 +12,11 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +import gtk + +from Theme import * +import sugar.graphics + class FileInstanceVariable: def __init__(self, value = None): self.value = value @@ -24,3 +29,46 @@ class FileInstanceVariable: def __getitem__(self, key): return self.value[key] + +class ComboBox(sugar.graphics.combobox.ComboBox): + def __init__(self): + sugar.graphics.combobox.ComboBox.__init__(self) + self.set_name('we-really-need-it-to-use-custom-combobox-colors') + + def append_item(self, action_id, text = None, icon_name = None, size = None, + pixbuf = None, position = None): + + if not self._icon_renderer and (icon_name or pixbuf): + self._icon_renderer = gtk.CellRendererPixbuf() + + settings = self.get_settings() + w, h = gtk.icon_size_lookup_for_settings(settings, gtk.ICON_SIZE_MENU) + self._icon_renderer.props.stock_size = w + + self._icon_renderer.props.xpad = 4 + self._icon_renderer.props.ypad = 4 + + self.pack_start(self._icon_renderer, False) + self.add_attribute(self._icon_renderer, 'pixbuf', 2) + + if not self._text_renderer and text: + self._text_renderer = gtk.CellRendererText() + self.pack_end(self._text_renderer, True) + self.add_attribute(self._text_renderer, 'text', 1) + + if not pixbuf: + if icon_name: + if not size: + size = gtk.ICON_SIZE_LARGE_TOOLBAR + width, height = gtk.icon_size_lookup(size) + else: + width, height = size + pixbuf = gtk.gdk.pixbuf_new_from_file_at_size(icon_name, + width, height) + else: + pixbuf = None + + if position: + self._model.insert(position, [action_id, text, pixbuf, False]) + else: + self._model.append([action_id, text, pixbuf, False]) diff --git a/backpics/bigbg01.gif b/images/backpics/bigbg01.gif index dd3b442..dd3b442 100644 --- a/backpics/bigbg01.gif +++ b/images/backpics/bigbg01.gif Binary files differ diff --git a/backpics/bigbg02.gif b/images/backpics/bigbg02.gif index 45f6cbd..45f6cbd 100644 --- a/backpics/bigbg02.gif +++ b/images/backpics/bigbg02.gif Binary files differ diff --git a/backpics/bigbg03.gif b/images/backpics/bigbg03.gif index 284c53c..284c53c 100644 --- a/backpics/bigbg03.gif +++ b/images/backpics/bigbg03.gif Binary files differ diff --git a/backpics/bigbg04.gif b/images/backpics/bigbg04.gif index 728cb29..728cb29 100644 --- a/backpics/bigbg04.gif +++ b/images/backpics/bigbg04.gif Binary files differ diff --git a/backpics/bigbg05.gif b/images/backpics/bigbg05.gif index 2ce3a01..2ce3a01 100644 --- a/backpics/bigbg05.gif +++ b/images/backpics/bigbg05.gif Binary files differ diff --git a/backpics/bigbg06.gif b/images/backpics/bigbg06.gif index 19ef057..19ef057 100644 --- a/backpics/bigbg06.gif +++ b/images/backpics/bigbg06.gif Binary files differ diff --git a/backpics/bigbg07.gif b/images/backpics/bigbg07.gif index 63c08fb..63c08fb 100644 --- a/backpics/bigbg07.gif +++ b/images/backpics/bigbg07.gif Binary files differ diff --git a/backpics/bigbg08.gif b/images/backpics/bigbg08.gif index 28975b9..28975b9 100644 --- a/backpics/bigbg08.gif +++ b/images/backpics/bigbg08.gif Binary files differ diff --git a/backpics/bigbg09.gif b/images/backpics/bigbg09.gif index 7081235..7081235 100644 --- a/backpics/bigbg09.gif +++ b/images/backpics/bigbg09.gif Binary files differ diff --git a/backpics/bigbg10.gif b/images/backpics/bigbg10.gif index 8472741..8472741 100644 --- a/backpics/bigbg10.gif +++ b/images/backpics/bigbg10.gif Binary files differ diff --git a/backpics/bigbg11.gif b/images/backpics/bigbg11.gif index 94e53d3..94e53d3 100644 --- a/backpics/bigbg11.gif +++ b/images/backpics/bigbg11.gif Binary files differ diff --git a/backpics/bigbg12.gif b/images/backpics/bigbg12.gif index d2f2235..d2f2235 100644 --- a/backpics/bigbg12.gif +++ b/images/backpics/bigbg12.gif Binary files differ diff --git a/backpics/bigbg13.gif b/images/backpics/bigbg13.gif index d631e2d..d631e2d 100644 --- a/backpics/bigbg13.gif +++ b/images/backpics/bigbg13.gif Binary files differ diff --git a/backpics/bigbg14.gif b/images/backpics/bigbg14.gif index c90ff31..c90ff31 100644 --- a/backpics/bigbg14.gif +++ b/images/backpics/bigbg14.gif Binary files differ diff --git a/backpics/bigbg15.gif b/images/backpics/bigbg15.gif index cfdd076..cfdd076 100644 --- a/backpics/bigbg15.gif +++ b/images/backpics/bigbg15.gif Binary files differ diff --git a/backpics/bigbg16.gif b/images/backpics/bigbg16.gif index f358416..f358416 100644 --- a/backpics/bigbg16.gif +++ b/images/backpics/bigbg16.gif Binary files differ diff --git a/backpics/bigbg17.gif b/images/backpics/bigbg17.gif index 49ca132..49ca132 100644 --- a/backpics/bigbg17.gif +++ b/images/backpics/bigbg17.gif Binary files differ diff --git a/images/backpics/custom.png b/images/backpics/custom.png new file mode 100644 index 0000000..9d2c610 --- /dev/null +++ b/images/backpics/custom.png Binary files differ diff --git a/icons/50x50blank-trans.png b/images/icons/50x50blank-trans.png index b8de5ee..b8de5ee 100644 --- a/icons/50x50blank-trans.png +++ b/images/icons/50x50blank-trans.png Binary files differ diff --git a/icons/big_down_arrow.png b/images/icons/big_down_arrow.png index b0dd75b..b0dd75b 100644 --- a/icons/big_down_arrow.png +++ b/images/icons/big_down_arrow.png Binary files differ diff --git a/icons/big_left_arrow.png b/images/icons/big_left_arrow.png index 9cd03c7..9cd03c7 100644 --- a/icons/big_left_arrow.png +++ b/images/icons/big_left_arrow.png Binary files differ diff --git a/icons/big_pause.png b/images/icons/big_pause.png index 11c07cb..11c07cb 100644 --- a/icons/big_pause.png +++ b/images/icons/big_pause.png Binary files differ diff --git a/icons/big_right_arrow.png b/images/icons/big_right_arrow.png index 026d59c..026d59c 100644 --- a/icons/big_right_arrow.png +++ b/images/icons/big_right_arrow.png Binary files differ diff --git a/icons/big_up_arrow.png b/images/icons/big_up_arrow.png index e86e224..e86e224 100644 --- a/icons/big_up_arrow.png +++ b/images/icons/big_up_arrow.png Binary files differ diff --git a/icons/clear.png b/images/icons/clear.png index 4885eea..4885eea 100644 --- a/icons/clear.png +++ b/images/icons/clear.png Binary files differ diff --git a/icons/down_arrow.png b/images/icons/down_arrow.png index df950cd..df950cd 100644 --- a/icons/down_arrow.png +++ b/images/icons/down_arrow.png Binary files differ diff --git a/icons/filmstrip.png b/images/icons/filmstrip.png index 37e3ca6..37e3ca6 100644 --- a/icons/filmstrip.png +++ b/images/icons/filmstrip.png Binary files differ diff --git a/icons/left_arrow.png b/images/icons/left_arrow.png index bde58b9..bde58b9 100644 --- a/icons/left_arrow.png +++ b/images/icons/left_arrow.png Binary files differ diff --git a/icons/logo.png b/images/icons/logo.png index e2b3df8..e2b3df8 100644 --- a/icons/logo.png +++ b/images/icons/logo.png Binary files differ diff --git a/icons/oldfilmstrip.png b/images/icons/oldfilmstrip.png index 5429616..5429616 100644 --- a/icons/oldfilmstrip.png +++ b/images/icons/oldfilmstrip.png Binary files differ diff --git a/icons/pause.png b/images/icons/pause.png index 59dc8b4..59dc8b4 100644 --- a/icons/pause.png +++ b/images/icons/pause.png Binary files differ diff --git a/icons/pink_arrow.png b/images/icons/pink_arrow.png index bb0ac73..bb0ac73 100644 --- a/icons/pink_arrow.png +++ b/images/icons/pink_arrow.png Binary files differ diff --git a/icons/right_arrow.png b/images/icons/right_arrow.png index 1dd5e10..1dd5e10 100644 --- a/icons/right_arrow.png +++ b/images/icons/right_arrow.png Binary files differ diff --git a/icons/up_arrow.png b/images/icons/up_arrow.png index e37d71c..e37d71c 100644 --- a/icons/up_arrow.png +++ b/images/icons/up_arrow.png Binary files differ diff --git a/icons/yellow_arrow.png b/images/icons/yellow_arrow.png index f3a35f2..f3a35f2 100644 --- a/icons/yellow_arrow.png +++ b/images/icons/yellow_arrow.png Binary files differ diff --git a/images/sounds/custom.png b/images/sounds/custom.png new file mode 100644 index 0000000..9d2c610 --- /dev/null +++ b/images/sounds/custom.png Binary files differ diff --git a/icons/sound_icon.png b/images/sounds/mute.png index 9283e50..9283e50 100644 --- a/icons/sound_icon.png +++ b/images/sounds/mute.png Binary files differ diff --git a/icons/sound_icon.png b/images/sounds/speaker.png index 9283e50..9283e50 100644 --- a/icons/sound_icon.png +++ b/images/sounds/speaker.png Binary files differ -- cgit v0.9.1