From 3c01f85455b589a03fef6bee02c3e6dfd0459b9f Mon Sep 17 00:00:00 2001 From: Pandada8 Date: Thu, 7 May 2015 10:05:52 +0800 Subject: [PATCH 1/4] Add xbacklight support --- i3pystatus/backlight.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/i3pystatus/backlight.py b/i3pystatus/backlight.py index ef8dc7a..dce6453 100644 --- a/i3pystatus/backlight.py +++ b/i3pystatus/backlight.py @@ -1,4 +1,6 @@ from i3pystatus.file import File +import shutils +import subprocesss class Backlight(File): @@ -30,8 +32,18 @@ class Backlight(File): transforms = { "percentage": lambda cdict: (cdict["brightness"] / cdict["max_brightness"]) * 100, } + on_upscroll = "lighter" + on_downscroll = "darker" def init(self): self.base_path = self.base_path.format(backlight=self.backlight) - + self.has_xbacklight = shutils.which("xbacklight") is not None super().init() + + def lighter(self): + if self.has_xbacklight: + subprocess.Popen(["backlight", '+5']) + + def darker(self): + if self.has_xbacklight: + subprocess.Popen(["backlight", '-5']) From babda71f9d9a14a9406448b08754e0b526eda88d Mon Sep 17 00:00:00 2001 From: Pandada8 Date: Thu, 7 May 2015 10:11:53 +0800 Subject: [PATCH 2/4] Fix typo :( --- i3pystatus/backlight.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/i3pystatus/backlight.py b/i3pystatus/backlight.py index dce6453..d6077a3 100644 --- a/i3pystatus/backlight.py +++ b/i3pystatus/backlight.py @@ -1,6 +1,7 @@ from i3pystatus.file import File -import shutils -import subprocesss +from i3pystatus import Module +import shutil +import subprocess class Backlight(File): @@ -34,16 +35,15 @@ class Backlight(File): } on_upscroll = "lighter" on_downscroll = "darker" - def init(self): self.base_path = self.base_path.format(backlight=self.backlight) - self.has_xbacklight = shutils.which("xbacklight") is not None - super().init() + self.has_xbacklight = shutil.which("xbacklight") is not None + super(Backlight, self).init() def lighter(self): if self.has_xbacklight: - subprocess.Popen(["backlight", '+5']) + subprocess.Popen(["xbacklight", '+5']) def darker(self): if self.has_xbacklight: - subprocess.Popen(["backlight", '-5']) + subprocess.Popen(["xbacklight", '-5']) From 0a3241ac304ecdd6854441af87515eb007e81e70 Mon Sep 17 00:00:00 2001 From: Pandada8 Date: Thu, 7 May 2015 10:58:28 +0800 Subject: [PATCH 3/4] pep8 and docs --- i3pystatus/backlight.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/i3pystatus/backlight.py b/i3pystatus/backlight.py index d6077a3..6261cf1 100644 --- a/i3pystatus/backlight.py +++ b/i3pystatus/backlight.py @@ -8,6 +8,8 @@ class Backlight(File): """ Screen backlight info + - Reuqire `xbacklight` installed to change the backlight through the scollwheel. + .. rubric:: Available formatters * `{brightness}` — current brightness relative to max_brightness @@ -35,15 +37,16 @@ class Backlight(File): } on_upscroll = "lighter" on_downscroll = "darker" + def init(self): self.base_path = self.base_path.format(backlight=self.backlight) self.has_xbacklight = shutil.which("xbacklight") is not None - super(Backlight, self).init() + super().init() def lighter(self): if self.has_xbacklight: - subprocess.Popen(["xbacklight", '+5']) + subprocess.Popen(["xbacklight", "+5"]) def darker(self): if self.has_xbacklight: - subprocess.Popen(["xbacklight", '-5']) + subprocess.Popen(["xbacklight", "-5"]) From 80b44c9c552ab61c2c8044e0713332996940482f Mon Sep 17 00:00:00 2001 From: Pandada8 Date: Fri, 8 May 2015 01:01:42 +0800 Subject: [PATCH 4/4] Use run_though_shell rather than subprocess --- i3pystatus/backlight.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/i3pystatus/backlight.py b/i3pystatus/backlight.py index 6261cf1..2bfa9e2 100644 --- a/i3pystatus/backlight.py +++ b/i3pystatus/backlight.py @@ -1,7 +1,7 @@ from i3pystatus.file import File from i3pystatus import Module +from i3pystatus.core.command import run_through_shell import shutil -import subprocess class Backlight(File): @@ -45,8 +45,8 @@ class Backlight(File): def lighter(self): if self.has_xbacklight: - subprocess.Popen(["xbacklight", "+5"]) + run_through_shell(["xbacklight", "+5"]) def darker(self): if self.has_xbacklight: - subprocess.Popen(["xbacklight", "-5"]) + run_through_shell(["xbacklight", "-5"])