[modules/cmus] quotes
This commit is contained in:
parent
2314a7b27a
commit
a943e65ed7
1 changed files with 37 additions and 37 deletions
|
@ -36,10 +36,10 @@ class Module(bumblebee.engine.Module):
|
||||||
def __init__(self, engine, config):
|
def __init__(self, engine, config):
|
||||||
super(Module, self).__init__(engine, config, [])
|
super(Module, self).__init__(engine, config, [])
|
||||||
|
|
||||||
self._layout = self.parameter("layout", "cmus.prev cmus.main cmus.next cmus.shuffle cmus.repeat")
|
self._layout = self.parameter('layout', 'cmus.prev cmus.main cmus.next cmus.shuffle cmus.repeat')
|
||||||
self._fmt = self.parameter("format", "{artist} - {title} {position}/{duration}")
|
self._fmt = self.parameter('format', '{artist} - {title} {position}/{duration}')
|
||||||
self._server = self.parameter("server", None)
|
self._server = self.parameter('server', None)
|
||||||
self._passwd = self.parameter("passwd", None)
|
self._passwd = self.parameter('passwd', None)
|
||||||
self._status = None
|
self._status = None
|
||||||
self._shuffle = False
|
self._shuffle = False
|
||||||
self._repeat = False
|
self._repeat = False
|
||||||
|
@ -51,25 +51,25 @@ class Module(bumblebee.engine.Module):
|
||||||
for widget_name in self._layout.split():
|
for widget_name in self._layout.split():
|
||||||
widget = bumblebee.output.Widget(name=widget_name)
|
widget = bumblebee.output.Widget(name=widget_name)
|
||||||
widget_list.append(widget)
|
widget_list.append(widget)
|
||||||
self._cmd = "cmus-remote"
|
self._cmd = 'cmus-remote'
|
||||||
if self._server is not None:
|
if self._server is not None:
|
||||||
self._cmd = "{cmd} --server {server}".format(cmd=self._cmd, server=self._server)
|
self._cmd = '{cmd} --server {server}'.format(cmd=self._cmd, server=self._server)
|
||||||
if self._passwd is not None:
|
if self._passwd is not None:
|
||||||
self._cmd = "{cmd} --passwd {passwd}".format(cmd=self._cmd, passwd=self._passwd)
|
self._cmd = '{cmd} --passwd {passwd}'.format(cmd=self._cmd, passwd=self._passwd)
|
||||||
|
|
||||||
if widget_name == "cmus.prev":
|
if widget_name == 'cmus.prev':
|
||||||
widget_map[widget] = {"button": bumblebee.input.LEFT_MOUSE, "cmd": "{cmd} -r".format(cmd=self._cmd)}
|
widget_map[widget] = {'button': bumblebee.input.LEFT_MOUSE, 'cmd': '{cmd} -r'.format(cmd=self._cmd)}
|
||||||
elif widget_name == "cmus.main":
|
elif widget_name == 'cmus.main':
|
||||||
widget_map[widget] = {"button": bumblebee.input.LEFT_MOUSE, "cmd": "{cmd} -u".format(cmd=self._cmd)}
|
widget_map[widget] = {'button': bumblebee.input.LEFT_MOUSE, 'cmd': '{cmd} -u'.format(cmd=self._cmd)}
|
||||||
widget.full_text(self.description)
|
widget.full_text(self.description)
|
||||||
elif widget_name == "cmus.next":
|
elif widget_name == 'cmus.next':
|
||||||
widget_map[widget] = {"button": bumblebee.input.LEFT_MOUSE, "cmd": "{cmd} -n".format(cmd=self._cmd)}
|
widget_map[widget] = {'button': bumblebee.input.LEFT_MOUSE, 'cmd': '{cmd} -n'.format(cmd=self._cmd)}
|
||||||
elif widget_name == "cmus.shuffle":
|
elif widget_name == 'cmus.shuffle':
|
||||||
widget_map[widget] = {"button": bumblebee.input.LEFT_MOUSE, "cmd": "{cmd} -S".format(cmd=self._cmd)}
|
widget_map[widget] = {'button': bumblebee.input.LEFT_MOUSE, 'cmd': '{cmd} -S'.format(cmd=self._cmd)}
|
||||||
elif widget_name == "cmus.repeat":
|
elif widget_name == 'cmus.repeat':
|
||||||
widget_map[widget] = {"button": bumblebee.input.LEFT_MOUSE, "cmd": "{cmd} -R".format(cmd=self._cmd)}
|
widget_map[widget] = {'button': bumblebee.input.LEFT_MOUSE, 'cmd': '{cmd} -R'.format(cmd=self._cmd)}
|
||||||
else:
|
else:
|
||||||
raise KeyError("The cmus module does not support a {widget_name!r} widget".format(widget_name=widget_name))
|
raise KeyError('The cmus module does not support a {widget_name!r} widget'.format(widget_name=widget_name))
|
||||||
self.widgets(widget_list)
|
self.widgets(widget_list)
|
||||||
|
|
||||||
# Register input callbacks
|
# Register input callbacks
|
||||||
|
@ -88,44 +88,44 @@ class Module(bumblebee.engine.Module):
|
||||||
|
|
||||||
def state(self, widget):
|
def state(self, widget):
|
||||||
returns = {
|
returns = {
|
||||||
"cmus.shuffle": "shuffle-on" if self._shuffle else "shuffle-off",
|
'cmus.shuffle': 'shuffle-on' if self._shuffle else 'shuffle-off',
|
||||||
"cmus.repeat": "repeat-on" if self._repeat else "repeat-off",
|
'cmus.repeat': 'repeat-on' if self._repeat else 'repeat-off',
|
||||||
"cmus.prev": "prev",
|
'cmus.prev': 'prev',
|
||||||
"cmus.next": "next",
|
'cmus.next': 'next',
|
||||||
}
|
}
|
||||||
return returns.get(widget.name, self._status)
|
return returns.get(widget.name, self._status)
|
||||||
|
|
||||||
def _eval_line(self, line):
|
def _eval_line(self, line):
|
||||||
if line.startswith("file "):
|
if line.startswith('file '):
|
||||||
full_file = line[5:]
|
full_file = line[5:]
|
||||||
file1 = os.path.basename(full_file)
|
file1 = os.path.basename(full_file)
|
||||||
file2 = os.path.splitext(file1)[0]
|
file2 = os.path.splitext(file1)[0]
|
||||||
self._tags.update({"file": full_file})
|
self._tags.update({'file': full_file})
|
||||||
self._tags.update({"file1": file1})
|
self._tags.update({'file1': file1})
|
||||||
self._tags.update({"file2": file2})
|
self._tags.update({'file2': file2})
|
||||||
return
|
return
|
||||||
name, key, value = (line.split(" ", 2) + [None, None])[:3]
|
name, key, value = (line.split(' ', 2) + [None, None])[:3]
|
||||||
|
|
||||||
if name == "status":
|
if name == 'status':
|
||||||
self._status = key
|
self._status = key
|
||||||
if name == "tag":
|
if name == 'tag':
|
||||||
self._tags.update({key: value})
|
self._tags.update({key: value})
|
||||||
if name in ["duration", "position"]:
|
if name in ['duration', 'position']:
|
||||||
self._tags.update({name: bumblebee.util.durationfmt(int(key))})
|
self._tags.update({name: bumblebee.util.durationfmt(int(key))})
|
||||||
if name == "set" and key == "repeat":
|
if name == 'set' and key == 'repeat':
|
||||||
self._repeat = value == "true"
|
self._repeat = value == 'true'
|
||||||
if name == "set" and key == "shuffle":
|
if name == 'set' and key == 'shuffle':
|
||||||
self._shuffle = value == "true"
|
self._shuffle = value == 'true'
|
||||||
|
|
||||||
def _load_song(self):
|
def _load_song(self):
|
||||||
info = ""
|
info = ''
|
||||||
try:
|
try:
|
||||||
info = bumblebee.util.execute("{cmd} -Q".format(cmd=self._cmd))
|
info = bumblebee.util.execute('{cmd} -Q'.format(cmd=self._cmd))
|
||||||
except RuntimeError:
|
except RuntimeError:
|
||||||
self._status = None
|
self._status = None
|
||||||
|
|
||||||
self._tags = defaultdict(lambda: '')
|
self._tags = defaultdict(lambda: '')
|
||||||
for line in info.split("\n"):
|
for line in info.split('\n'):
|
||||||
self._eval_line(line)
|
self._eval_line(line)
|
||||||
|
|
||||||
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|
||||||
|
|
Loading…
Reference in a new issue