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
|
2020-05-08 20:58:35 +02:00
|
|
|
|
|
|
|
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-05-03 11:15:52 +02:00
|
|
|
|
2020-04-19 14:27:11 +02:00
|
|
|
class Module(core.module.Module):
|
|
|
|
@core.decorators.every(minutes=60)
|
2020-04-26 16:39:24 +02:00
|
|
|
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
|
2020-05-03 11:15:52 +02:00
|
|
|
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):
|
2020-05-03 11:15:52 +02:00
|
|
|
self.__project = "hit"
|
2020-04-19 14:27:11 +02:00
|
|
|
if self.__tracking:
|
2020-05-03 11:15:52 +02:00
|
|
|
util.cli.execute("watson stop")
|
2020-04-19 14:23:41 +02:00
|
|
|
else:
|
2020-05-03 11:15:52 +02:00
|
|
|
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:
|
2020-05-03 11:15:52 +02:00
|
|
|
return "Paused"
|
2020-04-19 14:23:41 +02:00
|
|
|
|
2020-04-19 14:27:11 +02:00
|
|
|
def update(self):
|
2020-05-03 11:15:52 +02:00
|
|
|
output = util.cli.execute("watson status")
|
|
|
|
if re.match("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
|
2020-05-03 11:15:52 +02:00
|
|
|
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):
|
2020-05-03 11:15:52 +02:00
|
|
|
return "on" if self.__tracking else "off"
|
|
|
|
|
2020-04-19 14:23:41 +02:00
|
|
|
|
|
|
|
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|