Skip to content

Commit

Permalink
Add time increments while in timer
Browse files Browse the repository at this point in the history
  • Loading branch information
mk1123 committed Jul 28, 2022
1 parent 592ee2d commit 80b12e0
Showing 1 changed file with 29 additions and 6 deletions.
35 changes: 29 additions & 6 deletions timebox.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ def hour_formatter(minutes):

# %%
class TimerApp(object):

def add_time_callback(self, time):
def inner_callback_2(_, j=time):
self.timer.end += j * SEC_TO_MIN
return inner_callback_2
def __init__(self, timer_interval=1):
self.timer = rumps.Timer(self.on_tick, 1)
self.timer.stop() # timer running when initialized
Expand All @@ -91,11 +96,13 @@ def __init__(self, timer_interval=1):
self.buttons = {}
self.buttons_callback = {}
for i in [5, 10, 15, 20, 25]:
title = str(i) + " Minutes"
title = "Add " + str(i) + " Minutes"
def callback(_, j=i):
self.set_mins(_, j)
for btn in [*self.things_buttons.values(), *self.buttons.values()]:
for btn in self.things_buttons.values():
btn.set_callback(None)
for btn in self.buttons.values():
btn.set_callback(self.add_time_callback(j))
self.timer.count = 0
self.timer.end = self.interval
self.start_pause_button.title = "Pause Timer"
Expand Down Expand Up @@ -139,12 +146,13 @@ def callback(_, j=i):
None,
self.stop_button,
]

def callback(self, time):
def inner_callback(_, j=time):
self.set_mins(_, j)
for btn in [*self.things_buttons.values(), *self.buttons.values()]:
for btn in self.things_buttons.values():
btn.set_callback(None)
for i, btn in enumerate(self.buttons.values()):
btn.set_callback(self.add_time_callback([5, 10, 15, 20, 25][i]))
self.timer.count = 0
self.timer.end = self.interval
self.start_pause_button.title = "Pause Timer"
Expand Down Expand Up @@ -184,7 +192,7 @@ def run(self):
self.app.run()

def set_mins(self, sender, interval):
for btn in [*self.things_buttons.values(), *self.buttons.values()]:
for btn in self.things_buttons.values():
if sender.title == btn.title:
self.interval = interval * SEC_TO_MIN
print(f"here: {self.interval}")
Expand All @@ -197,10 +205,25 @@ def set_mins(self, sender, interval):
btn.state = True
elif sender.title != btn.title:
btn.state = False
for btn in self.buttons.values():
if sender.title == btn.title:
self.interval = interval * SEC_TO_MIN
print(f"here: {self.interval}")
cleaned_title = " ".join(sender.title.split()[3:])
self.menu_title = (
" ".join(cleaned_title.split()[:4])
if len(cleaned_title.split()) > 4
else cleaned_title
)
btn.state = True
elif sender.title != btn.title:
btn.state = False

def start_timer(self, sender, interval):
for btn in [*self.things_buttons.values(), *self.buttons.values()]:
for btn in self.things_buttons.values():
btn.set_callback(None)
for i, btn in enumerate(self.buttons.values()):
btn.set_callback(self.add_time_callback([5, 10, 15, 20, 25][i]))

if sender.title.lower().startswith(("start", "continue")):

Expand Down

0 comments on commit 80b12e0

Please sign in to comment.