From 7d1c9d094cc2cfb6def83b955dcfcdf3b5a15d70 Mon Sep 17 00:00:00 2001 From: Semyon Maryasin Date: Tue, 2 Jul 2024 15:30:04 +0300 Subject: [PATCH 1/2] Update selected date range when today is changed This will fix #633 --- src/hamster/overview.py | 7 +++++-- src/hamster/widgets/dates.py | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/src/hamster/overview.py b/src/hamster/overview.py index 1af1b0b80..8527b6a8e 100644 --- a/src/hamster/overview.py +++ b/src/hamster/overview.py @@ -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 diff --git a/src/hamster/widgets/dates.py b/src/hamster/widgets/dates.py index 6d3f63711..10bdc8779 100644 --- a/src/hamster/widgets/dates.py +++ b/src/hamster/widgets/dates.py @@ -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) """ From ace8013b1cbf11f1761caa8bb16c5fe9ab601ca8 Mon Sep 17 00:00:00 2001 From: Semyon Maryasin Date: Wed, 3 Jul 2024 03:30:18 +0300 Subject: [PATCH 2/2] Properly handle missing current_range --- src/hamster/widgets/dates.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/hamster/widgets/dates.py b/src/hamster/widgets/dates.py index 10bdc8779..bac08add9 100644 --- a/src/hamster/widgets/dates.py +++ b/src/hamster/widgets/dates.py @@ -167,7 +167,7 @@ def update_today(self, today): if today == self.today: return False # unchanged - if self.current_range == "day": + 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": @@ -177,9 +177,12 @@ def update_today(self, today): 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 + 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