[modules/cmus] Add controls for cmus (next/prev/shuffle/repeat)
Add controls that allow the user to switch to the next and previous song in cmus, toggle shuffle and repeat. Pause/play is toggled by clicking on the song title itself. fixes #5
This commit is contained in:
parent
a33cb1d7cb
commit
dead54ed1f
7 changed files with 82 additions and 7 deletions
|
@ -20,6 +20,12 @@ class Module(bumblebee.module.Module):
|
|||
self._status = "default"
|
||||
self._fmt = self._config.parameter("format", "{artist} - {title} {position}/{duration}")
|
||||
|
||||
output.add_callback(module="cmus.prev", button=1, cmd="cmus-remote -r")
|
||||
output.add_callback(module="cmus.next", button=1, cmd="cmus-remote -n")
|
||||
output.add_callback(module="cmus.shuffle", button=1, cmd="cmus-remote -S")
|
||||
output.add_callback(module="cmus.repeat", button=1, cmd="cmus-remote -R")
|
||||
output.add_callback(module=self.instance(), button=1, cmd="cmus-remote -u")
|
||||
|
||||
def _loadsong(self):
|
||||
process = subprocess.Popen(["cmus-remote", "-Q"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||
self._query, self._error = process.communicate()
|
||||
|
@ -30,17 +36,21 @@ class Module(bumblebee.module.Module):
|
|||
tags = defaultdict(lambda: '')
|
||||
for line in self._query:
|
||||
if line.startswith("status"):
|
||||
ignore, status = line.split(" ", 2)
|
||||
status = line.split(" ", 2)[1]
|
||||
self._status = status
|
||||
if line.startswith("tag"):
|
||||
ignore, key, value = line.split(" ", 2)
|
||||
key, value = line.split(" ", 2)[1:]
|
||||
tags.update({ key: value })
|
||||
if line.startswith("duration"):
|
||||
ignore, sec = line.split(" ")
|
||||
sec = line.split(" ")[1]
|
||||
tags.update({ "duration": bumblebee.util.durationfmt(int(sec)) })
|
||||
if line.startswith("position"):
|
||||
ignore, sec = line.split(" ")
|
||||
sec = line.split(" ")[1]
|
||||
tags.update({ "position": bumblebee.util.durationfmt(int(sec)) })
|
||||
if line.startswith("set repeat "):
|
||||
self._repeat = False if line.split(" ")[2] == "false" else True
|
||||
if line.startswith("set shuffle "):
|
||||
self._shuffle = False if line.split(" ")[2] == "false" else True
|
||||
|
||||
return tags
|
||||
|
||||
|
@ -48,9 +58,19 @@ class Module(bumblebee.module.Module):
|
|||
self._loadsong()
|
||||
tags = self._tags()
|
||||
|
||||
return bumblebee.output.Widget(self, string.Formatter().vformat(self._fmt, (), tags))
|
||||
return [
|
||||
bumblebee.output.Widget(self, "", instance="cmus.prev"),
|
||||
bumblebee.output.Widget(self, string.Formatter().vformat(self._fmt, (), tags)),
|
||||
bumblebee.output.Widget(self, "", instance="cmus.next"),
|
||||
bumblebee.output.Widget(self, "", instance="cmus.shuffle"),
|
||||
bumblebee.output.Widget(self, "", instance="cmus.repeat"),
|
||||
]
|
||||
|
||||
def state(self, widget):
|
||||
if widget.instance() == "cmus.shuffle":
|
||||
return "on" if self._shuffle else "off"
|
||||
if widget.instance() == "cmus.repeat":
|
||||
return "on" if self._repeat else "off"
|
||||
return self._status
|
||||
|
||||
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue