2017-03-15 21:55:05 +01:00
|
|
|
"""get volume level
|
|
|
|
|
|
|
|
"""
|
|
|
|
import re
|
|
|
|
|
|
|
|
import bumblebee.input
|
|
|
|
import bumblebee.output
|
|
|
|
import bumblebee.engine
|
|
|
|
|
|
|
|
class Module(bumblebee.engine.Module):
|
|
|
|
def __init__(self, engine, config):
|
|
|
|
super(Module, self).__init__(engine, config,
|
|
|
|
bumblebee.output.Widget(full_text=self.volume)
|
|
|
|
)
|
2017-03-15 22:02:13 +01:00
|
|
|
self._level = "0"
|
2017-03-15 22:12:55 +01:00
|
|
|
self._muted = True
|
2017-03-15 21:55:05 +01:00
|
|
|
device = self.parameter("device", "Master,0")
|
|
|
|
self._cmdString = "amixer get {}".format(device)
|
|
|
|
|
|
|
|
def volume(self, widget):
|
|
|
|
m = re.search(r'([\d]+)\%', self._level)
|
2017-03-15 22:12:55 +01:00
|
|
|
self._muted = True
|
|
|
|
if m:
|
|
|
|
if m.group(1) != "0":
|
|
|
|
self._muted = False
|
|
|
|
return "{}%".format(m.group(1))
|
|
|
|
else:
|
|
|
|
return "0%"
|
2017-03-15 21:55:05 +01:00
|
|
|
|
|
|
|
def update(self, widgets):
|
2017-08-21 09:37:38 +02:00
|
|
|
level = ""
|
|
|
|
try:
|
|
|
|
level = bumblebee.util.execute(self._cmdString)
|
|
|
|
except Exception as e:
|
|
|
|
level = ""
|
|
|
|
|
|
|
|
self._level = level
|
2017-03-15 21:55:05 +01:00
|
|
|
|
|
|
|
def state(self, widget):
|
|
|
|
if self._muted:
|
2017-10-13 17:06:18 +02:00
|
|
|
return ["warning", "muted"]
|
|
|
|
return ["unmuted"]
|