From 7999cc453ba50691631997974de22982f7e90c64 Mon Sep 17 00:00:00 2001 From: enkore Date: Sun, 24 Feb 2013 05:25:29 +0100 Subject: [PATCH] Added file "template" for backlight info This is 100pct. the same functionality as a complete module before :-) But still, have to come up with some better way to manage these "templates". And a place to stash them. --- i3pystatus/file.py | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/i3pystatus/file.py b/i3pystatus/file.py index 7374561..2868ddb 100644 --- a/i3pystatus/file.py +++ b/i3pystatus/file.py @@ -19,12 +19,13 @@ class File(IntervalModule): transform is a optional dict of callables taking a single argument, a dictionary containing the values of all components. The return value is bound to `name` """ + settings = ( ("format", "format string"), ("components", "List of tripels"), ("transforms", "List of pairs"), ("base_path", ""), - "color" + "color", "interval", ) required = ("format", "components") base_path = "/" @@ -45,3 +46,26 @@ class File(IntervalModule): "full_text": self.format.format(**cdict), "color": self.color } + +def backlight(backlight="acpi_video0", format="{brightness}/{max_brightness}"): + """ + Backlight info template + + Available formatters: + * brightness + * max_brightness + * percentage + """ + + return File( + base_path="/sys/class/backlight/{backlight}/".format(backlight=backlight), + components={ + "brightness": (int, "brightness"), + "max_brightness": (int, "max_brightness"), + }, + transforms={ + "percentage": lambda cdict: (cdict["brightness"] / cdict["max_brightness"]) * 100, + }, + format="{brightness}/{max_brightness}", + interval=1 + )