From 7398bf9f94992945ec03bd2a13b9e8cd49c9e66a Mon Sep 17 00:00:00 2001 From: Frank Scherrer Date: Fri, 14 Jun 2019 12:04:36 +0200 Subject: [PATCH 1/3] add code to consider brightnessctl binary for brightness module --- bumblebee/modules/brightness.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/bumblebee/modules/brightness.py b/bumblebee/modules/brightness.py index 749f608..9943364 100644 --- a/bumblebee/modules/brightness.py +++ b/bumblebee/modules/brightness.py @@ -28,6 +28,11 @@ class Module(bumblebee.engine.Module): cmd="light -A {}%".format(step)) engine.input.register_callback(self, button=bumblebee.input.WHEEL_DOWN, cmd="light -U {}%".format(step)) + elif bumblebee.util.which("brightnessctl"): + engine.input.register_callback(self, button=bumblebee.input.WHEEL_UP, + cmd="brightnessctl s {}%+".format(step)) + engine.input.register_callback(self, button=bumblebee.input.WHEEL_DOWN, + cmd="brightnessctl s {}%-".format(step)) else: engine.input.register_callback(self, button=bumblebee.input.WHEEL_UP, cmd="xbacklight +{}%".format(step)) From 30789499f52c17987c78555bc573cd9515cd56d8 Mon Sep 17 00:00:00 2001 From: Frank Scherrer Date: Fri, 14 Jun 2019 12:08:56 +0200 Subject: [PATCH 2/3] format code to be flake8 conform --- bumblebee/modules/brightness.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/bumblebee/modules/brightness.py b/bumblebee/modules/brightness.py index 9943364..0601c01 100644 --- a/bumblebee/modules/brightness.py +++ b/bumblebee/modules/brightness.py @@ -13,11 +13,11 @@ 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.brightness) - ) + bumblebee.output.Widget(full_text=self.brightness)) self._brightness = 0 self._device_path = self.parameter("device_path", "/sys/class/backlight/intel_backlight") @@ -25,19 +25,19 @@ class Module(bumblebee.engine.Module): if bumblebee.util.which("light"): engine.input.register_callback(self, button=bumblebee.input.WHEEL_UP, - cmd="light -A {}%".format(step)) + cmd="light -A {}%".format(step)) engine.input.register_callback(self, button=bumblebee.input.WHEEL_DOWN, - cmd="light -U {}%".format(step)) + cmd="light -U {}%".format(step)) elif bumblebee.util.which("brightnessctl"): engine.input.register_callback(self, button=bumblebee.input.WHEEL_UP, - cmd="brightnessctl s {}%+".format(step)) + cmd="brightnessctl s {}%+".format(step)) engine.input.register_callback(self, button=bumblebee.input.WHEEL_DOWN, - cmd="brightnessctl s {}%-".format(step)) + cmd="brightnessctl s {}%-".format(step)) else: engine.input.register_callback(self, button=bumblebee.input.WHEEL_UP, - cmd="xbacklight +{}%".format(step)) + cmd="xbacklight +{}%".format(step)) engine.input.register_callback(self, button=bumblebee.input.WHEEL_DOWN, - cmd="xbacklight -{}%".format(step)) + cmd="xbacklight -{}%".format(step)) def brightness(self, widget): if isinstance(self._brightness, float): @@ -51,7 +51,7 @@ class Module(bumblebee.engine.Module): backlight = int(f.readline()) with open("{}/max_brightness".format(self._device_path)) as f: max_brightness = int(f.readline()) - self._brightness = float(backlight*100/max_brightness) + self._brightness = float(backlight * 100 / max_brightness) except: return "Error" From 0185335e6678593f5ae306a098d93495b5bc528a Mon Sep 17 00:00:00 2001 From: Frank Scherrer Date: Fri, 14 Jun 2019 12:53:38 +0200 Subject: [PATCH 3/3] refactoring regarding errors from codeclimate --- bumblebee/modules/brightness.py | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/bumblebee/modules/brightness.py b/bumblebee/modules/brightness.py index 0601c01..0e82351 100644 --- a/bumblebee/modules/brightness.py +++ b/bumblebee/modules/brightness.py @@ -24,20 +24,18 @@ class Module(bumblebee.engine.Module): step = self.parameter("step", 2) if bumblebee.util.which("light"): - engine.input.register_callback(self, button=bumblebee.input.WHEEL_UP, - cmd="light -A {}%".format(step)) - engine.input.register_callback(self, button=bumblebee.input.WHEEL_DOWN, - cmd="light -U {}%".format(step)) + self.register_cmd(engine, "light -A {}%".format(step), + "light -U {}%".format(step)) elif bumblebee.util.which("brightnessctl"): - engine.input.register_callback(self, button=bumblebee.input.WHEEL_UP, - cmd="brightnessctl s {}%+".format(step)) - engine.input.register_callback(self, button=bumblebee.input.WHEEL_DOWN, - cmd="brightnessctl s {}%-".format(step)) + self.register_cmd(engine, "brightnessctl s {}%+".format(step), + "brightnessctl s {}%-".format(step)) else: - engine.input.register_callback(self, button=bumblebee.input.WHEEL_UP, - cmd="xbacklight +{}%".format(step)) - engine.input.register_callback(self, button=bumblebee.input.WHEEL_DOWN, - cmd="xbacklight -{}%".format(step)) + self.register_cmd(engine, "xbacklight +{}%".format(step), + "xbacklight -{}%".format(step)) + + def register_cmd(self, engine, upCmd, downCmd): + engine.input.register_callback(self, button=bumblebee.input.WHEEL_UP, cmd=upCmd) + engine.input.register_callback(self, button=bumblebee.input.WHEEL_DOWN, cmd=downCmd) def brightness(self, widget): if isinstance(self._brightness, float):