bumblebee-status/bumblebee_status/modules/contrib/watson.py

61 lines
1.5 KiB
Python
Raw Normal View History

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
contributed by `bendardenne <https://github.com/bendardenne>`_ - many thanks!
2020-04-19 14:23:41 +02:00
"""
import logging
import re
import functools
2020-04-19 14:27:11 +02:00
import core.module
import core.widget
import core.input
import core.decorators
import util.cli
2020-04-19 14:27:11 +02:00
class Module(core.module.Module):
@core.decorators.every(minutes=60)
def __init__(self, config, theme):
super().__init__(config, theme, core.widget.Widget(self.text))
2020-04-19 14:27:11 +02:00
self.__tracking = False
self.__project = ""
2020-04-19 14:27:11 +02:00
core.input.register(self, button=core.input.LEFT_MOUSE, cmd=self.toggle)
2020-04-19 14:23:41 +02:00
def toggle(self, widget):
self.__project = "hit"
2020-04-19 14:27:11 +02:00
if self.__tracking:
util.cli.execute("watson stop")
2020-04-19 14:23:41 +02:00
else:
util.cli.execute("watson restart")
2020-04-19 14:27:11 +02:00
self.__tracking = not self.__tracking
2020-04-19 14:23:41 +02:00
def text(self, widget):
2020-04-19 14:27:11 +02:00
if self.__tracking:
return self.__project
2020-04-19 14:23:41 +02:00
else:
return "Paused"
2020-04-19 14:23:41 +02:00
2020-04-19 14:27:11 +02:00
def update(self):
output = util.cli.execute("watson status")
if re.match(r"No project started", output):
2020-04-19 14:27:11 +02:00
self.__tracking = False
2020-04-19 14:23:41 +02:00
return
2020-04-19 14:27:11 +02:00
self.__tracking = True
m = re.search(r"Project (.+) started", output)
2020-04-19 14:27:11 +02:00
self.__project = m.group(1)
2020-04-19 14:23:41 +02:00
def state(self, widget):
return "on" if self.__tracking else "off"
2020-04-19 14:23:41 +02:00
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4