From 72d6a2440464c7eed908a154d0a782fb9bd2f236 Mon Sep 17 00:00:00 2001 From: Agustin Zubiaga Date: Tue, 24 Jul 2012 03:26:59 +0000 Subject: Add frame works, select frame works, but the animation can only be seen in fullscreen mode --- diff --git a/activity.py b/activity.py index c8d765c..ff40855 100644 --- a/activity.py +++ b/activity.py @@ -55,6 +55,7 @@ class AnimateActivity(activity.Activity): self._toolbarbox.show_all() canvas = gtk.EventBox() + canvas.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse('white')) self._animation = None self._animation_frames = [] @@ -62,8 +63,8 @@ class AnimateActivity(activity.Activity): self.modes_buttons = self._toolbarbox.modes_buttons self._frames_tray = FramesTray() -# self._frames_tray.connect("current-frame-changed", -# self._current_frame_changed_cb) + self._frames_tray.connect("current-frame-changed", + self._current_frame_changed_cb) # self._frames_tray.connect("move", self._move_cb) # self._frames_tray.connect('get-current-frame', # lambda w: self._animation.get_current_frame()) @@ -147,7 +148,7 @@ class AnimateActivity(activity.Activity): jobject = chooser.get_selected_object() pixbuf = gtk.gdk.pixbuf_new_from_file(jobject.get_file_path()) self._animation.add_frame(pixbuf) - self._frames_list.add_frame(pixbuf) + self._frames_tray.add_frame(pixbuf) else: return @@ -183,9 +184,9 @@ class AnimateActivity(activity.Activity): def _get_animation_size(self): canvas_allocation = self.get_canvas().get_allocation() - treeview_allocation = self._frames_list.get_allocation() + tray_allocation = self._frames_tray.get_allocation() - width = canvas_allocation[-2] - treeview_allocation[-2] + width = canvas_allocation[-2] - tray_allocation[-2] height = canvas_allocation[-1] return width, height @@ -195,9 +196,10 @@ class AnimateActivity(activity.Activity): if not self._animation: self._animation = animation.Animation(width, height) - self._animation.set_mode(self._animation_mode) - self._animation.connect('running', - self._frames_toolbar.set_buttons_sensitive) + if self._animation_mode: + self._animation.set_mode(self._animation_mode) + #self._animation.connect('running', + # self._frames_toolbar.set_buttons_sensitive) for pixbuf in self._animation_frames: self._animation.add_frame(pixbuf) self._frames_tray.add_frame(pixbuf) @@ -206,24 +208,24 @@ class AnimateActivity(activity.Activity): self._current_frame_updated_cb) self._animation.show_all() - del self._animation_mode + self._animation_mode = None canvas.add(self._animation) def _current_frame_updated_cb(self, widget, index): if widget.frames_reverse: index = len(widget.frames) - 1 - index - self._frames_list.select_frame(index) + self._frames_tray.select_frame(index) return index def _view_fullscreen(self, widget): - self._frames_try.hide() + self._frames_tray.hide() self._animation.set_size(gtk.gdk.screen_width(), gtk.gdk.screen_height()) activity.Activity.fullscreen(self) def unfullscreen(self): - self._framestray.show() + self._frames_tray.show() width, height = self._get_animation_size() self._animation.set_size(width, height) diff --git a/frames_tray.py b/frames_tray.py index 621e20b..f048b4d 100644 --- a/frames_tray.py +++ b/frames_tray.py @@ -22,27 +22,69 @@ # MA 02110-1301, USA. import gtk +import gobject +from sugar.graphics import style from sugar.graphics.tray import HTray +from sugar.graphics.radiotoolbutton import RadioToolButton class FramesTray(HTray): + __gsignals__ = {"current-frame-changed": (gobject.SIGNAL_RUN_LAST, + gobject.TYPE_NONE, + (gobject.TYPE_INT,))} + def __init__(self): HTray.__init__(self) + self._group = None + self._frames_count = 0 + self.set_size_request(-1, style.LARGE_ICON_SIZE + 10) + self.show() - def add_frame(self): - item = FrameWidget() + def add_frame(self, pixbuf): + self._frames_count += 1 + item = FrameWidget(pixbuf, self._frames_count) + + if not self._group: + self._group = item + else: + item.set_group(self._group) self.add_item(item) def remove_frame(self): return + def select_frame(self, index): + self.get_children()[index].set_active(True) -class FrameWidget(gtk.ToolItem): + def _frame_selected(self, index): + self.emit('current-frame-changed', index) - def __init__(self): - gtk.ToolItem.__init__(self) +class FrameWidget(RadioToolButton): + + __gsignals__ = {"frame-selected": (gobject.SIGNAL_RUN_LAST, + gobject.TYPE_NONE, + (gobject.TYPE_INT,))} + + def __init__(self, pixbuf, index): + super(FrameWidget, self).__init__() + + self._index = index + + width = pixbuf.get_width() + height = pixbuf.get_height() + preview_pixbuf = pixbuf.scale_simple(style.LARGE_ICON_SIZE * + width / height, + style.LARGE_ICON_SIZE, + gtk.gdk.INTERP_TILES) + image = gtk.image_new_from_pixbuf(preview_pixbuf) + self.set_icon_widget(image) + + image.show() self.show() + + def __frame_selected_cb(self, widget): + self.emit('frame-selected', self._index) -- cgit v0.9.1