Skip to content

Commit

Permalink
python: update pomodoro timer experiment
Browse files Browse the repository at this point in the history
  • Loading branch information
vpayno committed May 14, 2024
1 parent 384e35e commit 333c5d8
Showing 1 changed file with 28 additions and 7 deletions.
35 changes: 28 additions & 7 deletions python/src/pomodoro-timer.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ def __init__(self, work_duration: int = 45, break_duration: int = 15) -> None:
:param break_duration: the length, in minutes, of the break timer
"""

self.seconds_in_minute: int = 60
self.time_left: int = 0
self.work_duration: int = work_duration
self.break_duration: int = break_duration
Expand All @@ -25,10 +26,15 @@ def _five_minute_warning(self, fives_left: int) -> None:
:param fives_left: the number of 5 minute chunks left in the running timer.
"""

if fives_left == 1 and not self.warned and (self.work_duration > 5 or self.break_duration > 5):
music.play(music.BADDY)
if self.time_left == 1 and (self.work_duration == 5 or self.break_duration == 5):
print("INFO: 1 minute warning at " + str(self.time_left) + " minutes")
play_music_warning("BADDY")
elif fives_left == 1 and not self.warned and (self.work_duration > 5 or self.break_duration > 5):
print("INFO: 5 minute warning at " + str(self.time_left) + " minutes")
play_music_warning("BADDY")

if self.time_left <= 5:
if self.time_left == 5:
print("INFO: disabling timer warnings")
self.warned = not self.warned

def _run_timer(self, name: str, duration: int) -> bool:
Expand All @@ -39,7 +45,9 @@ def _run_timer(self, name: str, duration: int) -> bool:
:return: true, completed | false, canceled
"""

print("INFO: starting " + name + " timer for " + str(self.work_duration) + " minutes")
print("INFO: starting " + name + " timer for " + str(duration) + " minutes")

display.scroll(str(duration))

self.time_left = duration

Expand All @@ -59,7 +67,7 @@ def _run_timer(self, name: str, duration: int) -> bool:
self.time_left -= 1

heartbeat: bool = True
count: int = 60
count: int = self.seconds_in_minute

# counts seconds in a minute
while count > 0:
Expand Down Expand Up @@ -104,13 +112,16 @@ def start_timer(self) -> None:

if status:
print("INFO: work timer completed")
display.show(Image.SMILE)
audio.play(Sound.HAPPY)
display.show(Image.HAPPY)
play_sound_warning("HAPPY")
sleep(1000)

self.warned = False

if self._run_timer("break", self.break_duration):
print("INFO: break timer completed")
display.show(Image.FABULOUS)
play_sound_warning("HAPPY")
sleep(1000)
else:
print("INFO: break timer canceled")
Expand All @@ -122,6 +133,16 @@ def start_timer(self) -> None:
# Helper functions


def play_sound_warning(sound: str) -> None:
print("INFO: playing Sound." + sound)
audio.play(getattr(Sound, sound))


def play_music_warning(song: str) -> None:
print("INFO: playing music." + song)
music.play(getattr(music, song))


def reset_button_states() -> None:
"""We need to read buttons again after reading them to make sure
that users can't stack button presses."""
Expand Down

0 comments on commit 333c5d8

Please sign in to comment.