My collection of plugins for the Qtile window manager.
git clone https://mcol.xyz/code/qtools
Log | Files | Refs | README

commit 9c4c4d72c82d704fee6b3aa0dcd176f5471dd280
parent 63243929c7468d0bf5bd8d0850920dead38e65ad
Author: mcol <mcol@posteo.net>
Date:   Fri,  4 Sep 2020 22:43:49 +0100

habit tracker: old change i cant remember what it fixed

Diffstat:
Mqtools/widget/habit_tracker.py | 21++++++++++++---------
1 file changed, 12 insertions(+), 9 deletions(-)

diff --git a/qtools/widget/habit_tracker.py b/qtools/widget/habit_tracker.py @@ -64,9 +64,11 @@ class HabitTracker(base._Widget): def __init__(self, **config): base._Widget.__init__(self, bar.CALCULATED, **config) self.add_defaults(HabitTracker.defaults) - self._chain = self._load_chain() + self._chain = None self._block_size = 0 + self._load_chain() + if not hasattr(self, "draw_{0}".format(self.style)): logger.warning("HabitTracker style '{0}' invalid.".format(self.style)) self.style = "chain" @@ -79,14 +81,15 @@ class HabitTracker(base._Widget): self.mouse_callbacks.update({'Button3': self.cmd_decrement}) def _load_chain(self): - if not os.path.isfile(self.chain_file): - return 0 - with open(self.chain_file, 'r') as fd: - cache = json.load(fd) - if self.habit not in cache.keys(): - return 0 - start_date = datetime.strptime(cache.get(self.habit), "%Y-%m-%d") - return (datetime.now() - start_date).days + if os.path.isfile(self.chain_file): + with open(self.chain_file, 'r') as fd: + cache = json.load(fd) + if self.habit in cache.keys(): + start_date = datetime.strptime(cache.get(self.habit), "%Y-%m-%d") + self._chain = (datetime.now() - start_date).days + return + self._chain = 0 + self._save_chain() def _save_chain(self): cache = {}