bumblebee-status/bumblebee_status/modules/contrib/amixer.py
tobi-wan-kenobi 320827d577 [core] restructure to allow PIP packaging
OK - so I have to admit I *hate* the fact that PIP seems to require a
subdirectory named like the library.

But since the PIP package is something really nifty to have (thanks to
@tony again!!!), I updated the codebase to hopefully conform with what
PIP expects. Testruns so far look promising...
2020-05-09 21:22:00 +02:00

51 lines
1.3 KiB
Python

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