2020-04-19 14:23:41 +02:00
|
|
|
# pylint: disable=C0111,R0903
|
|
|
|
|
|
|
|
"""Displays the status of watson (time-tracking tool)
|
|
|
|
|
|
|
|
Requires the following executable:
|
|
|
|
* watson
|
|
|
|
"""
|
|
|
|
|
|
|
|
import bumblebee.input
|
|
|
|
import bumblebee.output
|
|
|
|
import bumblebee.engine
|
|
|
|
import bumblebee.util
|
|
|
|
import bumblebee.popup_v2
|
|
|
|
|
|
|
|
import logging
|
|
|
|
import re
|
|
|
|
import functools
|
|
|
|
|
|
|
|
class Module(bumblebee.engine.Module):
|
|
|
|
def __init__(self, engine, config):
|
|
|
|
super(Module, self).__init__(engine, config,
|
|
|
|
bumblebee.output.Widget(full_text=self.text))
|
|
|
|
self._tracking = False
|
2020-04-19 14:24:00 +02:00
|
|
|
self._project = ''
|
2020-04-19 14:23:41 +02:00
|
|
|
engine.input.register_callback(self, button=bumblebee.input.LEFT_MOUSE,
|
|
|
|
cmd=self.toggle)
|
|
|
|
|
|
|
|
def toggle(self, widget):
|
2020-04-19 14:24:00 +02:00
|
|
|
self._project = 'hit'
|
2020-04-19 14:23:41 +02:00
|
|
|
if self._tracking:
|
2020-04-19 14:24:00 +02:00
|
|
|
bumblebee.util.execute('watson stop')
|
2020-04-19 14:23:41 +02:00
|
|
|
else:
|
2020-04-19 14:24:00 +02:00
|
|
|
bumblebee.util.execute('watson restart')
|
2020-04-19 14:23:41 +02:00
|
|
|
self._tracking = not self._tracking
|
|
|
|
|
|
|
|
def text(self, widget):
|
|
|
|
if self._tracking:
|
|
|
|
return self._project
|
|
|
|
else:
|
2020-04-19 14:24:00 +02:00
|
|
|
return 'Paused'
|
2020-04-19 14:23:41 +02:00
|
|
|
|
|
|
|
def update(self, widgets):
|
2020-04-19 14:24:00 +02:00
|
|
|
output = bumblebee.util.execute('watson status')
|
2020-04-19 14:23:41 +02:00
|
|
|
if re.match('No project started', output):
|
|
|
|
self._tracking = False
|
|
|
|
return
|
|
|
|
|
|
|
|
self._tracking = True
|
|
|
|
m = re.search(r'Project (.+) started', output)
|
|
|
|
self._project = m.group(1)
|
|
|
|
|
|
|
|
#
|
|
|
|
def state(self, widget):
|
2020-04-19 14:24:00 +02:00
|
|
|
return 'on' if self._tracking else 'off'
|
|
|
|
# return [widget.get('status', None), widget.get('period', None)]
|
2020-04-19 14:23:41 +02:00
|
|
|
|
|
|
|
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|