From 69e478018278718ee2a6679d7725ee7dc0ae1a84 Mon Sep 17 00:00:00 2001 From: zetxx Date: Wed, 15 Mar 2017 22:55:05 +0200 Subject: [PATCH 1/3] feat: added volume level for amixer --- bumblebee/modules/amixer.py | 34 +++++++++++++++++++++++++++++++++ themes/icons/ascii.json | 4 ++++ themes/icons/awesome-fonts.json | 5 ++++- 3 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 bumblebee/modules/amixer.py diff --git a/bumblebee/modules/amixer.py b/bumblebee/modules/amixer.py new file mode 100644 index 0000000..e8991fb --- /dev/null +++ b/bumblebee/modules/amixer.py @@ -0,0 +1,34 @@ +"""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) + ) + self._level = 0 + self._muted = False + device = self.parameter("device", "Master,0") + self._cmdString = "amixer get {}".format(device) + + def volume(self, widget): + m = re.search(r'([\d]+)\%', self._level) + self._muted = False + if m == "0": + self._muted = True + + return "{}%".format(m.group(1)) + + def update(self, widgets): + self._level = bumblebee.util.execute(self._cmdString) + + def state(self, widget): + if self._muted: + return [ "warning", "muted" ] + return [ "unmuted" ] diff --git a/themes/icons/ascii.json b/themes/icons/ascii.json index de89921..c29c6d5 100644 --- a/themes/icons/ascii.json +++ b/themes/icons/ascii.json @@ -22,6 +22,10 @@ "muted": { "prefix": "audio(mute)" }, "unmuted": { "prefix": "audio" } }, + "amixer": { + "muted": { "prefix": "audio(mute)" }, + "unmuted": { "prefix": "audio" } + }, "pasource": { "muted": { "prefix": "mic(mute)" }, "unmuted": { "prefix": "mic" } diff --git a/themes/icons/awesome-fonts.json b/themes/icons/awesome-fonts.json index 69dd60f..a6c1c90 100644 --- a/themes/icons/awesome-fonts.json +++ b/themes/icons/awesome-fonts.json @@ -9,7 +9,6 @@ "cpu": { "prefix": "" }, "disk": { "prefix": "" }, "dnf": { "prefix": "" }, - "pacman": { "prefix": "" }, "brightness": { "prefix": "" }, "load": { "prefix": "" }, "layout": { "prefix": "" }, @@ -35,6 +34,10 @@ "muted": { "prefix": "" }, "unmuted": { "prefix": "" } }, + "amixer": { + "muted": { "prefix": "" }, + "unmuted": { "prefix": "" } + }, "pasource": { "muted": { "prefix": "" }, "unmuted": { "prefix": "" } From 0b961e23049ac048effd2d70a17ccf108a6f2463 Mon Sep 17 00:00:00 2001 From: zetxx Date: Wed, 15 Mar 2017 23:02:13 +0200 Subject: [PATCH 2/3] fix: init type --- bumblebee/modules/amixer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bumblebee/modules/amixer.py b/bumblebee/modules/amixer.py index e8991fb..4ed7271 100644 --- a/bumblebee/modules/amixer.py +++ b/bumblebee/modules/amixer.py @@ -12,7 +12,7 @@ class Module(bumblebee.engine.Module): super(Module, self).__init__(engine, config, bumblebee.output.Widget(full_text=self.volume) ) - self._level = 0 + self._level = "0" self._muted = False device = self.parameter("device", "Master,0") self._cmdString = "amixer get {}".format(device) From 289b42b26a1b9a98bb6cc6146c984428477d2985 Mon Sep 17 00:00:00 2001 From: zetxx Date: Wed, 15 Mar 2017 23:12:55 +0200 Subject: [PATCH 3/3] fix: state, check regex result before use it --- bumblebee/modules/amixer.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/bumblebee/modules/amixer.py b/bumblebee/modules/amixer.py index 4ed7271..fa08ec3 100644 --- a/bumblebee/modules/amixer.py +++ b/bumblebee/modules/amixer.py @@ -13,17 +13,19 @@ class Module(bumblebee.engine.Module): bumblebee.output.Widget(full_text=self.volume) ) self._level = "0" - self._muted = False + self._muted = True device = self.parameter("device", "Master,0") self._cmdString = "amixer get {}".format(device) def volume(self, widget): m = re.search(r'([\d]+)\%', self._level) - self._muted = False - if m == "0": - self._muted = True - - return "{}%".format(m.group(1)) + self._muted = True + if m: + if m.group(1) != "0": + self._muted = False + return "{}%".format(m.group(1)) + else: + return "0%" def update(self, widgets): self._level = bumblebee.util.execute(self._cmdString)