2020-04-13 14:19:36 +02:00
|
|
|
"""Displays the number of pending tasks in TaskWarrior.
|
|
|
|
|
|
|
|
Requires the following library:
|
|
|
|
* taskw
|
|
|
|
|
|
|
|
Parameters:
|
|
|
|
* taskwarrior.taskrc : path to the taskrc file (defaults to ~/.taskrc)
|
|
|
|
"""
|
|
|
|
|
|
|
|
import bumblebee.input
|
|
|
|
import bumblebee.output
|
|
|
|
import bumblebee.engine
|
|
|
|
|
|
|
|
try:
|
|
|
|
from taskw import TaskWarrior
|
|
|
|
except:
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
class Module(bumblebee.engine.Module):
|
|
|
|
"""TaskWarrior module."""
|
|
|
|
|
|
|
|
def __init__(self, engine, config):
|
|
|
|
"""Initialize taskwarrior module."""
|
|
|
|
super(Module, self).__init__(engine, config,
|
|
|
|
bumblebee.output.Widget(
|
|
|
|
full_text=self.output))
|
2020-04-13 14:20:03 +02:00
|
|
|
self._pending_tasks_count = '0'
|
2020-04-13 14:19:36 +02:00
|
|
|
|
|
|
|
def update(self, widgets):
|
|
|
|
"""Return a string with the number of pending tasks from TaskWarrior."""
|
|
|
|
try:
|
2020-04-13 14:20:03 +02:00
|
|
|
taskrc = self.parameter('taskrc', '~/.taskrc')
|
2020-04-13 14:19:36 +02:00
|
|
|
w = TaskWarrior(config_filename=taskrc)
|
|
|
|
pending_tasks = w.filter_tasks({'status': 'pending'})
|
|
|
|
self._pending_tasks_count = str(len(pending_tasks))
|
|
|
|
except:
|
|
|
|
self._pending_tasks_count = 'Error'
|
|
|
|
|
|
|
|
def output(self, _):
|
|
|
|
"""Format the task counter to output in bumblebee."""
|
2020-04-13 14:20:03 +02:00
|
|
|
return '{}'.format(self._pending_tasks_count)
|
|
|
|
|
|
|
|
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|