Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAleksey Lim <alsroot@member.fsf.org>2009-01-19 16:19:24 (GMT)
committer Aleksey Lim <alsroot@member.fsf.org>2009-01-21 11:51:11 (GMT)
commit22f0c6ef272e7400a57f44e75a562eded95337af (patch)
tree9526f37770001f58b484a6ad7407aa7ddab95109
parente59ebea703fcdbdba29d39bdd0e367fbd1753e5e (diff)
...
-rw-r--r--Activity.py7
-rw-r--r--Bundle.py3
-rw-r--r--Char.py3
-rw-r--r--ComboBox.py10
-rw-r--r--Ground.py2
-rw-r--r--Main.py100
-rw-r--r--Sound.py133
-rw-r--r--Theme.py24
-rw-r--r--Toolbar.py70
-rw-r--r--gtkrc16
10 files changed, 235 insertions, 133 deletions
diff --git a/Activity.py b/Activity.py
index fa6ec09..01d4a4c 100644
--- a/Activity.py
+++ b/Activity.py
@@ -20,8 +20,13 @@ import telepathy.client
from dbus import Interface
from dbus.service import method, signal
from dbus.gobject_service import ExportedGObject
+from gettext import gettext as _
+
+from sugar.activity.activity import get_activity_root
from Main import *
+from Toolbar import *
+import Bundle
SERVICE = 'org.freedesktop.Telepathy.Tube.Connect'
IFACE = SERVICE
@@ -40,7 +45,7 @@ class CartoonBuilderActivity(activity.Activity):
self.app = CartoonBuilder(True,self, bundle_path)
self.set_title('CartoonBuilder')
toolbox = activity.ActivityToolbox(self)
- bgtoolbar = BGToolbar(self,self.app)
+ bgtoolbar = Toolbar(self,self.app)
toolbox.add_toolbar(_('Background'),bgtoolbar)
bgtoolbar.show()
self.set_toolbox(toolbox)
diff --git a/Bundle.py b/Bundle.py
index c2f2a35..1d311fe 100644
--- a/Bundle.py
+++ b/Bundle.py
@@ -19,6 +19,9 @@ def save(filepath):
pass
"""
+import zipfile
+import StringIO
+
pics = self.getpics(self.imgdir)
pixbuf = gtk.gdk.pixbuf_new_from_file(pics[self.imgstartindex])
scaled_buf = pixbuf.scale_simple(IMGWIDTH,IMGHEIGHT,gtk.gdk.INTERP_BILINEAR)
diff --git a/Char.py b/Char.py
index c00b4ce..6a2e1eb 100644
--- a/Char.py
+++ b/Char.py
@@ -14,8 +14,6 @@
import gtk
-Size = (100, 100)
-
class Char:
id = 0
pixbuf = None #gtk.gdk.Pixbuf()
@@ -25,6 +23,7 @@ def themes():
"""
+import pickle
pics = self.getpics(self.imgdir)
pixbuf = gtk.gdk.pixbuf_new_from_file(pics[self.imgstartindex])
scaled_buf = pixbuf.scale_simple(IMGWIDTH,IMGHEIGHT,gtk.gdk.INTERP_BILINEAR)
diff --git a/ComboBox.py b/ComboBox.py
index d5a6c64..1ff3362 100644
--- a/ComboBox.py
+++ b/ComboBox.py
@@ -1,11 +1,16 @@
import pygtk
import gtk
-from sugar.graphics.combobox import ComboBox
+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):
@@ -32,7 +37,8 @@ class BigComboBox(ComboBox):
width, height = gtk.icon_size_lookup(size)
else:
width, height = size
- pixbuf = gtk.gdk.pixbuf_new_from_file_at_size(icon_name, width, height)
+ pixbuf = gtk.gdk.pixbuf_new_from_file_at_size(icon_name,
+ width, height)
else:
pixbuf = None
diff --git a/Ground.py b/Ground.py
index ff67c6c..7fb1d85 100644
--- a/Ground.py
+++ b/Ground.py
@@ -14,8 +14,6 @@
import gtk
-Size = (100, 100)
-
class Ground:
id = 0
pixbuf = None #gtk.gdk.Pixbuf()
diff --git a/Main.py b/Main.py
index ab3380b..8332f66 100644
--- a/Main.py
+++ b/Main.py
@@ -19,20 +19,12 @@
### (c) 2007 World Wide Workshop Foundation
import time
-import StringIO
import pygtk
import gtk
import gobject
import gettext
import os
-import zipfile
import textwrap
-import pickle
-import gst
-
-from sugar.activity.activity import get_activity_root
-from sugar.graphics.toolbutton import ToolButton
-from sugar.graphics.objectchooser import ObjectChooser
import Theme
from ComboBox import *
@@ -41,8 +33,6 @@ import Char
import Ground
import Sound
-_ = gettext.lgettext
-
class FrameWidget(gtk.DrawingArea):
def __init__(self,bgpixbuf,fgpixbuf):
gtk.DrawingArea.__init__(self)
@@ -72,8 +62,27 @@ class FrameWidget(gtk.DrawingArea):
#widget.window.draw_pixbuf(self.gc,fgpixbuf,0,0,75,75,-1,-1,0,0)
widget.window.draw_pixbuf(self.gc,self.fgpixbuf,0,0,0,0,-1,-1,0,0)
-
class CartoonBuilder:
+
+ def play(self):
+ self.playframenum = 0
+ self.playing = gobject.timeout_add(self.waittime, self.playframe)
+
+ def stop():
+ self.playing = False
+
+
+
+
+
+
+
+
+
+
+
+
+
def clearframe(self, widget, data=None):
transpixbuf = self.gettranspixbuf(IMGWIDTH,IMGHEIGHT)
self.frameimgs[self.frame_selected].set_from_pixbuf(transpixbuf)
@@ -143,27 +152,6 @@ class CartoonBuilder:
def _sound_cb(self, widget):
Sound.switch(widget.props.value)
- def go(self, widget, data=None):
- self.playframenum = 0
- if self.playing:
- Sound.stop()
- #widget.set_label('GO!')
- playimg = gtk.Image()
- #playimg.set_from_stock(gtk.STOCK_MEDIA_PLAY,gtk.ICON_SIZE_BUTTON)
- playimg.set_from_file(os.path.join(self.iconsdir,'big_right_arrow.png'))
- playimg.show()
- widget.set_image(playimg)
- self.playing = False
- else:
- Sound.play()
- #widget.set_label('STOP')
- stopimg = gtk.Image()
- #stopimg.set_from_stock(gtk.STOCK_MEDIA_STOP,gtk.ICON_SIZE_BUTTON)
- stopimg.set_from_file(os.path.join(self.iconsdir,'big_pause.png'))
- stopimg.show()
- widget.set_image(stopimg)
- self.playing = gobject.timeout_add(self.waittime, self.playframe)
-
def oldplayframe(self):
self.mfdraw.fgimgpath = self.frameimgpaths[self.playframenum]
self.mfdraw.queue_draw()
@@ -547,17 +535,8 @@ class CartoonBuilder:
self.bcontrolbox = gtk.HBox()
self.bcontrolbox.set_border_width(5)
self.bcontrolbox.show()
- # GO BUTTON
- playimg = gtk.Image()
- #playimg.set_from_stock(gtk.STOCK_MEDIA_PLAY,gtk.ICON_SIZE_BUTTON)
- playimg.set_from_file(os.path.join(self.iconsdir,'big_right_arrow.png'))
- playimg.show()
- self.gobutton = gtk.Button()
- self.gobutton.set_label('')
- self.gobutton.set_image(playimg)
- self.gobutton.connect('clicked', self.go, None)
- self.gobutton.show()
- self.bcontrolbox.pack_start(self.gobutton,True,True,5)
+
+
# SPEED CONTROLS
self.sbox = gtk.VBox()
@@ -584,7 +563,7 @@ class CartoonBuilder:
char_box = BigComboBox()
char_box.show()
for i in Char.themes():
- char_box.append_item(i.id, size = Char.Size,
+ 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)
@@ -593,7 +572,7 @@ class CartoonBuilder:
bg_box = BigComboBox()
bg_box.show()
for i in Ground.themes():
- bg_box.append_item(i.id, size = Ground.Size,
+ 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)
@@ -601,11 +580,12 @@ class CartoonBuilder:
# SOUND CONTROLS
sound_box = BigComboBox()
sound_box.show()
- for i in Sound.themes():
- sound_box.append_item(i.id, size = Sound.Size,
- pixbuf = i.pixbuf)
+ 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)
@@ -688,30 +668,6 @@ class CartoonBuilder:
def main(self):
gtk.main()
-class BGToolbar(gtk.Toolbar):
- def __init__(self,sactivity,app):
- gtk.Toolbar.__init__(self)
- self.sactivity = sactivity
- self.app = app
- self.image = ToolButton('insert-image')
- self.image.set_tooltip('Insert Image')
- self.imageid = self.image.connect('clicked',self.image_cb)
- self.insert(self.image,-1)
- self.image.show()
-
- def image_cb(self, button):
- chooser = ObjectChooser('Choose Image',self.sactivity,
- 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
-
"""
SPANISH = u'Espa\xf1ol'
diff --git a/Sound.py b/Sound.py
index e070d5c..f6262e2 100644
--- a/Sound.py
+++ b/Sound.py
@@ -12,70 +12,95 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+import os
import gtk
+import gst
+from gettext import gettext as _
-Size = (100, 100)
+import Theme
+from sugar.activity.activity import get_bundle_path
-class Sound:
- id = 0
- pixbuf = None #gtk.gdk.Pixbuf()
+sound_icon = Theme.pixmap('icons/sound_icon.png')
-def themes():
- return [Sound()]
+THEMES = (
+ { 'name' : _('Custom'),
+ 'pixbuf': sound_icon,
+ 'sound' : None },
+
+ { 'name' : _('Gobble'),
+ 'pixbuf': sound_icon,
+ 'sound' : 'sounds/gobble.wav' },
+
+ { 'name' : _('Funk'),
+ 'pixbuf': sound_icon,
+ 'sound' : 'sounds/funk.wav' },
+
+ { 'name' : _('Giggle'),
+ 'pixbuf': sound_icon,
+ 'sound' : 'sounds/giggle.wav' },
+
+ { 'name' : _('Jungle'),
+ 'pixbuf': sound_icon,
+ 'sound' : 'sounds/jungle.wav' },
+
+ { 'name' : _('Mute'),
+ 'pixbuf': sound_icon,
+ 'sound' : None } )
+
+class FileInstanceVariable:
+ def __init__(self, value = None):
+ self.value = value
+
+ def get(self):
+ return self.value
+
+ def set(self, value):
+ self.value = value
+
+ def __getitem__(self, key):
+ return self.value[key]
+
+theme = FileInstanceVariable(THEMES[0])
+playing = FileInstanceVariable(False)
def play():
- if self.soundfile:
- #self.player.set_property('uri', 'file://' + self.soundfile)
- self.player.set_state(gst.STATE_PLAYING)
+ playing.set(True)
+ switch(theme.get())
def stop():
- if self.soundfile:
- self.player.set_state(gst.STATE_NULL)
-
-def switch(id):
- self.soundfile = self.sounds[self.soundindex]
-
- if self.soundfile:
- soundname = os.path.splitext(os.path.split(self.soundfile)[1])[0]
- self.player.set_property('uri', 'file://' + self.soundfile)
- if self.playing:
- self.player.set_state(gst.STATE_NULL)
- self.player.set_state(gst.STATE_PLAYING)
- else:
- soundname = 'No Sound'
- if self.playing:
- self.player.set_state(gst.STATE_NULL)
- self.soundlabel.set_text(soundname.capitalize())
-
-
-def on_gstmessage(self, bus, message):
+ playing.set(False)
+ player.set_state(gst.STATE_NULL)
+
+def switch(a_theme):
+ if not a_theme: return
+ theme.set(a_theme)
+
+ if not playing.get(): return
+
+ player.set_state(gst.STATE_NULL)
+
+ sound = theme['sound']
+ if not sound: return
+
+ player.set_property('uri', 'file://' + Theme.path(sound))
+ player.set_state(gst.STATE_NULL)
+ player.set_state(gst.STATE_PLAYING)
+
+# GSTREAMER STUFF
+
+def _gstmessage_cb(bus, message):
t = message.type
if t == gst.MESSAGE_EOS:
# END OF SOUND FILE
- self.player.set_state(gst.STATE_NULL)
- self.player.set_state(gst.STATE_PLAYING)
+ player.set_state(gst.STATE_NULL)
+ player.set_state(gst.STATE_PLAYING)
elif t == gst.MESSAGE_ERROR:
- self.player.set_state(gst.STATE_NULL)
-
-def init():
- self.sounds = ['']
- soundfile = file(os.path.join(self.mdirpath,'config.sounds'))
- for line in soundfile:
- soundfilepath = line.strip()
- if soundfilepath[0] != '/':
- soundfilepath = os.path.join(self.mdirpath,line.strip())
- if os.path.isfile(soundfilepath):
- self.sounds.append(soundfilepath)
- soundfile.close()
-
- self.soundfile = self.sounds[self.soundindex]
-
- # START GSTREAMER STUFF
- self.player = gst.element_factory_make("playbin", "player")
- fakesink = gst.element_factory_make('fakesink', "my-fakesink")
- self.player.set_property("video-sink", fakesink)
- self.bus = self.player.get_bus()
- self.bus.add_signal_watch()
- self.bus.connect('message', self.on_gstmessage)
- # END GSTREAMER STUFF
+ player.set_state(gst.STATE_NULL)
+
+player = gst.element_factory_make("playbin", "player")
+fakesink = gst.element_factory_make('fakesink', "my-fakesink")
+player.set_property("video-sink", fakesink)
+bus = player.get_bus()
+bus.add_signal_watch()
+bus.connect('message', _gstmessage_cb)
diff --git a/Theme.py b/Theme.py
index d5483f4..3f7f9b9 100644
--- a/Theme.py
+++ b/Theme.py
@@ -12,11 +12,17 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+import os
+import gtk
+
+from sugar.activity.activity import get_bundle_path
+
TRANSIMG = '50x50blank-trans.png'
BGHEIGHT = gtk.gdk.screen_height() - 450 # 425
BGWIDTH = BGHEIGHT # 425
IMGHEIGHT = 100
IMGWIDTH = 100
+IMGSIZE = (IMGWIDTH, IMGHEIGHT)
BORDER_LEFT = 1
BORDER_RIGHT = 2
@@ -64,3 +70,21 @@ OLD_COLOR_BG_BUTTONS = (
FRAME_COUNT = (gtk.gdk.screen_height() - 370) / IMGHEIGHT * 2
TAPE_COUNT = (gtk.gdk.screen_width() - 430) / IMGWIDTH
+
+def path(file):
+ if os.path.isabs(file):
+ return 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))
+ out = out.scale_simple(IMGWIDTH, IMGHEIGHT, gtk.gdk.INTERP_BILINEAR)
+ return out
+
+# customize theme
+gtkrc = os.path.join(get_bundle_path(), 'gtkrc')
+gtk.rc_add_default_file(gtkrc)
+settings = gtk.settings_get_default()
+gtk.rc_reset_styles(settings)
+gtk.rc_reparse_all_for_settings(settings, True)
diff --git a/Toolbar.py b/Toolbar.py
new file mode 100644
index 0000000..c022d6c
--- /dev/null
+++ b/Toolbar.py
@@ -0,0 +1,70 @@
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# 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 gettext import gettext as _
+
+from sugar.graphics.toolbutton import ToolButton
+from sugar.graphics.toggletoolbutton import ToggleToolButton
+from sugar.graphics.objectchooser import ObjectChooser
+
+import Sound
+
+class Toolbar(gtk.Toolbar):
+ def __init__(self, activity, app):
+ gtk.Toolbar.__init__(self)
+ self.activity = activity
+ self.app = app
+
+ self.playButton = ToggleToolButton('media-playback-start')
+ self.playButton.connect('toggled', self._playButton_cb)
+ self.insert(self.playButton, -1)
+ self.playButton.show()
+ self.playButton.set_tooltip(_('Play / Pause'))
+
+ #Play button Image
+ self.playButtonImg = gtk.Image()
+ self.playButtonImg.set_from_icon_name('media-playback-start', gtk.ICON_SIZE_LARGE_TOOLBAR)
+ self.playButtonImg.show()
+
+ #Pause button Image
+ self.pauseButtonImg = gtk.Image()
+ self.pauseButtonImg.set_from_icon_name('media-playback-pause', gtk.ICON_SIZE_LARGE_TOOLBAR)
+ self.pauseButtonImg.show()
+
+ def _playButton_cb(self, widget):
+ if widget.get_active():
+ widget.set_icon_widget(self.pauseButtonImg)
+ Sound.play()
+ self.app.play()
+ else:
+ 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/gtkrc b/gtkrc
new file mode 100644
index 0000000..b4ae7cd
--- /dev/null
+++ b/gtkrc
@@ -0,0 +1,16 @@
+style "mamacombo"
+{
+ color["focus_line"] = "#027F01"
+ bg[NORMAL] = "#027F01"
+ bg[ACTIVE] = "#026002"
+}
+
+style "fixframe"
+{
+ color["focus_line"] = "#FFFFFF"
+ bg[NORMAL] = "#808080"
+ bg[ACTIVE] = "#808080"
+}
+
+widget_class "*<GtkComboBox>*" style "mamacombo"
+widget "*ComboBox*" style "fixframe"