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