2022-11-29 03:32:11 +01:00
|
|
|
# pylint: disable=C0111,R0903
|
|
|
|
|
|
|
|
"""Displays the status of watson (time-tracking tool)
|
|
|
|
Requires the following executable:
|
|
|
|
* watson
|
|
|
|
origional module contributed by `bendardenne <https://github.com/bendardenne>`_ - many thanks!
|
|
|
|
extended by `dale-muccignat <https://github.com/dale-muccignat>`_
|
|
|
|
"""
|
|
|
|
|
2022-11-29 07:27:06 +01:00
|
|
|
|
2022-11-29 03:32:11 +01:00
|
|
|
import logging
|
|
|
|
import re
|
|
|
|
import functools
|
|
|
|
|
|
|
|
import core.module
|
|
|
|
import core.widget
|
|
|
|
import core.input
|
|
|
|
import core.decorators
|
|
|
|
|
|
|
|
import util.cli
|
|
|
|
|
2022-11-30 01:15:10 +01:00
|
|
|
from easygui import *
|
|
|
|
|
2022-11-29 03:32:11 +01:00
|
|
|
|
|
|
|
class Module(core.module.Module):
|
2022-12-01 05:19:43 +01:00
|
|
|
@core.decorators.every(seconds=0.05)
|
2022-11-29 03:32:11 +01:00
|
|
|
def __init__(self, config, theme):
|
2022-12-01 05:19:43 +01:00
|
|
|
super().__init__(config, theme, core.widget.Widget(self.full_text))
|
2022-11-29 03:32:11 +01:00
|
|
|
|
|
|
|
self.__tracking = False
|
|
|
|
self.__status = ""
|
|
|
|
self.__project = "Select Project"
|
|
|
|
|
|
|
|
self.__project_key = {}
|
|
|
|
self.__project_list = []
|
|
|
|
|
|
|
|
core.input.register(self, button=core.input.LEFT_MOUSE, cmd=self.toggle)
|
2022-11-30 01:15:10 +01:00
|
|
|
core.input.register(self, button=core.input.RIGHT_MOUSE, cmd=self.new_project)
|
2022-11-30 01:24:56 +01:00
|
|
|
core.input.register(self, button=core.input.WHEEL_UP, cmd=self.change_project_up)
|
|
|
|
core.input.register(self, button=core.input.WHEEL_DOWN, cmd=self.change_project_down)
|
2022-11-29 03:32:11 +01:00
|
|
|
|
2022-12-01 05:19:43 +01:00
|
|
|
self.update_list()
|
|
|
|
|
|
|
|
def update_list(self):
|
|
|
|
# updates the list of current projects and creats a key dictionary
|
|
|
|
self.__project_list = util.cli.execute("watson projects").split()
|
|
|
|
for n in range(len(self.__project_list)):
|
|
|
|
if n == 0 and self.__project == "Select Project":
|
|
|
|
self.__project = self.__project_list[n]
|
|
|
|
if self.__project_list[n] not in self.__project_key:
|
|
|
|
self.__project_key[self.__project_list[n]] = n
|
|
|
|
|
2022-11-30 01:15:10 +01:00
|
|
|
def new_project(self, widget):
|
|
|
|
# on right-click, open dialog to enter the name of a new project
|
|
|
|
# TODO: enable entering a new tag in a second dialog box
|
|
|
|
if self.__tracking:
|
|
|
|
return
|
|
|
|
text = "Enter the name of a new project to start"
|
|
|
|
title = "Watson"
|
|
|
|
output = enterbox(text,title,self.__project)
|
|
|
|
if output:
|
|
|
|
self.__project = output
|
|
|
|
util.cli.execute("watson start " + self.__project)
|
2022-12-01 05:19:43 +01:00
|
|
|
self.update_list()
|
2022-11-30 01:15:10 +01:00
|
|
|
|
2022-11-29 03:32:11 +01:00
|
|
|
def toggle(self, widget):
|
|
|
|
# on click, starts the timer if the project is slected
|
|
|
|
if self.__project != "Select Project":
|
|
|
|
if self.__tracking:
|
|
|
|
util.cli.execute("watson stop")
|
|
|
|
else:
|
|
|
|
util.cli.execute("watson start " + self.__project)
|
|
|
|
self.__tracking = not self.__tracking
|
2022-12-01 05:19:43 +01:00
|
|
|
|
2022-11-29 03:32:11 +01:00
|
|
|
|
2022-11-30 01:24:56 +01:00
|
|
|
def change_project_up(self, event):
|
|
|
|
# on scroll up, cycles the currently selected project up
|
2022-11-29 03:32:11 +01:00
|
|
|
if self.__tracking:
|
|
|
|
return
|
|
|
|
if self.__project == "Select Project":
|
2022-11-30 01:24:56 +01:00
|
|
|
return
|
|
|
|
n = self.__project_key[self.__project]
|
|
|
|
if n < len(self.__project_list) - 1:
|
|
|
|
self.__project = self.__project_list[n + 1]
|
|
|
|
else:
|
2022-11-29 03:32:11 +01:00
|
|
|
self.__project = self.__project_list[0]
|
2022-11-30 01:24:56 +01:00
|
|
|
|
|
|
|
def change_project_down(self, event):
|
|
|
|
# on scroll down, cycles the currently selected project down
|
|
|
|
if self.__tracking:
|
|
|
|
return
|
|
|
|
if self.__project == "Select Project":
|
|
|
|
return
|
|
|
|
n = self.__project_key[self.__project]
|
|
|
|
if n > 0:
|
|
|
|
self.__project = self.__project_list[n - 1]
|
2022-11-29 03:32:11 +01:00
|
|
|
else:
|
2022-11-30 01:24:56 +01:00
|
|
|
self.__project = self.__project_list[-1]
|
2022-11-29 03:32:11 +01:00
|
|
|
|
2022-12-01 05:19:43 +01:00
|
|
|
def full_text(self, widget):
|
2022-11-29 03:32:11 +01:00
|
|
|
if self.__tracking:
|
2022-12-01 05:19:43 +01:00
|
|
|
return self.__project + ": Tracking" + self.__status
|
2022-11-29 03:32:11 +01:00
|
|
|
else:
|
2022-12-01 05:19:43 +01:00
|
|
|
return self.__project + ": Paused" + self.__status
|
2022-11-29 03:32:11 +01:00
|
|
|
|
|
|
|
def update(self):
|
|
|
|
output = util.cli.execute("watson status")
|
|
|
|
if re.match(r"No project started", output):
|
|
|
|
self.__tracking = False
|
2022-11-29 07:27:06 +01:00
|
|
|
else:
|
|
|
|
self.__tracking = True
|
|
|
|
m = re.search(r"Project (.+) started", output)
|
|
|
|
self.__project = m.group(1)
|
2022-11-29 03:32:11 +01:00
|
|
|
|
|
|
|
|
|
|
|
def state(self, widget):
|
|
|
|
return "on" if self.__tracking else "off"
|
|
|
|
|
|
|
|
|
|
|
|
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|