add pulse to timer

This commit is contained in:
Jannes Magnusson
2025-10-17 20:41:13 +02:00
parent 0fced46d61
commit 3aa2be909c

View File

@@ -7,13 +7,15 @@ import math
from .base import View from .base import View
class TimerView(View): class TimerView(View):
def __init__(self, parent, size, center, width=5, **kwargs): def __init__(self, parent, size, center, width=3, **kwargs):
self.start_time = None self.start_time = None
self.elapsed_time = 0 self.elapsed_time = 0
self.is_running = False self.is_running = False
self.goal_minutes = 0 # 0 means no goal set self.goal_minutes = 0 # 0 means no goal set
self.radius = min(center)-width self.radius = min(center) - 7
self.width = width self.width = width
self.goal_achived = 0
self.goal_pulse_freq = 0.1
super().__init__(parent, size, center, **kwargs) super().__init__(parent, size, center, **kwargs)
def init_ui(self, parent): def init_ui(self, parent):
@@ -83,15 +85,22 @@ class TimerView(View):
if progress > 0: if progress > 0:
inverted = int(progress) % 2 == 1 inverted = int(progress) % 2 == 1
progress = progress % 1.0 # Loop every full circle
start = self.center[0] - self.radius, self.center[1] - self.radius # pulse width if goal achieved
end = self.center[0] + self.radius, self.center[1] + self.radius if int(progress) > 0 and self.is_running:
self.goal_achived = (self.goal_achived + self.goal_pulse_freq) % 3
if inverted:
draw.arc((start, end), 360 * progress - 90, 270, fill='black', width=self.width)
else: else:
draw.arc((start, end), 270, 360 * progress - 90, fill='black', width=self.width) self.goal_achived = 0
pulse = int(self.goal_achived)
start = self.center[0] - self.radius - pulse, self.center[1] - self.radius - pulse
end = self.center[0] + self.radius + pulse, self.center[1] + self.radius + pulse
progress = progress % 1.0 # Loop every full circle
if inverted:
draw.arc((start, end), 360 * progress - 90, 270, fill='black', width=self.width + pulse)
else:
draw.arc((start, end), 270, 360 * progress - 90, fill='black', width=self.width + pulse)
except (ValueError, tk.TclError): except (ValueError, tk.TclError):
# Invalid goal value, just show time without progress # Invalid goal value, just show time without progress