Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatically update today view on date change #763

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
35 changes: 35 additions & 0 deletions src/hamster/widgets/dates.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,41 @@ 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" or self.start_date == self.end_date:
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:
old_start, old_end = self.start_date, self.end_date
if self.today < old_start or self.today > old_end:
self.today = today
return False
new_start = old_start + (today - self.today)
new_end = old_end + (today - self.today)

# 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
Loading