Product purchase

This commit is contained in:
Eden Kirin
2023-03-31 13:06:27 +02:00
parent e1e77aba96
commit 28a981980f
7 changed files with 108 additions and 18 deletions

View File

@ -5,7 +5,10 @@ from typing import Callable, Optional
class CountdownTimer(Thread):
def __init__(
self, seconds: int, timer_tick_callback: Optional[Callable[[int], None]] = None, timer_done_callback: Optional[Callable[[], None]] = None
self,
seconds: int,
timer_tick_callback: Optional[Callable[[int], None]] = None,
timer_done_callback: Optional[Callable[[], None]] = None,
) -> None:
self.seconds = seconds
self.stop_event = Event()
@ -18,7 +21,7 @@ class CountdownTimer(Thread):
while time_left and not self.stop_event.is_set():
time.sleep(1)
time_left -= 1
if self.timer_tick_callback:
if self.timer_tick_callback and not self.stop_event.is_set():
self.timer_tick_callback(time_left)
if time_left == 0 and self.timer_done_callback: