added countdown
This commit is contained in:
parent
30655c26fc
commit
1823feb53d
|
@ -17,6 +17,7 @@ class stopwatch:
|
|||
enable_sound: bool = False
|
||||
|
||||
def __init__(self, beep_at, enable_sound) -> None:
|
||||
print('='*120)
|
||||
self.start_time = datetime.datetime.now().replace(microsecond=0)
|
||||
if enable_sound:
|
||||
print("Warning:\tonce the beep time is reached, a sound will play.")
|
||||
|
@ -27,25 +28,30 @@ class stopwatch:
|
|||
print("Start time:\t%s\nWill beep at:\t%s\nBeeping Time:\t%sm" % (self.start_time, self.beep_at_time, beep_at))
|
||||
else:
|
||||
self.beep_at = 0
|
||||
self.beep_at_time = datetime.datetime.now()
|
||||
print("Start time:\t%s" % self.start_time)
|
||||
print('='*120)
|
||||
|
||||
|
||||
def display(self) -> None:
|
||||
text2 = ""
|
||||
text3 = ""
|
||||
while True:
|
||||
now = datetime.datetime.now().replace(microsecond=0)
|
||||
elapsed = (now - self.start_time)
|
||||
text0 = ("\rcurrent:\t%s" % now)
|
||||
text1 = ("elapsed:\t%s" % elapsed)
|
||||
text1 = ("elapsed: %s" % elapsed)
|
||||
if self.beep_at > 0 and not self.has_beeped:
|
||||
remaining = self.beep_at_time - now
|
||||
text2 = ("remaining: %s" % remaining)
|
||||
if elapsed.seconds / 60 >= self.beep_at and not self.has_beeped and not self.beep_at == 0:
|
||||
text0 += '\a'
|
||||
text2 = "🔔Beep!🔔"
|
||||
text3 = "🔔Beep!🔔"
|
||||
self.has_beeped = True
|
||||
if self.enable_sound:
|
||||
p = Process(target=beepy.beep, kwargs={"sound": "success"})
|
||||
p.start()
|
||||
sys.stdout.write('\r' + str(text0+"\t\t"+text1+"\t\t"+text2) + "\t" * 3)
|
||||
sys.stdout.write('\r' + text0+"\t\t"+text1+"\t\t"+text2+"\t\t"+text3 + "\t")
|
||||
sys.stdout.flush()
|
||||
time.sleep(0.1)
|
||||
|
||||
|
|
Loading…
Reference in New Issue