[module/watson] Add formatting string
Make it possible to customize the watson message in the widget see #963
This commit is contained in:
parent
14f19c897a
commit
8967eec44b
1 changed files with 19 additions and 8 deletions
|
@ -5,6 +5,10 @@
|
||||||
Requires the following executable:
|
Requires the following executable:
|
||||||
* watson
|
* watson
|
||||||
|
|
||||||
|
Parameters:
|
||||||
|
* watson.format: Output format, defaults to "{project} [{tags}]"
|
||||||
|
Supported fields are: {project}, {tags}, {relative_start}, {absolute_start}
|
||||||
|
|
||||||
contributed by `bendardenne <https://github.com/bendardenne>`_ - many thanks!
|
contributed by `bendardenne <https://github.com/bendardenne>`_ - many thanks!
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
@ -26,11 +30,11 @@ class Module(core.module.Module):
|
||||||
super().__init__(config, theme, core.widget.Widget(self.text))
|
super().__init__(config, theme, core.widget.Widget(self.text))
|
||||||
|
|
||||||
self.__tracking = False
|
self.__tracking = False
|
||||||
self.__project = ""
|
self.__info = {}
|
||||||
|
self.__format = self.parameter("format", "{project} [{tags}]")
|
||||||
core.input.register(self, button=core.input.LEFT_MOUSE, cmd=self.toggle)
|
core.input.register(self, button=core.input.LEFT_MOUSE, cmd=self.toggle)
|
||||||
|
|
||||||
def toggle(self, widget):
|
def toggle(self, widget):
|
||||||
self.__project = "hit"
|
|
||||||
if self.__tracking:
|
if self.__tracking:
|
||||||
util.cli.execute("watson stop")
|
util.cli.execute("watson stop")
|
||||||
else:
|
else:
|
||||||
|
@ -39,20 +43,27 @@ class Module(core.module.Module):
|
||||||
|
|
||||||
def text(self, widget):
|
def text(self, widget):
|
||||||
if self.__tracking:
|
if self.__tracking:
|
||||||
return self.__project
|
return self.__format.format(**self.__info)
|
||||||
else:
|
else:
|
||||||
return "Paused"
|
return "Paused"
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
output = util.cli.execute("watson status")
|
output = util.cli.execute("watson status")
|
||||||
if re.match(r"No project started", output):
|
|
||||||
|
m = re.search(r"Project ([^\[\]]+)(?: \[(.+)\])? started (.+) \((.+)\)", output)
|
||||||
|
|
||||||
|
if m:
|
||||||
|
self.__tracking = True
|
||||||
|
self.__info = {
|
||||||
|
"project": m.group(1),
|
||||||
|
"tags": m.group(2) or "",
|
||||||
|
"relative_start": m.group(3),
|
||||||
|
"absolute_start": m.group(4),
|
||||||
|
}
|
||||||
|
else:
|
||||||
self.__tracking = False
|
self.__tracking = False
|
||||||
return
|
return
|
||||||
|
|
||||||
self.__tracking = True
|
|
||||||
m = re.search(r"Project (.+) started", output)
|
|
||||||
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"
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue