Skip to content

Commit

Permalink
Update selected date range when today is changed
Browse files Browse the repository at this point in the history
This will fix projecthamster#633
  • Loading branch information
MarSoft committed Jul 2, 2024
1 parent 81be67e commit 7d1c9d0
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/hamster/overview.py
Original file line number Diff line number Diff line change
Expand Up @@ -573,8 +573,11 @@ def on_search_toggled(self, button):
self.filter_entry.grab_focus()

def on_timeout(self):
# TODO: should update only the running FactTree row (if any), and totals
self.find_facts()
# make sure the date is current
if not self.header_bar.range_pick.update_today(dt.hday.today()):
# TODO: should update only the running FactTree row (if any), and totals
self.find_facts()
# otherwise find_facts was already called by emitted event
# The timeout will stop if returning False
return True

Expand Down
32 changes: 32 additions & 0 deletions src/hamster/widgets/dates.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,38 @@ def next_range(self):
self.emit_range(self.current_range, start, end)


def update_today(self, today):
if today == self.today:
return False # unchanged

if self.current_range == "day":
old_start = old_end = self.today
new_start = new_end = today
elif self.current_range == "week":
old_start, old_end = stuff.week(self.today)
new_start, new_end = stuff.week(today)
elif self.current_range == "month":
old_start, old_end = stuff.month(self.today)
new_start, new_end = stuff.month(today)
else:
# manual range not touched, just bump today
self.today = today
return False # today changed under the hood but range not updated

# now we can already set it
self.today = today

if (old_start, old_end) == (new_start, new_end):
# current range unchanged
return False

if (self.start_date, self.end_date) != (old_start, old_end):
return False # not a current range was selected

self.emit_range(self.current_range, new_start, new_end)
return True



def get_widget(self, name):
""" skip one variable (huh) """
Expand Down

0 comments on commit 7d1c9d0

Please sign in to comment.