2020-03-07 13:34:02 +01:00
|
|
|
# pylint: disable=C0111,R0903
|
|
|
|
|
2020-04-02 16:30:31 +02:00
|
|
|
"""Displays the brightness of a display
|
2020-03-07 13:34:02 +01:00
|
|
|
|
|
|
|
Parameters:
|
|
|
|
* brightness.step: The amount of increase/decrease on scroll in % (defaults to 2)
|
|
|
|
|
2020-04-02 16:30:31 +02:00
|
|
|
"""
|
2020-03-07 13:34:02 +01:00
|
|
|
|
|
|
|
import glob
|
2020-03-07 13:37:56 +01:00
|
|
|
import shutil
|
2020-03-07 13:34:02 +01:00
|
|
|
|
2020-03-07 13:37:56 +01:00
|
|
|
import core.module
|
|
|
|
import core.widget
|
|
|
|
import core.input
|
2020-04-02 16:30:31 +02:00
|
|
|
import core.decorators
|
2020-03-07 13:34:02 +01:00
|
|
|
|
2020-04-11 08:58:34 +02:00
|
|
|
import util.cli
|
|
|
|
|
2020-03-07 13:37:56 +01:00
|
|
|
class Module(core.module.Module):
|
2020-04-11 08:58:34 +02:00
|
|
|
@core.decorators.every(seconds=30)
|
2020-04-26 16:39:24 +02:00
|
|
|
def __init__(self, config, theme):
|
|
|
|
super().__init__(config, theme, core.widget.Widget(self.brightness))
|
2020-03-07 13:37:56 +01:00
|
|
|
|
2020-04-11 08:58:34 +02:00
|
|
|
self.__brightness = 'n/a'
|
|
|
|
self.__readcmd = None
|
2020-03-07 13:34:22 +01:00
|
|
|
step = self.parameter('step', 2)
|
2020-03-07 13:34:02 +01:00
|
|
|
|
2020-03-07 13:37:56 +01:00
|
|
|
if shutil.which('light'):
|
2020-04-11 08:58:34 +02:00
|
|
|
self.__readcmd = self.__light
|
2020-03-07 13:37:56 +01:00
|
|
|
self.register_cmd('light -A {}%'.format(step),
|
|
|
|
'light -U {}%'.format(step))
|
|
|
|
elif shutil.which('brightnessctl'):
|
2020-04-11 08:58:34 +02:00
|
|
|
self.__readcmd = self.__brightnessctl
|
2020-03-07 13:37:56 +01:00
|
|
|
self.register_cmd('brightnessctl s {}%+'.format(step),
|
|
|
|
'brightnessctl s {}%-'.format(step))
|
2020-03-07 13:34:02 +01:00
|
|
|
else:
|
2020-04-11 08:58:34 +02:00
|
|
|
self.__readcmd = self.__xbacklight
|
2020-03-28 21:17:38 +01:00
|
|
|
self.register_cmd('xbacklight +{}%'.format(step),
|
2020-03-07 13:37:56 +01:00
|
|
|
'xbacklight -{}%'.format(step))
|
2020-03-07 13:34:02 +01:00
|
|
|
|
2020-03-07 13:37:56 +01:00
|
|
|
def register_cmd(self, up_cmd, down_cmd):
|
|
|
|
core.input.register(self, button=core.input.WHEEL_UP, cmd=up_cmd)
|
|
|
|
core.input.register(self, button=core.input.WHEEL_DOWN, cmd=down_cmd)
|
2020-03-07 13:34:02 +01:00
|
|
|
|
|
|
|
def brightness(self, widget):
|
2020-04-11 08:58:34 +02:00
|
|
|
return self.__brightness
|
|
|
|
|
|
|
|
def __light(self):
|
|
|
|
return util.cli.execute('light').strip()
|
|
|
|
|
|
|
|
def __brightnessctl(self):
|
|
|
|
m = util.cli.execute('brightnessctl m').strip()
|
|
|
|
g = util.cli.execute('brightnessctl g').strip()
|
|
|
|
return float(g)/float(m)*100.0
|
|
|
|
|
|
|
|
def __xbacklight(self):
|
|
|
|
return util.cli.execute('xbacklight -get').strip()
|
2020-03-07 13:34:02 +01:00
|
|
|
|
2020-03-07 13:37:56 +01:00
|
|
|
def update(self):
|
2020-03-07 13:34:02 +01:00
|
|
|
try:
|
2020-04-11 08:58:34 +02:00
|
|
|
self.__brightness = '{:3.0f}%'.format(float(self.__readcmd()))
|
2020-03-07 13:34:02 +01:00
|
|
|
except:
|
2020-04-11 08:58:34 +02:00
|
|
|
self.__brightness = 'n/a'
|
2020-03-07 13:34:02 +01:00
|
|
|
|
|
|
|
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|