Merge pull request #10 from paxy97/master
Add brightness and Cmus modules
This commit is contained in:
commit
da4dd7c7a1
2 changed files with 68 additions and 0 deletions
22
bumblebee/modules/brightness.py
Normal file
22
bumblebee/modules/brightness.py
Normal file
|
@ -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))
|
||||||
|
|
46
bumblebee/modules/cmus.py
Normal file
46
bumblebee/modules/cmus.py
Normal file
|
@ -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"
|
||||||
|
|
Loading…
Reference in a new issue