Player state

This commit is contained in:
Eden Kirin
2023-03-30 13:09:23 +02:00
parent 8a48d61dc9
commit ecffdc5d1e
11 changed files with 84 additions and 25 deletions

25
hopper/countdown_timer.py Normal file
View File

@ -0,0 +1,25 @@
import time
from threading import Event, Thread
from typing import Callable, Optional
class CountdownTimer(Thread):
def __init__(
self, seconds: int, callback: Optional[Callable[[], None]] = None
) -> None:
self.seconds = seconds
self.stop_event = Event()
self.callback = callback
super().__init__()
def run(self) -> None:
cnt = self.seconds
while cnt > 0 and not self.stop_event.is_set():
cnt -= 1
time.sleep(1)
if cnt == 0 and self.callback:
self.callback()
def stop(self) -> None:
self.stop_event.set()