[modules/todo] Update to latest API
This commit is contained in:
parent
89b69369c6
commit
05a3c5d8f6
1 changed files with 16 additions and 18 deletions
|
@ -6,40 +6,38 @@ Parameters:
|
||||||
* todo.file: File to read TODOs from (defaults to ~/Documents/todo.txt)
|
* todo.file: File to read TODOs from (defaults to ~/Documents/todo.txt)
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import bumblebee.input
|
|
||||||
import bumblebee.output
|
|
||||||
import bumblebee.engine
|
|
||||||
import os.path
|
import os.path
|
||||||
|
|
||||||
|
import core.module
|
||||||
|
import core.widget
|
||||||
|
|
||||||
class Module(bumblebee.engine.Module):
|
class Module(core.module.Module):
|
||||||
|
def __init__(self, config):
|
||||||
|
super().__init__(config, core.widget.Widget(self.output))
|
||||||
|
|
||||||
|
self.__doc = os.path.expanduser(self.parameter('file', '~/Documents/todo.txt'))
|
||||||
def __init__(self, engine, config):
|
self.__todos = self.count_items()
|
||||||
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):
|
def output(self, widget):
|
||||||
self._todos = self.count_items()
|
return str(self.__todos)
|
||||||
return str(self._todos)
|
|
||||||
|
|
||||||
|
def update(self):
|
||||||
|
self.__todos = self.count_items()
|
||||||
|
|
||||||
def state(self, widgets):
|
def state(self, widgets):
|
||||||
if self._todos == 0:
|
if self.__todos == 0:
|
||||||
return "empty"
|
return 'empty'
|
||||||
return "items"
|
return 'items'
|
||||||
|
|
||||||
|
|
||||||
def count_items(self):
|
def count_items(self):
|
||||||
try:
|
try:
|
||||||
i = -1
|
i = -1
|
||||||
with open(self._doc) as f:
|
with open(self.__doc) as f:
|
||||||
for i, l in enumerate(f):
|
for i, l in enumerate(f):
|
||||||
pass
|
pass
|
||||||
return i+1
|
return i+1
|
||||||
except Exception:
|
except Exception:
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|
||||||
|
|
Loading…
Reference in a new issue