From 250c0135e6565e755feb514574cd933193a287c0 Mon Sep 17 00:00:00 2001 From: Michael Skelton Date: Fri, 16 Jun 2017 16:51:27 +1000 Subject: [PATCH 1/5] added bumblebee module --- bumblebee/modules/todo.py | 43 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 bumblebee/modules/todo.py diff --git a/bumblebee/modules/todo.py b/bumblebee/modules/todo.py new file mode 100644 index 0000000..e51ff8f --- /dev/null +++ b/bumblebee/modules/todo.py @@ -0,0 +1,43 @@ +# pylint: disable=C0111,R0903 + +"""Displays the number of todo items in ~/Documents/todo.txt""" + +import platform + +import bumblebee.input +import bumblebee.output +import bumblebee.engine + + +class Module(bumblebee.engine.Module): + + + def __init__(self, engine, config): + super(Module, self).__init__(engine, config, + bumblebee.output.Widget(full_text=self.output) + ) + self._todos = self.count_items() + + + def output(self, widget): + self._todos = self.count_items() + return self._todos + + + def state(self, widgets): + if self._todos == 0 : + return "empty" + return "items" + + + def count_items(filename): + try: + i=-1 + with open('/home/codingo/Documents/todo.txt') as f: + for i, l in enumerate(f): + pass + return i+1 + except Exception: + return 0 + +# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4 From 66ecf73760021cc7c528684f7b63fc3d8754856f Mon Sep 17 00:00:00 2001 From: Michael Skelton Date: Fri, 16 Jun 2017 16:52:01 +1000 Subject: [PATCH 2/5] Updated todo module to agnostic user path --- bumblebee/modules/todo.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bumblebee/modules/todo.py b/bumblebee/modules/todo.py index e51ff8f..12166c3 100644 --- a/bumblebee/modules/todo.py +++ b/bumblebee/modules/todo.py @@ -33,7 +33,7 @@ class Module(bumblebee.engine.Module): def count_items(filename): try: i=-1 - with open('/home/codingo/Documents/todo.txt') as f: + with open('~/Documents/todo.txt') as f: for i, l in enumerate(f): pass return i+1 From c27236cd82d0bd09886b853fc4a3c401d7e6db58 Mon Sep 17 00:00:00 2001 From: Michael Skelton Date: Fri, 16 Jun 2017 16:54:52 +1000 Subject: [PATCH 3/5] Updated icon for todo module --- themes/icons/awesome-fonts.json | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/themes/icons/awesome-fonts.json b/themes/icons/awesome-fonts.json index bf95f55..596c569 100644 --- a/themes/icons/awesome-fonts.json +++ b/themes/icons/awesome-fonts.json @@ -14,6 +14,10 @@ "brightness": { "prefix": "" }, "load": { "prefix": "" }, "layout": { "prefix": "" }, ++ "todo": { "empty": {"prefix": "" }, + + "items": {"prefix": "" } + }, + "cmus": { "playing": { "prefix": "" }, "paused": { "prefix": "" }, From 4337c2b08754d2d36c37d240af9bc69cfcd06eb9 Mon Sep 17 00:00:00 2001 From: Tobias Witek Date: Fri, 16 Jun 2017 11:22:08 +0200 Subject: [PATCH 4/5] [modules/todo] Make unit test pass Return value of full_text must be a string. --- bumblebee/modules/todo.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bumblebee/modules/todo.py b/bumblebee/modules/todo.py index 12166c3..8bab920 100644 --- a/bumblebee/modules/todo.py +++ b/bumblebee/modules/todo.py @@ -21,7 +21,7 @@ class Module(bumblebee.engine.Module): def output(self, widget): self._todos = self.count_items() - return self._todos + return str(self._todos) def state(self, widgets): From 6183054ac61ca69e71a8ee5821f97e163d29a3fb Mon Sep 17 00:00:00 2001 From: Tobias Witek Date: Fri, 16 Jun 2017 11:24:55 +0200 Subject: [PATCH 5/5] [modules/todo] Make path to TODO file configurable --- bumblebee/modules/todo.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/bumblebee/modules/todo.py b/bumblebee/modules/todo.py index 8bab920..d96388f 100644 --- a/bumblebee/modules/todo.py +++ b/bumblebee/modules/todo.py @@ -1,6 +1,10 @@ # pylint: disable=C0111,R0903 -"""Displays the number of todo items in ~/Documents/todo.txt""" +"""Displays the number of todo items from a text file + +Parameters: + * todo.file: File to read TODOs from (defaults to ~/Documents/todo.txt) +""" import platform @@ -32,8 +36,9 @@ class Module(bumblebee.engine.Module): def count_items(filename): try: - i=-1 - with open('~/Documents/todo.txt') as f: + i = -1 + doc = self.parameter("file", "~/Documents/todo.txt") + with open(doc) as f: for i, l in enumerate(f): pass return i+1