diff options
author | Agustin Zubiaga <aguz@sugarlabs.org> | 2012-05-26 03:40:37 (GMT) |
---|---|---|
committer | Agustin Zubiaga <aguz@sugarlabs.org> | 2012-05-26 03:42:53 (GMT) |
commit | 341506dbcffded7581b6108105bc921d3ed3b955 (patch) | |
tree | 9ee53040e70f2d4f6b1174c5c894dd0e70bc9fe8 | |
parent | a9841fa320cdbcb6e60e6afe771f9b6fba893071 (diff) |
Run button added but works with bugs :|
Other changes:
* When an item in the list is clicked show his image (but doesn't works well)
* set_pos function added
Signed-off-by: Agustin Zubiaga <aguz@sugarlabs.org>
-rw-r--r-- | TODO | 3 | ||||
-rw-r--r-- | activity.py | 19 | ||||
-rw-r--r-- | animation.py | 40 | ||||
-rw-r--r-- | frames_list.py | 16 |
4 files changed, 59 insertions, 19 deletions
@@ -4,4 +4,5 @@ New functions: Fixes: Void. Bugs: - No reported. + - Don't shows the correct always when the List is clicked + - Don't sets the images when are just added diff --git a/activity.py b/activity.py index b228cf9..330034b 100644 --- a/activity.py +++ b/activity.py @@ -60,6 +60,16 @@ class AnimateActivity(activity.Activity): toolbarbox.toolbar.insert(add_image, -1) separator = gtk.SeparatorToolItem() + separator.set_expand(False) + separator.set_draw(True) + toolbarbox.toolbar.insert(separator, -1) + + run_btn = ToolButton('media-playback-start') + run_btn.set_tooltip(_('Run animation')) + run_btn.connect('clicked', self._run_animation) + toolbarbox.toolbar.insert(run_btn, -1) + + separator = gtk.SeparatorToolItem() separator.set_expand(True) separator.set_draw(False) toolbarbox.toolbar.insert(separator, -1) @@ -89,12 +99,15 @@ class AnimateActivity(activity.Activity): if result == gtk.RESPONSE_ACCEPT: jobject = chooser.get_selected_object() pixbuf = gtk.gdk.pixbuf_new_from_file(jobject.get_file_path()) - self._frames_list.add_frame(pixbuf) - self._animation.add_image(jobject.get_file_path()) + self._frames_list.add_frame(pixbuf, jobject.get_file_path()) else: return + def _run_animation(self, widget): + self._animation._images = [i[-1] for i in self._frames_list.store] + self._animation.run() + def __canvas_expose_cb(self, canvas, event): canvas_allocation = canvas.get_allocation() treeview_allocation = self._frames_list.get_allocation() @@ -104,4 +117,6 @@ class AnimateActivity(activity.Activity): self._animation = Animation(width, height) self._animation.show_all() + + self._frames_list._animation = self._animation canvas.pack_start(self._animation, True, True, 0) diff --git a/animation.py b/animation.py index d169954..b2e3d87 100644 --- a/animation.py +++ b/animation.py @@ -38,6 +38,7 @@ class Animation(gtk.Image): self._current_image = 0 self._timeout = None self._return = True + self._running = False self._images = [] self._size = width, height @@ -50,26 +51,39 @@ class Animation(gtk.Image): def add_image(self, image_path): """Appends an image to the list""" - self._images.append(image_path) + self._images += [image_path] def run(self): """Runs the animation""" - try: - pixbuf = gtk.gdk.pixbuf_new_from_file_at_size( - self._images[self._current_image], - self._size[0] - 10, self._size[1] - 10) + if not self._running: + try: + pixbuf = gtk.gdk.pixbuf_new_from_file_at_size( + self._images[self._current_image], + self._size[0], self._size[1]) - self.set_from_pixbuf(pixbuf) + self.set_from_pixbuf(pixbuf) - self._timeout = gobject.timeout_add(self._sleep_time, self.next) + self._running = True + self._timeout = gobject.timeout_add(self._sleep_time, self.next) + _logger.info(" Running!") - except IndexError: - _logger.error(" There aren't images") + except IndexError: + _logger.error(" There aren't images") + else: + _logger.error(" The animation is runing already") + + def set_pos(self, pos): + self._current_image = pos + pixbuf = gtk.gdk.pixbuf_new_from_file_at_size( + self._images[self._current_image], + self._size[0], self._size[1]) + + self.set_from_pixbuf(pixbuf) def stop(self): """Stops the animation""" gobject.source_remove(self._timeout) - self._timeout = None + self._running = False def next(self): """Shows the next frame""" @@ -81,11 +95,11 @@ class Animation(gtk.Image): pixbuf = gtk.gdk.pixbuf_new_from_file_at_size( self._images[self._current_image], - self._size[0] - 10, self._size[1] - 10) + self._size[0], self._size[1]) self.set_from_pixbuf(pixbuf) - return True + return self._running def back(self): """Shows the previous frame""" @@ -97,6 +111,6 @@ class Animation(gtk.Image): pixbuf = gtk.gdk.pixbuf_new_from_file_at_size( self._images[self._current_image], - self._size[0] - 10, self._size[1] - 10) + self._size[0], self._size[1]) self.set_from_pixbuf(pixbuf) diff --git a/frames_list.py b/frames_list.py index 76047f8..d36bca5 100644 --- a/frames_list.py +++ b/frames_list.py @@ -29,26 +29,36 @@ class FramesList(gtk.ScrolledWindow): super(FramesList, self).__init__() self.set_size_request(225, -1) self.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC) - self.store = gtk.ListStore(int, gtk.gdk.Pixbuf) + self.store = gtk.ListStore(int, gtk.gdk.Pixbuf, str) self.treeview = gtk.TreeView(self.store) self.set_vadjustment(self.treeview.get_vadjustment()) + self.treeview.connect("row-activated", self._row_activated_cb) column = gtk.TreeViewColumn("Frame") self.treeview.append_column(column) num_cell = gtk.CellRendererText() preview_cell = gtk.CellRendererPixbuf() + path_cell = gtk.CellRendererText() column.pack_start(num_cell) column.pack_start(preview_cell) + column.pack_start(path_cell) column.add_attribute(num_cell, 'text', 0) column.add_attribute(preview_cell, 'pixbuf', 1) + column.add_attribute(path_cell, 'text', 2) + path_cell.set_property('visible', False) self.treeview.show() self.add(self.treeview) self.frames = 0 - def add_frame(self, pixbuf): + def add_frame(self, pixbuf, imagepath): self.frames += 1 width = pixbuf.get_width() height = pixbuf.get_height() preview_pixbuf = pixbuf.scale_simple(200, 200 * height / width, gtk.gdk.INTERP_TILES) - self.store.append([self.frames, preview_pixbuf]) + self.store.append([self.frames, preview_pixbuf, imagepath]) + + def _row_activated_cb(self, treeview, treepath, column): + #FIXME: I don't show the correct image always + self._animation._images = [i[-1] for i in self.store] + self._animation.set_pos(treepath[0]) |