diff options
author | Aleksey Lim <alsroot@member.fsf.org> | 2009-02-01 01:57:04 (GMT) |
---|---|---|
committer | Aleksey Lim <alsroot@member.fsf.org> | 2009-02-01 01:57:04 (GMT) |
commit | 4af506e8a79b598541387fbfe92d0cfbfc1c0c08 (patch) | |
tree | eab0ba1f11b0419ee8d8584c57023aa9d9ab57ad | |
parent | e02b2e586759e2582c5f361d3e81d703a44d6d23 (diff) |
play button
-rw-r--r-- | Activity.py | 7 | ||||
-rw-r--r-- | Char.py | 111 | ||||
-rw-r--r-- | Document.py | 5 | ||||
-rw-r--r-- | Toolbar.py | 12 | ||||
-rw-r--r-- | Utils.py | 4 | ||||
-rw-r--r-- | View.py | 55 |
6 files changed, 59 insertions, 135 deletions
diff --git a/Activity.py b/Activity.py index 4446a80..878d427 100644 --- a/Activity.py +++ b/Activity.py @@ -25,7 +25,7 @@ from gettext import gettext as _ from sugar.activity.activity import get_activity_root from View import View -from Toolbar import * +from Toolbar import Toolbar import Document import Char import Ground @@ -35,7 +35,7 @@ SERVICE = 'org.freedesktop.Telepathy.Tube.Connect' IFACE = SERVICE PATH = '/org/freedesktop/Telepathy/Tube/Connect' -TMPDIR = os.path.join(get_activity_root(), 'tmp') +#TMPDIR = os.path.join(get_activity_root(), 'tmp') class CartoonBuilderActivity(activity.Activity): def __init__(self, handle): @@ -43,6 +43,9 @@ class CartoonBuilderActivity(activity.Activity): self.app = View() toolbox = activity.ActivityToolbox(self) + bgtoolbar = Toolbar(self,self.app) + toolbox.add_toolbar(_('Background'),bgtoolbar) + bgtoolbar.show() self.set_toolbox(toolbox) toolbox.show() self.set_canvas(self.app.main) @@ -94,6 +94,14 @@ class Char: return pix + def clean(self, index): + if self._type != CUSTOM: + return + if self._thumbs.has_key(index): + del self._thumbs[index] + if self._origs.has_key(index): + del self._origs[index] + THEMES = ( Char(_('Elephant'), 'images/pics/Elephant/bigelephant0.gif', 'images/pics/Elephant', PREINSTALLED), @@ -103,106 +111,3 @@ THEMES = ( 'images/pics/Turkey', PREINSTALLED), None, Char(_('Custom'), 'images/pics/custom.png', None, CUSTOM)) - - - - - -""" -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) - self.ccismall.set_from_pixbuf(scaled_buf) - self.charlabel.set_label(os.path.split(self.imgdir)[1]) - - - def restore(self, sdata): - # THE BELOW SHOULD WORK BUT DOESN'T - #zf = StringIO.StringIO(sdata) - #self.loadfromzip(zf) - # END OF STUFF THAT DOESN'T WORK - sdd = pickle.loads(sdata) - tmpbgpath = os.path.join(TMPDIR,'back.png') - f = file(tmpbgpath,'w') - f.write(sdd['pngdata']) - f.close() - self.setback(tmpbgpath) - os.remove(tmpbgpath) - transimgpath = os.path.join(self.iconsdir,TRANSIMG) - for i in range(len(sdd['fgpixbufpaths'])): - filepath = sdd['fgpixbufpaths'][i] - if filepath == transimgpath: - continue - pixbuf = gtk.gdk.pixbuf_new_from_file(filepath) - fgpixbuf = pixbuf.scale_simple(BGWIDTH,BGHEIGHT,gtk.gdk.INTERP_BILINEAR) - self.fgpixbufs[i] = fgpixbuf - if i == 0: - self.fgpixbuf = fgpixbuf - self.drawmain() - scaled_buf = pixbuf.scale_simple(IMGWIDTH,IMGHEIGHT,gtk.gdk.INTERP_BILINEAR) - self.frameimgs[i].set_from_pixbuf(scaled_buf) - - - def loadfromzip(self, f): - # print filepath - #zf = zipfile.ZipFile(filepath,'r') - zf = zipfile.ZipFile(f) - 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) - -def prepare_btn(btn, w=-1, h=-1): - for state, color in COLOR_BG_BUTTONS: - btn.modify_bg(state, gtk.gdk.color_parse(color)) - c = btn.get_child() - if c is not None: - for state, color in COLOR_FG_BUTTONS: - c.modify_fg(state, gtk.gdk.color_parse(color)) - else: - for state, color in COLOR_FG_BUTTONS: - btn.modify_fg(state, gtk.gdk.color_parse(color)) - if w>0 or h>0: - btn.set_size_request(w, h) - return btn - - -""" diff --git a/Document.py b/Document.py index 6e8e7cf..a700f75 100644 --- a/Document.py +++ b/Document.py @@ -109,7 +109,10 @@ def load(filepath): if i >= Theme.TAPE_COUNT: continue if int(frame.attrib['preinstalled']): - Document.tape[i].orig = Theme.pixbuf(frame.attrib['filename']) + 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].filename = frame.attrib['filename'] else: pixbuf = loaded.get(frame.attrib['filename']) @@ -24,10 +24,10 @@ import Sound from Utils import * class Toolbar(gtk.Toolbar): - def __init__(self, activity, app): + def __init__(self, activity, view): gtk.Toolbar.__init__(self) self.activity = activity - self.app = app + self.view = view self.playButton = ToggleToolButton('media-playback-start') self.playButton.connect('toggled', self._play_cb) @@ -65,20 +65,20 @@ class Toolbar(gtk.Toolbar): self.show_all() def _clear_tape_cb(self, widget): - self.app.set_tempo(widget.value) + self.view.clear_tape() def _tempo_cb(self, widget): - self.app.set_tempo(widget.value) + self.view.set_tempo(widget.value) def _play_cb(self, widget): if widget.get_active(): widget.set_icon_widget(self.pauseButtonImg) Sound.play() - self.app.play() + self.view.play() else: widget.set_icon_widget(self.playButtonImg) Sound.stop() - self.app.stop() + self.view.stop() """ SPANISH = u'Espa\xf1ol' @@ -196,9 +196,9 @@ class ScrolledBox(gtk.EventBox): self._scrolled = gtk.ScrolledWindow() if orientation == gtk.ORIENTATION_HORIZONTAL: - self._scrolled.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_NEVER) + self._scrolled.set_policy(arrows_policy, gtk.POLICY_NEVER) else: - self._scrolled.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC) + self._scrolled.set_policy(gtk.POLICY_NEVER, arrows_policy) self._scrolled.connect('scroll-event', self._scroll_event_cb) box.pack_start(self._scrolled, True, True, 0) @@ -156,7 +156,7 @@ class View: 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_box.pack_start(frame, False, False) + frame_box.pack_start(frame) self.tape.append(frame) frame_image = gtk.Image() @@ -213,8 +213,6 @@ class View: animframe.set_border_width(5) animframe.add(tape_scroll) animborder.add(animframe) - #animbox = gtk.HBox() - #animbox.pack_start(animborder) tape_box = gtk.VBox() tape_box.props.border_width = 10 @@ -280,7 +278,7 @@ class View: self._playing = None def set_tempo(self, tempo): - self.waittime = int((6-tempo) * 150) + self.waittime = 10 + (10-tempo) * 100 if self._playing: gobject.source_remove(self._playing) self._playing = gobject.timeout_add(self.waittime, self._play_tape) @@ -292,19 +290,28 @@ class View: self.screen.draw() def _play_tape(self): + if not self._playing: + return False + self.screen.fgpixbuf = Document.tape[self.play_tape_num].orig self.screen.draw() - self.play_tape_num += 1 - if self.play_tape_num == TAPE_COUNT: - self.play_tape_num = 0 - - if self._playing: + for i in range(Theme.TAPE_COUNT): + self.play_tape_num += 1 + if self.play_tape_num == TAPE_COUNT: + self.play_tape_num = 0 + if Document.tape[self.play_tape_num].orig == Theme.EMPTY_ORIG: + continue return True - else: - return False + + self.stop() + return False def _tape_cb(self, widget, event, index): + if event and event.button == 3: + Document.tape[index].clean() + self.tape[index].child.set_from_pixbuf(Theme.EMPTY_THUMB) + 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)) @@ -312,24 +319,30 @@ class View: 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)) + 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[index].orig self.screen.draw() def _frame_cb(self, widget, event, frame): - orig = self.char.orig(frame) - if not orig: return - thumb = self.char.thumb(frame) + if event.button == 3: + self.char.clean(frame) + self.frames[frame].set_from_pixbuf(self.char.thumb(frame)) + else: + orig = self.char.orig(frame) + if not orig: return + thumb = self.char.thumb(frame) - Document.tape[self.tape_selected].orig = orig - Document.tape[self.tape_selected].filename = self.char.filename(frame) + Document.tape[self.tape_selected].orig = orig + Document.tape[self.tape_selected].filename = self.char.filename(frame) - 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) + 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, closure): self.char = widget.props.value |