[modules/amixer] update to new API
This commit is contained in:
parent
f5c1c4975f
commit
f2a62ca7c6
1 changed files with 30 additions and 27 deletions
|
@ -1,42 +1,45 @@
|
||||||
"""get volume level
|
"""get volume level
|
||||||
|
|
||||||
|
Parameters:
|
||||||
|
* amixer.device: Device to use, defaults to "Master,0"
|
||||||
"""
|
"""
|
||||||
import re
|
import re
|
||||||
|
|
||||||
import bumblebee.input
|
import core.module
|
||||||
import bumblebee.output
|
import core.widget
|
||||||
import bumblebee.engine
|
|
||||||
|
|
||||||
class Module(bumblebee.engine.Module):
|
import util.cli
|
||||||
def __init__(self, engine, config):
|
|
||||||
super(Module, self).__init__(engine, config,
|
class Module(core.module.Module):
|
||||||
bumblebee.output.Widget(full_text=self.volume)
|
def __init__(self, config):
|
||||||
)
|
super().__init__(config, core.widget.Widget(self.volume))
|
||||||
self._level = "0"
|
|
||||||
self._muted = True
|
self.__level = 'n/a'
|
||||||
device = self.parameter("device", "Master,0")
|
self.__muted = True
|
||||||
self._cmdString = "amixer get {}".format(device)
|
device = self.parameter('device', 'Master,0')
|
||||||
|
self._cmdString = 'amixer get {}'.format(device)
|
||||||
|
|
||||||
def volume(self, widget):
|
def volume(self, widget):
|
||||||
m = re.search(r'([\d]+)\%', self._level)
|
if self.__level == 'n/a':
|
||||||
self._muted = True
|
return self.__level
|
||||||
|
m = re.search(r'([\d]+)\%', self.__level)
|
||||||
|
self.__muted = True
|
||||||
if m:
|
if m:
|
||||||
if m.group(1) != "0" and "[on]" in self._level:
|
if m.group(1) != '0' and '[on]' in self.__level:
|
||||||
self._muted = False
|
self.__muted = False
|
||||||
return "{}%".format(m.group(1))
|
return '{}%'.format(m.group(1))
|
||||||
else:
|
else:
|
||||||
return "0%"
|
return '0%'
|
||||||
|
|
||||||
def update(self, widgets):
|
def update(self):
|
||||||
level = ""
|
|
||||||
try:
|
try:
|
||||||
level = bumblebee.util.execute(self._cmdString)
|
self.__level = util.cli.execute('amixer get {}'.format(self.parameter('device', 'Master,0')))
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
level = ""
|
self.__level = 'n/a'
|
||||||
|
|
||||||
self._level = level
|
|
||||||
|
|
||||||
def state(self, widget):
|
def state(self, widget):
|
||||||
if self._muted:
|
if self.__muted:
|
||||||
return ["warning", "muted"]
|
return ['warning', 'muted']
|
||||||
return ["unmuted"]
|
return ['unmuted']
|
||||||
|
|
||||||
|
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|
||||||
|
|
Loading…
Reference in a new issue