fixes and update on animated icon contexmanager gitea and menu_bar
This commit is contained in:
@@ -55,6 +55,7 @@ class AnimatedIcon(tk.Canvas):
|
||||
self.highlight_color = highlight_color
|
||||
self.use_pillow = use_pillow and PIL_AVAILABLE
|
||||
self.running = False
|
||||
self.pause_count = 0
|
||||
self.angle = 0
|
||||
self.pulse_animation = False
|
||||
|
||||
@@ -453,7 +454,7 @@ class AnimatedIcon(tk.Canvas):
|
||||
|
||||
def _animate(self) -> None:
|
||||
"""The main animation loop."""
|
||||
if not self.winfo_exists() or not self.running:
|
||||
if self.pause_count > 0 or not self.running or not self.winfo_exists():
|
||||
return
|
||||
|
||||
# Do not animate if a grab is active on a different window.
|
||||
@@ -478,9 +479,9 @@ class AnimatedIcon(tk.Canvas):
|
||||
"""
|
||||
if not self.winfo_exists():
|
||||
return
|
||||
if not self.running:
|
||||
self.pulse_animation = pulse
|
||||
self.running = True
|
||||
self.running = True
|
||||
self.pulse_animation = pulse
|
||||
if self.pause_count == 0:
|
||||
self._animate()
|
||||
|
||||
def stop(self, status: Optional[str] = None) -> None:
|
||||
@@ -511,9 +512,20 @@ class AnimatedIcon(tk.Canvas):
|
||||
self.pulse_animation = False
|
||||
self.delete("all")
|
||||
|
||||
def pause(self) -> None:
|
||||
"""Pauses the animation and draws a static frame."""
|
||||
self.pause_count += 1
|
||||
self._draw_stopped_frame()
|
||||
|
||||
def resume(self) -> None:
|
||||
"""Resumes the animation if the pause count is zero."""
|
||||
self.pause_count = max(0, self.pause_count - 1)
|
||||
if self.pause_count == 0 and self.running:
|
||||
self._animate()
|
||||
|
||||
def show_full_circle(self) -> None:
|
||||
"""Shows the static 'stopped' frame without starting the animation."""
|
||||
if not self.winfo_exists():
|
||||
return
|
||||
if not self.running:
|
||||
self._draw_stopped_frame()
|
||||
self._draw_stopped_frame()
|
@@ -837,16 +837,16 @@ class Translate:
|
||||
@contextmanager
|
||||
def message_box_animation(animated_icon):
|
||||
"""
|
||||
A context manager to handle starting and stopping an animated icon
|
||||
A context manager to handle pausing and resuming an animated icon
|
||||
around an operation like showing a message box.
|
||||
|
||||
Args:
|
||||
animated_icon: The animated icon object with start() and stop() methods.
|
||||
animated_icon: The animated icon object with pause() and resume() methods.
|
||||
"""
|
||||
if animated_icon:
|
||||
animated_icon.stop()
|
||||
animated_icon.pause()
|
||||
try:
|
||||
yield
|
||||
finally:
|
||||
if animated_icon:
|
||||
animated_icon.start()
|
||||
animated_icon.resume()
|
||||
|
Reference in New Issue
Block a user