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)) + 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" +