community icon indicating copy to clipboard operation
community copied to clipboard

[BUG, solution proposed] kivy.core.image.Image.anim_reset(True) does not reset

Open Zeratoxx opened this issue 1 year ago • 4 comments

Software Versions

  • Python: 3.12
  • OS: Windows 10 22H2
  • Kivy: 2.3.0
  • Kivy installation method: pip

Introduction
In the code below, I have a custom Image Widget with a GIF as source. The custom Image Widget is reacting when the cursor is hovering over the image. When starting the app, both GIFs are being animated as expected.

Describe the bug
When the cursor is leaving the area of interest, the GIF just stops WIHTOUT resetting to frame 0.

Expected behavior
When the cursor is leaving the area of interest, the GIF should stop AND reset to frame 0.

To Reproduce
A short, runnable example that reproduces the issue follows. I tested it with Kivy 2.3.0 but it will also happen with latest kivy master as the according code is the same.

Code and Logs and screenshots
test.py:

from kivy.app import App
from kivy.uix.image import Image
from kivy.core.window import Window


class ReactiveImage(Image):
    def __init__(self, **kwargs):
        super(ReactiveImage, self).__init__(**kwargs)
        Window.bind(mouse_pos=self.on_mouse_pos_on_button)
        self._active = False

    def on_mouse_pos_on_button(self, *largs):
        pos = self.to_widget(*largs[1])
        if self.collide_point(*pos):
            self._reaction_ref()
            return
        if self._active:
            self._clear_instructions()

    def _reaction_ref(self):
        if self._active:
            return
        self._coreimage.anim_reset(True)
        self._active = True

    def _clear_instructions(self):
        if not self._active:
            return
        self._coreimage.anim_reset(True)
        self._coreimage.anim_reset(False)
        self._active = False


class TestApp(App):
    pass


TestApp().run()

test.kv:

BoxLayout:
    orientation: 'vertical'

    ReactiveImage:
        canvas.before:
            Color:
                rgba: rgba(63, 63, 63)
            Rectangle:
                pos: self.x, self.y
                size: self.width, self.height

        id: edit_gif
        source: 'some1.gif'
        center: self.parent.center
        size_hint_x: .9
        size_hint_y: .9
        allow_stretch: False
        opacity: 1
        anim_delay: 1/24

    ReactiveImage:
        canvas.before:
            Color:
                rgba: rgba(63, 63, 63)
            Rectangle:
                pos: self.x, self.y
                size: self.width, self.height
        id: progress_gif
        source: 'some2.gif'
        center: self.parent.center
        size_hint_x: .9
        size_hint_y: .9
        allow_stretch: False
        opacity: 1
        anim_delay: 1/60

Additional context
In file kivy/core/image/init.py between line 621 and 622, there is missing following code:

            self._anim_index = 0

This fixes the issue.

Zeratoxx avatar Aug 13 '24 20:08 Zeratoxx

Hello @Zeratoxx I am looking for issues to contribute and came across this. Is it still relevant and up for grabs?

kitsiosvas avatar Sep 21 '24 21:09 kitsiosvas

Hello @Zeratoxx I am looking for issues to contribute and came across this. Is it still relevant and up for grabs?

Hi @kitsiosvas, idk if it is still relevant, I didn't work on the project since then, I had too many important things to do. But I can look into it again tomorrow.

If it is still relevant, it is definitely "up for grabs" :)

Zeratoxx avatar Sep 21 '24 22:09 Zeratoxx

@Zeratoxx That would be great. I could check if this issue still happens with the example you provided above as well. Eitherway I would be grateful for hearing from you tomorrow

kitsiosvas avatar Sep 21 '24 22:09 kitsiosvas

Oops, sorry @kitsiosvas, completely forgot that I wanted to check 😅 as I said, too many important things to do currently

Zeratoxx avatar Sep 24 '24 08:09 Zeratoxx