From 89b69369c637a4a4d865919988c497ba4c38f904 Mon Sep 17 00:00:00 2001 From: tobi-wan-kenobi Date: Mon, 13 Apr 2020 13:53:54 +0200 Subject: [PATCH] [modules] re-enable todo --- modules/contrib/todo.py | 45 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 modules/contrib/todo.py diff --git a/modules/contrib/todo.py b/modules/contrib/todo.py new file mode 100644 index 0000000..04cd256 --- /dev/null +++ b/modules/contrib/todo.py @@ -0,0 +1,45 @@ +# pylint: disable=C0111,R0903 + +"""Displays the number of todo items from a text file + +Parameters: + * todo.file: File to read TODOs from (defaults to ~/Documents/todo.txt) +""" + +import bumblebee.input +import bumblebee.output +import bumblebee.engine +import os.path + + +class Module(bumblebee.engine.Module): + + + def __init__(self, engine, config): + super(Module, self).__init__(engine, config, + bumblebee.output.Widget(full_text=self.output) + ) + self._doc = os.path.expanduser(self.parameter("file", "~/Documents/todo.txt")) + self._todos = self.count_items() + + + def output(self, widget): + self._todos = self.count_items() + return str(self._todos) + + + def state(self, widgets): + if self._todos == 0: + return "empty" + return "items" + + + def count_items(self): + try: + i = -1 + with open(self._doc) as f: + for i, l in enumerate(f): + pass + return i+1 + except Exception: + return 0