[modules/cmus] Update to latest API

This commit is contained in:
tobi-wan-kenobi 2020-04-28 20:25:28 +02:00
parent a943e65ed7
commit 32444ed49f
3 changed files with 25 additions and 21 deletions

View file

@ -64,6 +64,7 @@ def main():
core.event.trigger('stop') core.event.trigger('stop')
if __name__ == "__main__": if __name__ == "__main__":
main()
try: try:
main() main()
except Exception as e: except Exception as e:

View file

@ -153,7 +153,10 @@ class i3(object):
if widget.get('pango', False): if widget.get('pango', False):
blk.set('markup', 'pango') blk.set('markup', 'pango')
if self.__config.debug(): if self.__config.debug():
blk.set('__state', ', '.join(module.state(widget))) state = module.state(widget)
if isinstance(state, list):
state = ', '.join(state)
blk.set('__state', state)
return blk return blk
def blocks(self, module): def blocks(self, module):

View file

@ -24,17 +24,17 @@ from collections import defaultdict
import os import os
import string import string
import bumblebee.util import core.module
import bumblebee.input import core.widget
import bumblebee.output import core.input
import bumblebee.engine import core.decorators
from bumblebee.output import scrollable import util.cli
import util.format
class Module(core.module.Module):
class Module(bumblebee.engine.Module): def __init__(self, config, theme):
def __init__(self, engine, config): super().__init__(config, theme, [])
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}')
@ -49,7 +49,7 @@ class Module(bumblebee.engine.Module):
widget_list = [] widget_list = []
widget_map = {} widget_map = {}
for widget_name in self._layout.split(): for widget_name in self._layout.split():
widget = bumblebee.output.Widget(name=widget_name) widget = core.widget.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:
@ -58,32 +58,32 @@ class Module(bumblebee.engine.Module):
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': core.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': core.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': core.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': core.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': core.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
for widget, callback_options in widget_map.items(): for widget, callback_options in widget_map.items():
engine.input.register_callback(widget, **callback_options) core.input.register(widget, **callback_options)
def hidden(self): def hidden(self):
return self._status is None return self._status is None
@scrollable @core.decorators.scrollable
def description(self, widget): def description(self, widget):
return string.Formatter().vformat(self._fmt, (), self._tags) return string.Formatter().vformat(self._fmt, (), self._tags)
def update(self, widgets): def update(self):
self._load_song() self._load_song()
def state(self, widget): def state(self, widget):
@ -111,7 +111,7 @@ class Module(bumblebee.engine.Module):
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: util.format.duration(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':
@ -120,7 +120,7 @@ class Module(bumblebee.engine.Module):
def _load_song(self): def _load_song(self):
info = '' info = ''
try: try:
info = bumblebee.util.execute('{cmd} -Q'.format(cmd=self._cmd)) info = util.cli.execute('{cmd} -Q'.format(cmd=self._cmd))
except RuntimeError: except RuntimeError:
self._status = None self._status = None