[modules/watson] Update to latest API
This commit is contained in:
parent
a9fd33f94f
commit
d2417411f3
1 changed files with 28 additions and 29 deletions
|
@ -6,52 +6,51 @@ Requires the following executable:
|
||||||
* watson
|
* watson
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import bumblebee.input
|
|
||||||
import bumblebee.output
|
|
||||||
import bumblebee.engine
|
|
||||||
import bumblebee.util
|
|
||||||
import bumblebee.popup_v2
|
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
import re
|
import re
|
||||||
import functools
|
import functools
|
||||||
|
|
||||||
class Module(bumblebee.engine.Module):
|
import core.module
|
||||||
def __init__(self, engine, config):
|
import core.widget
|
||||||
super(Module, self).__init__(engine, config,
|
import core.input
|
||||||
bumblebee.output.Widget(full_text=self.text))
|
import core.decorators
|
||||||
self._tracking = False
|
|
||||||
self._project = ''
|
import util.cli
|
||||||
engine.input.register_callback(self, button=bumblebee.input.LEFT_MOUSE,
|
|
||||||
cmd=self.toggle)
|
class Module(core.module.Module):
|
||||||
|
@core.decorators.every(minutes=60)
|
||||||
|
def __init__(self, config):
|
||||||
|
super().__init__(config, core.widget.Widget(self.text))
|
||||||
|
|
||||||
|
self.__tracking = False
|
||||||
|
self.__project = ''
|
||||||
|
core.input.register(self, button=core.input.LEFT_MOUSE, cmd=self.toggle)
|
||||||
|
|
||||||
def toggle(self, widget):
|
def toggle(self, widget):
|
||||||
self._project = 'hit'
|
self.__project = 'hit'
|
||||||
if self._tracking:
|
if self.__tracking:
|
||||||
bumblebee.util.execute('watson stop')
|
util.cli.execute('watson stop')
|
||||||
else:
|
else:
|
||||||
bumblebee.util.execute('watson restart')
|
util.cli.execute('watson restart')
|
||||||
self._tracking = not self._tracking
|
self.__tracking = not self.__tracking
|
||||||
|
|
||||||
def text(self, widget):
|
def text(self, widget):
|
||||||
if self._tracking:
|
if self.__tracking:
|
||||||
return self._project
|
return self.__project
|
||||||
else:
|
else:
|
||||||
return 'Paused'
|
return 'Paused'
|
||||||
|
|
||||||
def update(self, widgets):
|
def update(self):
|
||||||
output = bumblebee.util.execute('watson status')
|
output = util.cli.execute('watson status')
|
||||||
if re.match('No project started', output):
|
if re.match('No project started', output):
|
||||||
self._tracking = False
|
self.__tracking = False
|
||||||
return
|
return
|
||||||
|
|
||||||
self._tracking = True
|
self.__tracking = True
|
||||||
m = re.search(r'Project (.+) started', output)
|
m = re.search(r'Project (.+) started', output)
|
||||||
self._project = m.group(1)
|
self.__project = m.group(1)
|
||||||
|
|
||||||
#
|
|
||||||
def state(self, widget):
|
def state(self, widget):
|
||||||
return 'on' if self._tracking else 'off'
|
return 'on' if self.__tracking else 'off'
|
||||||
# return [widget.get('status', None), widget.get('period', None)]
|
|
||||||
|
|
||||||
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|
||||||
|
|
Loading…
Reference in a new issue