diff --git a/timebox.py b/timebox.py index 3a8f21d..9dc5d04 100644 --- a/timebox.py +++ b/timebox.py @@ -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 @@ -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" @@ -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" @@ -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}") @@ -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")):