Skip to content

Commit

Permalink
feat: start timer when click on task
Browse files Browse the repository at this point in the history
  • Loading branch information
mk1123 committed Apr 6, 2021
1 parent 2e42593 commit 286f14f
Showing 1 changed file with 29 additions and 4 deletions.
33 changes: 29 additions & 4 deletions timebox.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,11 @@ def __init__(self, timer_interval=1):
self.buttons_callback = {}
for i in [5, 10, 15, 20, 25]:
title = str(i) + " Minutes"
callback = lambda _, j=i: self.set_mins(_, j)
def callback(_, j=i):
self.set_mins(_, j)
self.timer.count = 0
self.timer.end = j
self.timer.start()
self.buttons["btn_" + str(i)] = rumps.MenuItem(
title=title, callback=callback
)
Expand All @@ -109,11 +113,22 @@ def __init__(self, timer_interval=1):
self.sum_of_tasks_scheduled = sum(self.things_processed_tasks.values())

self.sum_menu_item = rumps.MenuItem(title="hours_spent", callback=None)

def callback(time):
def inner_callback(_, j=time):
self.set_mins(_, j)
for btn in [*self.things_buttons.values(), *self.buttons.values()]:
btn.set_callback(None)
self.timer.count = 0
self.timer.end = self.interval
self.start_pause_button.title = "Pause Timer"
self.timer.start()
return inner_callback

self.things_buttons = {
f"{title}": rumps.MenuItem(
title=f"({time} min) {title}",
callback=lambda _, j=time: self.set_mins(_, j),
callback=callback(time)
)
for title, time in self.things_processed_tasks.items()
}
Expand Down Expand Up @@ -147,11 +162,21 @@ def sync_data(self):
for title in prev_things_buttons.keys():
del self.app.menu[prev_things_buttons[title].title]

def callback(time):
def inner_callback(_, j=time):
self.set_mins(_, j)
for btn in [*self.things_buttons.values(), *self.buttons.values()]:
btn.set_callback(None)
self.timer.count = 0
self.timer.end = self.interval
self.start_pause_button.title = "Pause Timer"
self.timer.start()
return inner_callback

self.things_buttons = {
f"({time} min) {title}": rumps.MenuItem(
title=f"({time} min) {title}",
callback=lambda _, j=time: self.set_mins(_, j),
)
callback=callback(time))
for title, time in self.things_processed_tasks.items()
}

Expand Down

0 comments on commit 286f14f

Please sign in to comment.