2017-06-16 08:51:27 +02:00
|
|
|
# pylint: disable=C0111,R0903
|
|
|
|
|
2017-06-16 11:24:55 +02:00
|
|
|
"""Displays the number of todo items from a text file
|
|
|
|
|
|
|
|
Parameters:
|
|
|
|
* todo.file: File to read TODOs from (defaults to ~/Documents/todo.txt)
|
|
|
|
"""
|
2017-06-16 08:51:27 +02:00
|
|
|
|
|
|
|
import bumblebee.input
|
|
|
|
import bumblebee.output
|
|
|
|
import bumblebee.engine
|
|
|
|
|
|
|
|
|
|
|
|
class Module(bumblebee.engine.Module):
|
|
|
|
|
2017-10-13 17:09:09 +02:00
|
|
|
|
2017-06-16 08:51:27 +02:00
|
|
|
def __init__(self, engine, config):
|
|
|
|
super(Module, self).__init__(engine, config,
|
|
|
|
bumblebee.output.Widget(full_text=self.output)
|
|
|
|
)
|
2017-10-13 17:09:09 +02:00
|
|
|
self._todos = self.count_items()
|
2017-06-16 08:51:27 +02:00
|
|
|
|
|
|
|
|
|
|
|
def output(self, widget):
|
|
|
|
self._todos = self.count_items()
|
2017-06-16 11:22:08 +02:00
|
|
|
return str(self._todos)
|
2017-06-16 08:51:27 +02:00
|
|
|
|
2017-10-13 17:09:09 +02:00
|
|
|
|
2017-06-16 08:51:27 +02:00
|
|
|
def state(self, widgets):
|
2017-10-13 17:06:18 +02:00
|
|
|
if self._todos == 0:
|
2017-06-16 08:51:27 +02:00
|
|
|
return "empty"
|
|
|
|
return "items"
|
2017-10-13 17:09:09 +02:00
|
|
|
|
2017-06-16 08:51:27 +02:00
|
|
|
|
|
|
|
def count_items(filename):
|
|
|
|
try:
|
2017-06-16 11:24:55 +02:00
|
|
|
i = -1
|
|
|
|
doc = self.parameter("file", "~/Documents/todo.txt")
|
|
|
|
with open(doc) as f:
|
2017-06-16 08:51:27 +02:00
|
|
|
for i, l in enumerate(f):
|
|
|
|
pass
|
2017-10-13 17:09:09 +02:00
|
|
|
return i+1
|
2017-06-16 08:51:27 +02:00
|
|
|
except Exception:
|
|
|
|
return 0
|
|
|
|
|
|
|
|
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|