[modules/cmus] Add status callback

Inform the theme about the current playback status (start, stop, repeat,
shuffle).

see #23
This commit is contained in:
Tobi-wan Kenobi 2016-12-10 08:16:27 +01:00
parent 225d471c6a
commit 1a3217bb5f
2 changed files with 18 additions and 2 deletions

View file

@ -22,6 +22,9 @@ class Module(bumblebee.engine.Module):
] ]
super(Module, self).__init__(engine, config, widgets) super(Module, self).__init__(engine, config, widgets)
self._fmt = self.parameter("format", "{artist} - {title} {position}/{duration}") self._fmt = self.parameter("format", "{artist} - {title} {position}/{duration}")
self._status = None
self._shuffle = False
self._repeat = False
def description(self): def description(self):
return string.Formatter().vformat(self._fmt, (), self._tags) return string.Formatter().vformat(self._fmt, (), self._tags)
@ -29,6 +32,17 @@ class Module(bumblebee.engine.Module):
def update(self, widgets): def update(self, widgets):
self._load_song() self._load_song()
def state(self, widget):
if widget.name == "cmus.shuffle":
return "shuffle-on" if self._shuffle else "shuffle-off"
if widget.name == "cmus.repeat":
return "repeat-on" if self._repeat else "repeat-off"
if widget.name == "cmus.prev":
return "prev"
if widget.name == "cmus.next":
return "next"
return self._status
def _load_song(self): def _load_song(self):
info = "" info = ""
try: try:

View file

@ -13,8 +13,10 @@
"stopped": { "prefix": "" }, "stopped": { "prefix": "" },
"prev": { "prefix": "" }, "prev": { "prefix": "" },
"next": { "prefix": "" }, "next": { "prefix": "" },
"shuffle": { "on": { "prefix": "" }, "off": { "prefix": "" } }, "shuffle-on": { "prefix": "" },
"repeat": { "on": { "prefix": "" }, "off": { "prefix": "" } } "shuffle-off": { "prefix": "" },
"repeat-on": { "prefix": "" },
"repeat-off": { "prefix": "" }
}, },
"pasink": { "pasink": {
"muted": { "prefix": "" }, "muted": { "prefix": "" },