Skip to content

Instantly share code, notes, and snippets.

@tito
Created October 5, 2015 21:44
Show Gist options
  • Save tito/e3ed8dce836e8ab668fd to your computer and use it in GitHub Desktop.
Save tito/e3ed8dce836e8ab668fd to your computer and use it in GitHub Desktop.
Image: control direction of animation (normal or reverse). Great to have open/close animation
from functools import partial
def coreimage_animation(self, *largs):
# accept reverse direction
if not self._image:
return
textures = self.image.textures
self._texture = self.image.textures[self._anim_index]
self.dispatch('on_texture')
self._anim_index += self._anim_direction
if self._anim_index == len(self._image.textures) - 1:
self.anim_reset(False)
elif self._anim_index == 0:
self.anim_reset(False)
self._anim_index %= len(self._image.textures)
def patch_image(uix_image):
coreimage = uix_image._coreimage
coreimage._anim_direction = 1
coreimage.anim_reset(False)
coreimage._anim_old = coreimage._anim
coreimage._anim = partial(coreimage_animation, coreimage)
return uix_image
# Usage
_anim_help_fr = patch_image(Image(source="data/images/L3-aide-FR.zip", anim_delay=(1 / 30.)))
def show_help_br(self):
self._anim_help_fr._coreimage._anim_direction = 1
self._anim_help_fr._coreimage.anim_reset(True)
def hide_help_br(self):
self._anim_help_fr._coreimage._anim_direction = -1
self._anim_help_fr._coreimage.anim_reset(True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment