diff options
author | Daniel Francis <francis@sugarlabs.org> | 2012-05-27 01:23:37 (GMT) |
---|---|---|
committer | Daniel Francis <francis@sugarlabs.org> | 2012-05-27 01:23:37 (GMT) |
commit | ff5683d49edb04efa8fb5c5cf839f0d0554c61d3 (patch) | |
tree | 995ce4a8bb59f1c1e7e10ac8e36981c67fda229a | |
parent | f4eeb4218e0c3987f003f3cab5ec73b48e9bc275 (diff) |
Scale images in the main canvas, fixing code style errors.
-rw-r--r-- | TODO | 9 | ||||
-rw-r--r-- | animation.py | 52 |
2 files changed, 35 insertions, 26 deletions
@@ -1,8 +1,7 @@ New functions: - - Add and remove frames from the Treeview. (In progress) - - Connect the selected image in the FramesList to the animation canvas. + - Save data in journal Fixes: - - Don't sets the images when are just added (Fixed) - - Can't pause the animation (Fixed) + - Select the frame in the list when the animation is running + - Use the treeselection in the place of row-selected event in treeview Bugs: - - Don't shows the correct always when the List is clicked + No reported. diff --git a/animation.py b/animation.py index 48265dc..8259bc8 100644 --- a/animation.py +++ b/animation.py @@ -51,17 +51,26 @@ class Animation(gtk.Image): def add_image(self, image_path): """Appends an image to the list""" - self.images += [image_path] + self.images.append(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._size[0], self._size[1]) - - self.set_from_pixbuf(pixbuf) + pixbuf = gtk.gdk.pixbuf_new_from_file(self.images[ + self._current_image]) + width = pixbuf.get_width() + height = pixbuf.get_height() + max_size = max(width, height) + if max_size is width: + scaled_pixbuf = pixbuf.scale_simple(self._size[0], + self._size[0] * height / width, + gtk.gdk.INTERP_TILES) + else: + scaled_pixbuf = pixbuf.scale_simple(self._size[1], + self.size[1] * width / height, + gtk.gdk.INTERP_TILES) + self.set_from_pixbuf(scaled_pixbuf) self._running = True self._timeout = gobject.timeout_add(self._sleep_time, self.next) @@ -74,11 +83,20 @@ class Animation(gtk.Image): 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) + pixbuf = gtk.gdk.pixbuf_new_from_file(self.images[self._current_image]) + width = pixbuf.get_width() + height = pixbuf.get_height() + max_size = max(width, height) + if max_size is width: + scaled_pixbuf = pixbuf.scale_simple(self._size[0], + self._size[0] * height / width, + gtk.gdk.INTERP_TILES) + else: + scaled_pixbuf = pixbuf.scale_simple(self._size[1], + self._size[1] * width / height, + gtk.gdk.INTERP_TILES) + self.set_from_pixbuf(scaled_pixbuf) + self.set_from_pixbuf(scaled_pixbuf) def pause(self): """Pause the animation""" @@ -93,11 +111,7 @@ class Animation(gtk.Image): 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._size[0], self._size[1]) - - self.set_from_pixbuf(pixbuf) + self.set_pos(self._current_image) return True @@ -109,8 +123,4 @@ class Animation(gtk.Image): elif self._current_image == 0 and self._return: self._current_image = -1 - 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_pos(self._current_image) |