From 6a79db9e131b629e66737eb32c74db430c8e7e5b Mon Sep 17 00:00:00 2001 From: Agustin Zubiaga Date: Mon, 28 May 2012 01:32:10 +0000 Subject: Few changes in animation mode, ping pong mode added --- diff --git a/TODO b/TODO index f288b6f..c41bc84 100644 --- a/TODO +++ b/TODO @@ -4,5 +4,6 @@ New functions: - Select the frames when the activitie loads them. Fixes: - Enable drag and drop between frames. + - Correct frame selection in ping pong mode Bugs: Void. diff --git a/activity.py b/activity.py index 06c6bfa..4375b7a 100644 --- a/activity.py +++ b/activity.py @@ -31,13 +31,14 @@ from sugar.activity.widgets import ActivityToolbarButton from sugar.graphics.objectchooser import ObjectChooser from sugar.graphics.toolbarbox import ToolbarBox from sugar.graphics.toolbutton import ToolButton -from sugar.graphics.toggletoolbutton import ToggleToolButton +from sugar.graphics.radiotoolbutton import RadioToolButton from sugar import mime from gettext import gettext as _ +import animation + from frames_list import FramesList -from animation import Animation class AnimateActivity(activity.Activity): @@ -95,12 +96,24 @@ class AnimateActivity(activity.Activity): options_button = ToolbarButton(icon_name='preferences-system') options_toolbar = gtk.Toolbar() - returnbutton = ToggleToolButton("media-playlist-repeat") - returnbutton.set_tooltip(_("Repeat")) - returnbutton.set_active(True) - returnbutton.connect("toggled", self._set_return) + returnbutton = RadioToolButton(icon_name="media-playlist-repeat") + returnbutton.set_tooltip(_("Repeat Mode")) + returnbutton.connect("clicked", self._set_return_mode) options_toolbar.insert(returnbutton, -1) + normalmode = RadioToolButton(icon_name='normal-mode') + normalmode.props.group = returnbutton + normalmode.set_tooltip(_('Normal Mode')) + normalmode.set_active(True) + normalmode.connect("clicked", self._set_normal_mode) + options_toolbar.insert(normalmode, -1) + + pingpong = RadioToolButton(icon_name='ping-pong') + pingpong.props.group = returnbutton + pingpong.set_tooltip(_("Ping Pong Mode")) + pingpong.connect("clicked", self._set_pingpong_mode) + options_toolbar.insert(pingpong, -1) + options_button.props.page = options_toolbar options_toolbar.show_all() @@ -159,8 +172,14 @@ class AnimateActivity(activity.Activity): else: return - def _set_return(self, widget): - self._animation.set_return(widget.get_active()) + def _set_return_mode(self, widget): + self._animation.set_mode(animation.RETURN_MODE) + + def _set_normal_mode(self, widget): + self._animation.set_mode(animation.NORMAL_MODE) + + def _set_pingpong_mode(self, widget): + self._animation.set_mode(animation.PING_PONG_MODE) def _previous_frame(self, widget): self._animation.back() @@ -192,7 +211,7 @@ class AnimateActivity(activity.Activity): width, height = self._get_animation_size() if not self._animation: - self._animation = Animation(width, height) + self._animation = animation.Animation(width, height) self._animation.show_all() self._frames_list._animation = self._animation diff --git a/animation.py b/animation.py index 837aeaa..4dd810a 100644 --- a/animation.py +++ b/animation.py @@ -29,6 +29,10 @@ _logger = logging.getLogger('animate-animation') _logger.setLevel(logging.DEBUG) logging.basicConfig() +NORMAL_MODE = 0 +RETURN_MODE = 1 +PING_PONG_MODE = 2 + class Animation(gtk.Image): __gsignals__ = {"current-frame-updated": (gobject.SIGNAL_RUN_LAST, @@ -40,7 +44,7 @@ class Animation(gtk.Image): self._current_image = 0 self._timeout = None - self._return = True + self._mode = NORMAL_MODE self._running = False self.images = [] @@ -57,10 +61,9 @@ class Animation(gtk.Image): self.set_from_pixbuf(None) self._current_image = 0 - def set_return(self, _return=True): - """Defines if when get to the last image, - should return to the first""" - self._return = _return + def set_mode(self, mode): + """Defines animation mode""" + self._mode = mode def set_size(self, width, height): """Defines animation size""" @@ -128,7 +131,11 @@ class Animation(gtk.Image): 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 \ + not self._mode == NORMAL_MODE: + if self._mode == PING_PONG_MODE: + self.images.reverse() + self._current_image = 0 self.emit("current-frame-updated", self._current_image) @@ -140,7 +147,10 @@ class Animation(gtk.Image): if self._current_image != 0: self._current_image -= 1 - elif self._current_image == 0 and self._return: + elif self._current_image == 0 and not self._mode == NORMAL_MODE: + if self._mode == PING_PONG_MODE: + self._images.reverse() + self._current_image = -1 self.emit("current-frame-updated", self._current_image) diff --git a/icons/normal-mode.svg b/icons/normal-mode.svg new file mode 100644 index 0000000..e8233c8 --- /dev/null +++ b/icons/normal-mode.svg @@ -0,0 +1,88 @@ + +image/svg+xml + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/icons/ping-pong.svg b/icons/ping-pong.svg new file mode 100644 index 0000000..df55366 --- /dev/null +++ b/icons/ping-pong.svg @@ -0,0 +1,63 @@ + + + +image/svg+xml + + + + + + + + + + + + + + + + + \ No newline at end of file -- cgit v0.9.1