diff options
author | Agustin Zubiaga <aguz@sugarlabs.org> | 2012-05-26 17:34:23 (GMT) |
---|---|---|
committer | Agustin Zubiaga <aguz@sugarlabs.org> | 2012-05-26 17:34:23 (GMT) |
commit | afdcf8cbea2aca30193f83066f951acc0f032746 (patch) | |
tree | c5748befbaa3c66b33f01a27d19dd0bfa879287f | |
parent | 341506dbcffded7581b6108105bc921d3ed3b955 (diff) |
Pause button added in Run button
-rw-r--r-- | TODO | 4 | ||||
-rw-r--r-- | activity.py | 17 | ||||
-rw-r--r-- | animation.py | 24 | ||||
-rw-r--r-- | frames_list.py | 2 |
4 files changed, 28 insertions, 19 deletions
@@ -2,7 +2,7 @@ New functions: - Add and remove frames from the Treeview. (In progress) - Connect the selected image in the FramesList to the animation canvas. Fixes: - Void. + - Don't sets the images when are just added + - Can't pause the animation (source_remove doesn't works) Bugs: - 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 330034b..204e82d 100644 --- a/activity.py +++ b/activity.py @@ -66,7 +66,7 @@ class AnimateActivity(activity.Activity): run_btn = ToolButton('media-playback-start') run_btn.set_tooltip(_('Run animation')) - run_btn.connect('clicked', self._run_animation) + run_btn.connect('clicked', self._run_pause_animation) toolbarbox.toolbar.insert(run_btn, -1) separator = gtk.SeparatorToolItem() @@ -104,9 +104,18 @@ class AnimateActivity(activity.Activity): else: return - def _run_animation(self, widget): - self._animation._images = [i[-1] for i in self._frames_list.store] - self._animation.run() + def _run_pause_animation(self, widget): + self._animation.images = [i[-1] for i in self._frames_list.store] + + if not self._animation._running: + self._animation.run() + widget.set_icon("media-playback-pause") + widget.set_tooltip(_("Pause animation")) + + elif self._animation._running: + self._animation.pause() + widget.set_icon("media-playback-pause") + widget.set_tooltip(_("Run animation")) def __canvas_expose_cb(self, canvas, event): canvas_allocation = canvas.get_allocation() diff --git a/animation.py b/animation.py index b2e3d87..48265dc 100644 --- a/animation.py +++ b/animation.py @@ -39,7 +39,7 @@ class Animation(gtk.Image): self._timeout = None self._return = True self._running = False - self._images = [] + self.images = [] self._size = width, height self._sleep_time = sleep_time * 1000 @@ -51,14 +51,14 @@ class Animation(gtk.Image): def add_image(self, image_path): """Appends an image to the list""" - self._images += [image_path] + self.images += [image_path] def run(self): """Runs the animation""" if not self._running: try: pixbuf = gtk.gdk.pixbuf_new_from_file_at_size( - self._images[self._current_image], + self.images[self._current_image], self._size[0], self._size[1]) self.set_from_pixbuf(pixbuf) @@ -70,36 +70,36 @@ class Animation(gtk.Image): except IndexError: _logger.error(" There aren't images") else: - _logger.error(" The animation is runing already") + _logger.error(" The animation is running 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.images[self._current_image], self._size[0], self._size[1]) self.set_from_pixbuf(pixbuf) - def stop(self): - """Stops the animation""" + def pause(self): + """Pause the animation""" gobject.source_remove(self._timeout) self._running = False def next(self): """Shows the next frame""" - if self._current_image != len(self._images) - 1: + if self._current_image != len(self.images) - 1: self._current_image += 1 - elif not self._current_image != len(self._images) - 1 and self._return: + elif not self._current_image != len(self.images) - 1 and self._return: self._current_image = 0 pixbuf = gtk.gdk.pixbuf_new_from_file_at_size( - self._images[self._current_image], + self.images[self._current_image], self._size[0], self._size[1]) self.set_from_pixbuf(pixbuf) - return self._running + return True def back(self): """Shows the previous frame""" @@ -110,7 +110,7 @@ class Animation(gtk.Image): self._current_image = -1 pixbuf = gtk.gdk.pixbuf_new_from_file_at_size( - self._images[self._current_image], + self.images[self._current_image], self._size[0], self._size[1]) self.set_from_pixbuf(pixbuf) diff --git a/frames_list.py b/frames_list.py index d36bca5..10b715b 100644 --- a/frames_list.py +++ b/frames_list.py @@ -60,5 +60,5 @@ class FramesList(gtk.ScrolledWindow): 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.images = [i[-1] for i in self.store] self._animation.set_pos(treepath[0]) |