From 3a19be09c31030974ea163d9c3c6a4022e000d0a Mon Sep 17 00:00:00 2001 From: Pavle Portic Date: Mon, 7 Nov 2016 22:00:02 +0100 Subject: [PATCH 1/2] Add brightness module --- bumblebee/modules/brightness.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 bumblebee/modules/brightness.py diff --git a/bumblebee/modules/brightness.py b/bumblebee/modules/brightness.py new file mode 100644 index 0000000..e5d82b8 --- /dev/null +++ b/bumblebee/modules/brightness.py @@ -0,0 +1,22 @@ +import bumblebee.module + +def description(): + return "Displays brightness percentage" + +class Module(bumblebee.module.Module): + def __init__(self, output, config, alias): + super(Module, self).__init__(output, config, alias) + self._brightness = 0 + self._max = 0 + self._percent = 0 + + def widgets(self): + with open("/sys/class/backlight/intel_backlight/brightness") as f: + self._brightness = int(f.read()) + with open("/sys/class/backlight/intel_backlight/max_brightness") as f: + self._max = int(f.read()) + self._brightness = self._brightness if self._brightness < self._max else self._max + self._percent = round(self._brightness * 100 / self._max) + + return bumblebee.output.Widget(self, "{:02d}%".format(self._percent)) + From 56524ce54bf9125374180757bb19c67254b6a0d7 Mon Sep 17 00:00:00 2001 From: Pavle Portic Date: Mon, 7 Nov 2016 22:14:46 +0100 Subject: [PATCH 2/2] Add Cmus player module --- bumblebee/modules/cmus.py | 46 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 bumblebee/modules/cmus.py diff --git a/bumblebee/modules/cmus.py b/bumblebee/modules/cmus.py new file mode 100644 index 0000000..dc2b70f --- /dev/null +++ b/bumblebee/modules/cmus.py @@ -0,0 +1,46 @@ +import datetime +import bumblebee.module +import subprocess + +def description(): + return "Displays the current song and artist playing in cmus" + +class Module(bumblebee.module.Module): + def __init__(self, output, config, alias): + super(Module, self).__init__(output, config, alias) + self._title = "None" + self._artist = "None" + self._status = 0 + + def widgets(self): + self._process = subprocess.Popen(["cmus-remote", "-Q"], stdout=subprocess.PIPE, stderr=subprocess.PIPE) + self._query, self._error = self._process.communicate() + self._query = self._query.decode("utf-8").split("\n") + if b'cmus is not running' in self._error: + return bumblebee.output.Widget(self, "Cmus isn't running") + for line in self._query: + if "status playing" in line: + self._status = 1 + if "status paused" in line: + self._status = 2 + if "status stopped" in line: + self._status = 3 + else: + if "tag title" in line: + self._title = line[10:] + if "tag artist" in line: + self._artist = line[11:] + + return bumblebee.output.Widget(self, "{} - {}".format( + self._artist, + self._title) + ) + def state(self, widget): + if self._status == 1: + return "playing" + if self._status == 2: + return "paused" + if self._status == 3: + return "stopped" + return "default" +