Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Activity.py16
-rw-r--r--Char.py22
-rw-r--r--Document.py65
-rw-r--r--Ground.py29
-rw-r--r--Sound.py62
-rw-r--r--Theme.py12
-rw-r--r--Utils.py2
-rw-r--r--View.py (renamed from Main.py)281
8 files changed, 281 insertions, 208 deletions
diff --git a/Activity.py b/Activity.py
index 35e7596..eccde28 100644
--- a/Activity.py
+++ b/Activity.py
@@ -24,9 +24,12 @@ from gettext import gettext as _
from sugar.activity.activity import get_activity_root
-from Main import *
+from View import View
from Toolbar import *
import Document
+import Char
+import Ground
+import Sound
SERVICE = 'org.freedesktop.Telepathy.Tube.Connect'
IFACE = SERVICE
@@ -39,8 +42,7 @@ class CartoonBuilderActivity(activity.Activity):
activity.Activity.__init__(self,handle)
self.connect("destroy",self.destroy_cb)
- #app = cartoonbuilder(self,'/home/olpc/Activities/CartoonBuilder.activity')
- self.app = CartoonBuilder()
+ self.app = View()
self.set_title('CartoonBuilder')
toolbox = activity.ActivityToolbox(self)
bgtoolbar = Toolbar(self,self.app)
@@ -179,9 +181,13 @@ class CartoonBuilderActivity(activity.Activity):
def read_file(self, filepath):
Document.load(filepath)
+ Char.load()
+ Ground.load()
+ Sound.load()
- def write_file(self, filepath):
- Document.save(filepath)
+ #def write_file(self, filepath):
+ #pass
+ #Document.save(filepath)
class ConnectGame(ExportedGObject):
diff --git a/Char.py b/Char.py
index 23da9b7..d335a85 100644
--- a/Char.py
+++ b/Char.py
@@ -19,12 +19,18 @@ from gettext import gettext as _
import Theme
import Document
+def load():
+ custom = THEMES[-1]
+
+ for i in range(Theme.TAPE_COUNT):
+ custom.origs[i] = Document.tape_orig(i)
+ custom.thumbs[i] = Document.tape_thumb(i)
+
class Char:
def __init__(self, name, file, dir, custom):
self.name = name
self.pixbuf = Theme.pixbuf(file, Theme.THUMB_SIZE)
self.custom = custom
- self.loaded = False
self.thumbs = {}
self.origs = {}
self.files = []
@@ -34,15 +40,6 @@ class Char:
else:
self.files = sorted(glob.glob(Theme.path(dir + '/*')))
- def change(self):
- if not self.custom or self.loaded:
- return
- self.loaded = True
-
- for i in range(Theme.TAPE_COUNT):
- self.origs[i] = Document.orig(i)
- self.thumbs[i] = Document.thumb(i)
-
def thumb(self, index = None):
if index == None:
return self.pixbuf
@@ -66,10 +63,9 @@ class Char:
if pix == None:
if self.custom:
- pix = Theme.choose_pixbuf(lambda t, file: Theme.pixbuf(file))
+ pix = Theme.choose(lambda t, file: Theme.pixbuf(file))
if pix:
- self.thumbs[index] = pix.scale_simple(Theme.THUMB_SIZE,
- Theme.THUMB_SIZE, gtk.gdk.INTERP_BILINEAR)
+ self.thumbs[index] = Theme.scale(pix)
self.origs[index] = pix
else:
if index < len(self.files):
diff --git a/Document.py b/Document.py
index 51320e6..c1714b9 100644
--- a/Document.py
+++ b/Document.py
@@ -17,26 +17,83 @@ import gtk
import Theme
def load(filepath):
+ """
+ def loadfromzip(self, f):
+
+ zf = zipfile.ZipFile(filepath)
+ fnames = zf.namelist()
+ framenames = []
+ for fname in fnames:
+ if fname[-8:] == 'back.png':
+ backname = fname
+ else:
+ framenames.append(fname)
+ framenames.sort()
+ # set the background
+ tmpbgpath = os.path.join(TMPDIR,'back.png')
+ f = file(tmpbgpath,'w')
+
+
+ f.write(zf.read(backname))
+
+
+ f.close()
+ self.setback(tmpbgpath)
+ os.remove(tmpbgpath)
+ self.imgdir = TMPDIR
+ for filepath in framenames:
+ fname = os.path.split(filepath)[1]
+ tmpfilepath = os.path.join(TMPDIR,fname)
+ f = file(tmpfilepath,'w')
+ f.write(zf.read(filepath))
+ f.close()
+ zf.close()
+ self.loadimages()
+ # setup the filmstrip frames
+ pics = self.getpics(self.imgdir)
+ count = 0
+ for imgpath in pics:
+ pixbuf = gtk.gdk.pixbuf_new_from_file(imgpath)
+ fgpixbuf = pixbuf.scale_simple(BGWIDTH,BGHEIGHT,gtk.gdk.INTERP_BILINEAR)
+ self.fgpixbufs[count] = fgpixbuf
+ if count == 0:
+ self.fgpixbuf = fgpixbuf
+ self.drawmain()
+ scaled_buf = pixbuf.scale_simple(IMGWIDTH,IMGHEIGHT,gtk.gdk.INTERP_BILINEAR)
+ self.frameimgs[count].set_from_pixbuf(scaled_buf)
+ count += 1
+ entries = os.listdir(TMPDIR)
+ for entry in entries:
+ entrypath = os.path.join(TMPDIR,entry)
+ os.remove(entrypath)
+ """
pass
def save(filepath):
pass
-def orig(index):
+def tape_orig(index):
return gtk.gdk.pixbuf_new_from_file(
Theme.path('images/pics/Elephant/bigelephant0.gif'))
-def thumb(index):
+def tape_thumb(index):
return gtk.gdk.pixbuf_new_from_file_at_size(
Theme.path('images/pics/Elephant/bigelephant0.gif'),
Theme.THUMB_SIZE, Theme.THUMB_SIZE)
-def clean(index):
+def tape_clean(index):
pass
-def stamp(index, pixbuf):
+def tape_stamp(index, pixbuf):
pass
+def ground():
+ return ('foo', gtk.gdk.pixbuf_new_from_file(
+ Theme.path('images/pics/Elephant/bigelephant1.gif')))
+
+def sound():
+ return ('foo', 'sounds/jungle.wav')
+
"""
import zipfile
import StringIO
diff --git a/Ground.py b/Ground.py
index 6a62e30..512f2ad 100644
--- a/Ground.py
+++ b/Ground.py
@@ -19,17 +19,22 @@ from sugar.graphics.objectchooser import ObjectChooser
import Theme
+def load():
+ ground = Document.ground()
+ custom = Ground(ground[0], None, False)
+ custom._pixbuf = ground[1]
+ THEMES.insert(-1, custom)
+
class Ground:
def __init__(self, name, file, custom):
self.name = name
- self._pixbuf = Theme.pixbuf(file)
+ if file: 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)
+ self._thumb = Theme.scale(self._pixbuf)
return self._thumb
def orig(self):
@@ -38,22 +43,8 @@ class Ground:
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()
-
- 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
+ else:
+ return Theme.choose(lambda title, file: Ground(title, file, False))
THEMES = (
Ground(_('Saturn'), 'images/backpics/bigbg01.gif', None),
diff --git a/Sound.py b/Sound.py
index c678b95..86a59c5 100644
--- a/Sound.py
+++ b/Sound.py
@@ -15,44 +15,78 @@
import os
import gtk
import gst
+from glob import glob
from gettext import gettext as _
import Theme
from Utils import *
from sugar.activity.activity import get_bundle_path
+TYPE_PREISTALLED = 0
+TYPE_CUSTOM = 1
+TYPE_JOURNAL = 2
+
+def load():
+ sound = Document.sound()
+ custom = Sound(sound[0], 'images/sounds/speaker.png', sound[1])
+ THEMES.insert(-1, custom)
+
class Sound:
playing = False
current = None
player = None
- def __init__(self, name, file, sound):
+ def __init__(self, name, file, sound, type):
self.name = name
- self.pixbuf = Theme.pixbuf(file, THUMB_SIZE)
- self.sound = sound
+ self._thumb = Theme.pixbuf(file, THUMB_SIZE)
+ self._type = type
+
+ if type == TYPE_JOURNAL:
+ l = sorted(glob(os.path.join(Theme.SESSION_PATH, 'sound*')))
+ self._sound = os.path.join(Theme.SESSION_PATH,
+ 'sound.%03d' % (len(l)+1))
+ os.rename(sound, self._sound)
+ else:
+ self._sound = sound
def thumb(self):
- return self.pixbuf
+ return self._thumb
def change(self):
+ out = self
+
+ if self._type == TYPE_CUSTOM:
+ out = Theme.choose(
+ lambda title, file: Sound(title,
+ 'images/sounds/speaker.png', file, TYPE_JOURNAL))
+ if not out:
+ return None
+
Sound.current = self
- if not Sound.playing: return
+ if not Sound.playing: return out
Sound.player.set_state(gst.STATE_NULL)
- if not self.sound: return
+ if not out._sound: return out
- Sound.player.set_property('uri', 'file://' + Theme.path(self.sound))
+ Sound.player.set_property('uri', 'file://' + Theme.path(out._sound))
Sound.player.set_state(gst.STATE_NULL)
Sound.player.set_state(gst.STATE_PLAYING)
+ return out
+
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),
+ Sound(_('Gobble'), 'images/sounds/speaker.png', 'sounds/gobble.wav',
+ TYPE_PREISTALLED),
+ Sound(_('Funk'), 'images/sounds/speaker.png', 'sounds/funk.wav',
+ TYPE_PREISTALLED),
+ Sound(_('Giggle'), 'images/sounds/speaker.png', 'sounds/giggle.wav',
+ TYPE_PREISTALLED),
+ Sound(_('Jungle'), 'images/sounds/speaker.png', 'sounds/jungle.wav',
+ TYPE_PREISTALLED),
+ Sound(_('Mute'), 'images/sounds/mute.png', None,
+ TYPE_PREISTALLED),
None,
- Sound(_('Custom'), 'images/sounds/custom.png', None) )
-
+ Sound(_('Custom'), 'images/sounds/custom.png', None,
+ TYPE_CUSTOM) )
Sound.current = THEMES[0]
def play():
diff --git a/Theme.py b/Theme.py
index 6aa5fc8..8329bb6 100644
--- a/Theme.py
+++ b/Theme.py
@@ -14,8 +14,9 @@
import os
import gtk
+import shutil
-from sugar.activity.activity import get_bundle_path
+from sugar.activity.activity import get_bundle_path, get_activity_root
from sugar.graphics import style
TRANSIMG = '50x50blank-trans.png'
@@ -77,6 +78,11 @@ OLD_COLOR_BG_BUTTONS = (
(gtk.STATE_INSENSITIVE,"#027F01"),
)
+SESSION_PATH = os.path.join(get_activity_root(), 'tmp', '.session')
+if os.path.isdir(SESSION_PATH):
+ shutil.rmtree(SESSION_PATH)
+os.mkdir(SESSION_PATH)
+
def path(file):
if os.path.isabs(file):
return file
@@ -92,8 +98,10 @@ def pixbuf(file, size = None):
EMPTY_PIXBUF = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, True, 8, 1, 1)
+def scale(pixbuf, size = THUMB_SIZE):
+ return pixbuf.scale_simple(size, size, gtk.gdk.INTERP_BILINEAR)
-def choose_pixbuf(out_fun):
+def choose(out_fun):
from sugar.graphics.objectchooser import ObjectChooser
chooser = ObjectChooser()
diff --git a/Utils.py b/Utils.py
index a816bb9..7931776 100644
--- a/Utils.py
+++ b/Utils.py
@@ -13,6 +13,7 @@
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
import gtk
+import pango
from Theme import *
import sugar.graphics
@@ -56,6 +57,7 @@ class ComboBox(sugar.graphics.combobox.ComboBox):
if not self._text_renderer and text:
self._text_renderer = gtk.CellRendererText()
+ self._text_renderer.props.ellipsize = pango.ELLIPSIZE_END
self.pack_end(self._text_renderer, True)
self.add_attribute(self._text_renderer, 'text', 1)
diff --git a/Main.py b/View.py
index be48034..98815df 100644
--- a/Main.py
+++ b/View.py
@@ -56,115 +56,25 @@ class FrameWidget(gtk.DrawingArea):
if self.bgpixbuf:
pixbuf = self.bgpixbuf
if pixbuf.get_width != self.width:
- pixbuf = pixbuf.scale_simple(self.width, self.height,
- gtk.gdk.INTERP_BILINEAR)
+ 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 = pixbuf.scale_simple(self.width,
- self.height, gtk.gdk.INTERP_BILINEAR)
+ pixbuf = Theme.scale(pixbuf, self.width)
widget.window.draw_pixbuf(self.gc, pixbuf, 0, 0, 0, 0, -1, -1, 0, 0)
def draw(self):
self.queue_draw()
-class CartoonBuilder:
- def play(self):
- self.play_tape_num = 0
- self._playing = gobject.timeout_add(self.waittime, self._play_tape)
-
- def stop(self):
- self._playing = None
-
- def set_tempo(self, tempo):
- self.waittime = int((6-tempo) * 150)
- if self._playing:
- gobject.source_remove(self._playing)
- self._playing = gobject.timeout_add(self.waittime, self._play_tape)
-
- def clear_tape(self):
- for i in range(TAPE_COUNT):
- Document.clean(i)
- self.screen.fgpixbuf = Document.orig(self.tape_selected)
- self.screen.draw()
-
- def _play_tape(self):
- self.screen.fgpixbuf = Document.orig(self.play_tape_num)
- self.screen.draw()
-
- self.play_tape_num += 1
- if self.play_tape_num == TAPE_COUNT:
- self.play_tape_num = 0
-
- if self._playing:
- return True
- else:
- return False
-
- def _tape_cb(self, widget, event, index):
- tape = self.tape[index]
- tape.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse(YELLOW))
- tape.modify_bg(gtk.STATE_PRELIGHT, gtk.gdk.color_parse(YELLOW))
-
- if self.tape_selected != index:
- if self.tape_selected != -1:
- old_tape = self.tape[self.tape_selected]
- old_tape.modify_bg(gtk.STATE_NORMAL,gtk.gdk.color_parse(BLACK))
- old_tape.modify_bg(gtk.STATE_PRELIGHT,gtk.gdk.color_parse(BLACK))
-
- self.tape_selected = index
- self.screen.fgpixbuf = Document.orig(index)
- self.screen.draw()
-
- def _frame_cb(self, widget, event, frame):
- orig = self.char.orig(frame)
- if not orig: return
- thumb = self.char.thumb(frame)
-
- Document.stamp(self.tape_selected, orig)
- self.tape[self.tape_selected].child.set_from_pixbuf(thumb)
- self.frames[frame].set_from_pixbuf(thumb)
-
- self._tape_cb(None, None, self.tape_selected)
-
- def _char_cb(self, widget, combo):
- self.char = widget.props.value
- self.char.change()
- for i in range(len(self.frames)):
- self.frames[i].set_from_pixbuf(self.char.thumb(i))
-
- def _ground_cb(self, widget, combo):
- choice = widget.props.value.change()
-
- 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.THUMB_SIZE, Theme.THUMB_SIZE),
- pixbuf = choice.thumb(), position = pos)
- combo.set_active(pos)
-
- self._prev_ground = widget.get_active()
- self.screen.bgpixbuf = choice.orig()
- self.screen.draw()
-
- def _sound_cb(self, widget, combo):
- widget.props.value.change()
-
- def _screen_size_cb(self, widget, aloc):
- size = min(aloc.width, aloc.height)
- widget.child.set_size_request(size, size)
-
+class View:
def __init__(self):
self._playing = None
self.waittime = 3*150
self.tape = []
self.frames = []
+ self._prev_combo_selected = {}
# frames table
@@ -174,16 +84,13 @@ class CartoonBuilder:
int(ceil(float(FRAME_COUNT) / FRAME_COLS)))
self.table = gtk.Table(rows, columns=Theme.FRAME_COLS, homogeneous=False)
- self.table.show()
for y in range(rows):
for x in range(Theme.FRAME_COLS):
image = gtk.Image()
- image.show()
self.frames.append(image)
image_box = gtk.EventBox()
- image_box.show()
image_box.set_events(gtk.gdk.BUTTON_PRESS_MASK)
image_box.connect('button_press_event', self._frame_cb,
y * Theme.FRAME_COLS + x)
@@ -198,26 +105,21 @@ class CartoonBuilder:
# frames box
table_scroll = VScrolledBox()
- table_scroll.show()
table_scroll.set_viewport(self.table)
table_scroll.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse(BUTTON_BACKGROUND))
yellow_frames = gtk.EventBox()
yellow_frames.modify_bg(gtk.STATE_NORMAL,gtk.gdk.color_parse(YELLOW))
- yellow_frames.show()
table_frames = gtk.EventBox()
table_frames.modify_bg(gtk.STATE_NORMAL,gtk.gdk.color_parse(BACKGROUND))
- table_frames.show()
table_frames.set_border_width(5)
table_frames.add(table_scroll)
yellow_frames.add(table_frames)
yelow_arrow = gtk.Image()
yelow_arrow.set_from_file(Theme.path('icons/yellow_arrow.png'))
- yelow_arrow.show()
frames_box = gtk.VBox()
- frames_box.show()
frames_box.pack_start(yellow_frames, True, True)
frames_box.pack_start(yelow_arrow, False, False)
frames_box.props.border_width = 20
@@ -225,13 +127,10 @@ class CartoonBuilder:
# screen
self.screen = FrameWidget()
- self.screen.show()
screen_pink = gtk.EventBox()
screen_pink.modify_bg(gtk.STATE_NORMAL,gtk.gdk.color_parse(PINK))
- screen_pink.show()
screen_box = gtk.EventBox()
screen_box.set_border_width(5)
- screen_box.show()
screen_box.add(self.screen)
screen_pink.add(screen_box)
screen_pink.props.border_width = 20
@@ -239,22 +138,18 @@ class CartoonBuilder:
# tape
tape = gtk.HBox()
- tape.show()
for i in range(TAPE_COUNT):
frame_box = gtk.VBox()
- frame_box.show()
filmstrip_pixbuf = gtk.gdk.pixbuf_new_from_file_at_scale(
Theme.path('icons/filmstrip.png'), THUMB_SIZE, -1, False)
filmstrip = gtk.Image()
filmstrip.set_from_pixbuf(filmstrip_pixbuf);
- filmstrip.show()
frame_box.pack_start(filmstrip, True, False)
frame = gtk.EventBox()
- frame.show()
frame.set_events(gtk.gdk.BUTTON_PRESS_MASK)
frame.connect('button_press_event', self._tape_cb, i)
frame.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse(BLACK))
@@ -265,13 +160,11 @@ class CartoonBuilder:
self.tape.append(frame)
frame_image = gtk.Image()
- frame_image.set_from_pixbuf(Document.thumb(i))
- frame_image.show()
+ frame_image.set_from_pixbuf(Document.tape_thumb(i))
frame.add(frame_image)
filmstrip = gtk.Image()
filmstrip.set_from_pixbuf(filmstrip_pixbuf);
- filmstrip.show()
frame_box.pack_start(filmstrip, False, False)
tape.pack_start(frame_box, False, False)
@@ -281,40 +174,16 @@ class CartoonBuilder:
# left control box
- def new_combo(themes, cb):
- combo = ComboBox()
- combo.show()
- for i in themes:
- if not i:
- combo.append_separator()
- continue
-
- 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)
- return combo
-
- controlbox = gtk.VBox()
- controlbox.show()
- controlbox.props.border_width = 10
- controlbox.props.spacing = 10
- controlbox.pack_start(new_combo(Char.THEMES, self._char_cb),
- True, False)
- controlbox.pack_start(new_combo(Ground.THEMES, self._ground_cb),
- True, False)
- controlbox.pack_start(new_combo(Sound.THEMES, self._sound_cb),
- True, False)
+ self.controlbox = gtk.VBox()
+ self.controlbox.props.border_width = 10
+ self.controlbox.props.spacing = 10
leftbox = gtk.VBox()
- leftbox.show()
logo = gtk.Image()
- logo.show()
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(controlbox, True, True)
+ leftbox.pack_start(self.controlbox, True, True)
# screen box
@@ -323,12 +192,10 @@ class CartoonBuilder:
screen_alignment.connect('size-allocate', self._screen_size_cb)
cetralbox = gtk.HBox()
- cetralbox.show()
cetralbox.pack_start(screen_alignment, True, True)
cetralbox.pack_start(frames_box, True, False)
hdesktop = gtk.HBox()
- hdesktop.show()
hdesktop.pack_start(leftbox,False,True,0)
hdesktop.pack_start(cetralbox,True,True,0)
@@ -336,18 +203,14 @@ class CartoonBuilder:
arrow = gtk.Image()
arrow.set_from_file(Theme.path('icons/pink_arrow.png'))
- arrow.show()
animborder = gtk.EventBox()
animborder.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse(PINK))
- animborder.show()
animframe = gtk.EventBox()
animframe.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse(BACKGROUND))
animframe.set_border_width(5)
- animframe.show()
animframe.add(tape)
animborder.add(animframe)
animbox = gtk.HBox()
- animbox.show()
animbox.pack_start(animborder, True, False)
tape_box = gtk.VBox()
tape_box.props.border_width = 10
@@ -355,20 +218,136 @@ class CartoonBuilder:
tape_box.pack_start(animbox, False, False, 0)
desktop = gtk.VBox()
- desktop.show()
desktop.pack_start(hdesktop,True,True,0)
desktop.pack_start(tape_box, False, False, 0)
greenbox = gtk.EventBox()
greenbox.modify_bg(gtk.STATE_NORMAL,gtk.gdk.color_parse(BACKGROUND))
greenbox.set_border_width(5)
- greenbox.show()
greenbox.add(desktop)
yellowbox = gtk.EventBox()
yellowbox.modify_bg(gtk.STATE_NORMAL,gtk.gdk.color_parse(YELLOW))
- yellowbox.show()
yellowbox.add(greenbox)
+ yellowbox.show_all()
self.main = yellowbox
- self.main.show_all()
+ yellowbox.connect_after('map', self.map_cb)
+
+ def map_cb(self, widget):
+ def new_combo(themes, cb):
+ combo = ComboBox()
+
+ for i in themes:
+ if not i:
+ combo.append_separator()
+ continue
+
+ combo.append_item(i, text = i.name,
+ size = (Theme.THUMB_SIZE, Theme.THUMB_SIZE),
+ pixbuf = i.thumb())
+
+ combo.connect('changed', cb)
+ combo.set_active(0)
+ combo.show()
+
+ return combo
+
+ self.controlbox.pack_start(new_combo(Char.THEMES, self._char_cb),
+ True, False)
+ self.controlbox.pack_start(new_combo(Ground.THEMES, self._ground_cb),
+ True, False)
+ self.controlbox.pack_start(new_combo(Sound.THEMES, self._combo_cb),
+ True, False)
+
+ return False
+
+ def play(self):
+ self.play_tape_num = 0
+ self._playing = gobject.timeout_add(self.waittime, self._play_tape)
+
+ def stop(self):
+ self._playing = None
+
+ def set_tempo(self, tempo):
+ self.waittime = int((6-tempo) * 150)
+ if self._playing:
+ gobject.source_remove(self._playing)
+ self._playing = gobject.timeout_add(self.waittime, self._play_tape)
+
+ def clear_tape(self):
+ for i in range(TAPE_COUNT):
+ Document.tape_clean(i)
+ self.screen.fgpixbuf = Document.tape_orig(self.tape_selected)
+ self.screen.draw()
+
+ def _play_tape(self):
+ self.screen.fgpixbuf = Document.tape_orig(self.play_tape_num)
+ self.screen.draw()
+
+ self.play_tape_num += 1
+ if self.play_tape_num == TAPE_COUNT:
+ self.play_tape_num = 0
+
+ if self._playing:
+ return True
+ else:
+ return False
+
+ def _tape_cb(self, widget, event, index):
+ tape = self.tape[index]
+ tape.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse(YELLOW))
+ tape.modify_bg(gtk.STATE_PRELIGHT, gtk.gdk.color_parse(YELLOW))
+
+ if self.tape_selected != index:
+ if self.tape_selected != -1:
+ old_tape = self.tape[self.tape_selected]
+ old_tape.modify_bg(gtk.STATE_NORMAL,gtk.gdk.color_parse(BLACK))
+ old_tape.modify_bg(gtk.STATE_PRELIGHT,gtk.gdk.color_parse(BLACK))
+
+ self.tape_selected = index
+ self.screen.fgpixbuf = Document.tape_orig(index)
+ self.screen.draw()
+
+ def _frame_cb(self, widget, event, frame):
+ orig = self.char.orig(frame)
+ if not orig: return
+ thumb = self.char.thumb(frame)
+
+ Document.tape_stamp(self.tape_selected, orig)
+ self.tape[self.tape_selected].child.set_from_pixbuf(thumb)
+ self.frames[frame].set_from_pixbuf(thumb)
+
+ self._tape_cb(None, None, self.tape_selected)
+
+ def _char_cb(self, widget):
+ self.char = widget.props.value
+ for i in range(len(self.frames)):
+ self.frames[i].set_from_pixbuf(self.char.thumb(i))
+
+ def _combo_cb(self, widget):
+ choice = widget.props.value.change()
+
+ if not choice:
+ widget.set_active(self._prev_combo_selected[widget])
+ return None
+
+ 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),
+ pixbuf = choice.thumb(), position = pos)
+ widget.set_active(pos)
+
+ self._prev_combo_selected[widget] = widget.get_active()
+ return choice
+
+ def _ground_cb(self, widget):
+ choice = self._combo_cb(widget)
+ if choice:
+ self.screen.bgpixbuf = choice.orig()
+ self.screen.draw()
+
+ def _screen_size_cb(self, widget, aloc):
+ size = min(aloc.width, aloc.height)
+ widget.child.set_size_request(size, size)