2020-04-13 09:14:22 +02:00
|
|
|
"""get volume level
|
|
|
|
|
2020-04-13 09:19:18 +02:00
|
|
|
Parameters:
|
|
|
|
* amixer.device: Device to use, defaults to "Master,0"
|
2020-05-08 20:58:35 +02:00
|
|
|
|
|
|
|
contributed by `zetxx <https://github.com/zetxx>`_ - many thanks!
|
2020-04-13 09:14:22 +02:00
|
|
|
"""
|
|
|
|
import re
|
|
|
|
|
2020-04-13 09:19:18 +02:00
|
|
|
import core.module
|
|
|
|
import core.widget
|
2020-04-13 09:14:22 +02:00
|
|
|
|
2020-04-13 09:19:18 +02:00
|
|
|
import util.cli
|
|
|
|
|
2020-05-03 11:15:52 +02:00
|
|
|
|
2020-04-13 09:19:18 +02:00
|
|
|
class Module(core.module.Module):
|
2020-04-26 16:39:24 +02:00
|
|
|
def __init__(self, config, theme):
|
|
|
|
super().__init__(config, theme, core.widget.Widget(self.volume))
|
2020-04-13 09:19:18 +02:00
|
|
|
|
2020-05-03 11:15:52 +02:00
|
|
|
self.__level = "n/a"
|
2020-04-13 09:19:18 +02:00
|
|
|
self.__muted = True
|
2020-05-03 11:15:52 +02:00
|
|
|
device = self.parameter("device", "Master,0")
|
|
|
|
self._cmdString = "amixer get {}".format(device)
|
2020-04-13 09:14:22 +02:00
|
|
|
|
|
|
|
def volume(self, widget):
|
2020-05-03 11:15:52 +02:00
|
|
|
if self.__level == "n/a":
|
2020-04-13 09:19:18 +02:00
|
|
|
return self.__level
|
2020-05-03 11:15:52 +02:00
|
|
|
m = re.search(r"([\d]+)\%", self.__level)
|
2020-04-13 09:19:18 +02:00
|
|
|
self.__muted = True
|
2020-04-13 09:14:22 +02:00
|
|
|
if m:
|
2020-05-03 11:15:52 +02:00
|
|
|
if m.group(1) != "0" and "[on]" in self.__level:
|
2020-04-13 09:19:18 +02:00
|
|
|
self.__muted = False
|
2020-05-03 11:15:52 +02:00
|
|
|
return "{}%".format(m.group(1))
|
2020-04-13 09:14:22 +02:00
|
|
|
else:
|
2020-05-03 11:15:52 +02:00
|
|
|
return "0%"
|
2020-04-13 09:14:22 +02:00
|
|
|
|
2020-04-13 09:19:18 +02:00
|
|
|
def update(self):
|
2020-04-13 09:14:22 +02:00
|
|
|
try:
|
2020-05-03 11:15:52 +02:00
|
|
|
self.__level = util.cli.execute(
|
|
|
|
"amixer get {}".format(self.parameter("device", "Master,0"))
|
|
|
|
)
|
2020-04-13 09:14:22 +02:00
|
|
|
except Exception as e:
|
2020-05-03 11:15:52 +02:00
|
|
|
self.__level = "n/a"
|
2020-04-13 09:14:22 +02:00
|
|
|
|
|
|
|
def state(self, widget):
|
2020-04-13 09:19:18 +02:00
|
|
|
if self.__muted:
|
2020-05-03 11:15:52 +02:00
|
|
|
return ["warning", "muted"]
|
|
|
|
return ["unmuted"]
|
|
|
|
|
2020-04-13 09:19:18 +02:00
|
|
|
|
|
|
|
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|