From 446eda72180db1fc6abd7b7bceaa575a5965c822 Mon Sep 17 00:00:00 2001 From: enkore Date: Mon, 25 Feb 2013 18:36:17 +0100 Subject: [PATCH] alsa module, requires pyalsaaudio (from PyPI) --- README.md | 20 ++++++++++++++++++ i3pystatus/alsa.py | 47 +++++++++++++++++++++++++++++++++++++++++ i3pystatus/backlight.py | 1 - 3 files changed, 67 insertions(+), 1 deletion(-) create mode 100644 i3pystatus/alsa.py diff --git a/README.md b/README.md index 19ea46e..bb60869 100644 --- a/README.md +++ b/README.md @@ -40,6 +40,26 @@ Many modules let you modify the output via a [format string](http://docs.python.org/3/library/string.html#formatstrings). +### alsa + + +Shows volume of ALSA mixer. You can also use this for inputs, btw. + +Requires pyalsaaudio + + +* `format` — {volume} is the current volume, {muted} is one of `muted` or `unmuted`. {card} is the sound card used; {mixer} the mixer. (default: `♪: {volume}`) +* `mixer` — ALSA mixer (default: `Master`) +* `mixer_id` — ALSA mixer id (default: `0`) +* `card` — ALSA sound card (default: `0`) +* `muted` — (default: `M`) +* `unmuted` — (default: ``) +* `color_muted` — (default: `#AAAAAA`) +* `color` — (default: `#FFFFFF`) +* `channel` — (default: `0`) + + + ### backlight diff --git a/i3pystatus/alsa.py b/i3pystatus/alsa.py new file mode 100644 index 0000000..cfae163 --- /dev/null +++ b/i3pystatus/alsa.py @@ -0,0 +1,47 @@ +from alsaaudio import Mixer + +from i3pystatus import IntervalModule + +class ALSA(IntervalModule): + """ + Shows volume of ALSA mixer. You can also use this for inputs, btw. + + Requires pyalsaaudio + """ + + settings = ( + ("format", "{volume} is the current volume, {muted} is one of `muted` or `unmuted`. {card} is the sound card used; {mixer} the mixer."), + ("mixer", "ALSA mixer"), + ("mixer_id", "ALSA mixer id"), + ("card", "ALSA sound card"), + "muted", "unmuted", + "color_muted", "color", + "channel" + ) + + muted = "M" + unmuted = "" + color_muted = "#AAAAAA" + color = "#FFFFFF" + format = "♪: {volume}" + mixer = "Master" + mixer_id = 0 + card = 0 + channel = 0 + + def init(self): + self.alsamixer = Mixer(control=self.mixer, id=self.mixer_id, cardindex=self.card) + self.fdict = { + "card": self.alsamixer.cardname(), + "mixer": self.mixer, + } + + def run(self): + muted = self.alsamixer.getmute()[self.channel] == 1 + self.fdict["volume"] = self.alsamixer.getvolume()[self.channel] + self.fdict["muted"] = self.muted if muted else self.muted + + self.output = { + "full_text" : self.format.format(**self.fdict), + "color": self.color_muted if muted else self.color, + } diff --git a/i3pystatus/backlight.py b/i3pystatus/backlight.py index e0878e0..5fcc6a0 100644 --- a/i3pystatus/backlight.py +++ b/i3pystatus/backlight.py @@ -20,7 +20,6 @@ class Backlight(File): backlight="acpi_video0" format="{brightness}/{max_brightness}" - interval=5 base_path = "/sys/class/backlight/{backlight}/" components={ "brightness": (int, "brightness"),