From a5bcf9bfa22eeeadd9eeef88c8c4cf899f4d95c2 Mon Sep 17 00:00:00 2001 From: enkore Date: Sun, 24 Feb 2013 02:12:32 +0100 Subject: [PATCH] backlight module Probably I'll discard these as soon as I come up with a nice generic way of reading multiple files, converting values etc. --- README.md | 14 ++++++++++++++ i3pystatus/backlight.py | 31 +++++++++++++++++++++++++++++++ i3pystatus/mail/__init__.py | 7 ++++++- 3 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 i3pystatus/backlight.py diff --git a/README.md b/README.md index 8e77eda..eca6dbb 100644 --- a/README.md +++ b/README.md @@ -35,6 +35,18 @@ as you like. ## Modules +### backlight + + +Shows backlight brightness + + +* format — format string used for output. {brightness}, {max_brightness}, {percentage} are available (default: {brightness}/{max_brightness}) +* backlight — backlight. See /sys/class/backlight/ (default: acpi_video0) +* color — (default: #FFFFFF) + + + ### battery @@ -43,6 +55,7 @@ battery status * battery_ident — (default: BAT0) +* format — (default: {status} {remaining}) @@ -79,6 +92,7 @@ The `backends` setting determines the backends to use. Currently available are: * color_unread — (default: #ff0000) * format — (default: {unread} new email) * format_plural — (default: {unread} new emails) +* hide_if_null — Don't output anything if there are no new mails (default: True) Currently available backends are: diff --git a/i3pystatus/backlight.py b/i3pystatus/backlight.py new file mode 100644 index 0000000..cdddd21 --- /dev/null +++ b/i3pystatus/backlight.py @@ -0,0 +1,31 @@ +from i3pystatus import IntervalModule + +class Backlight(IntervalModule): + """ + Shows backlight brightness + """ + + settings = ( + ("format", "format string used for output. {brightness}, {max_brightness}, {percentage} are available"), + ("backlight", "backlight. See /sys/class/backlight/"), + "color", + ) + format = "{brightness}/{max_brightness}" + color = "#FFFFFF" + backlight = "acpi_video0" + + def init(self): + self.base_path = "/sys/class/backlight/{backlight}".format(backlight=self.backlight) + + with open("{base_path}/max_brightness".format(base_path=self.base_path), "r") as f: + self.max_brightness = int(f.read()) + + def run(self): + with open("{base_path}/brightness".format(base_path=self.base_path), "r") as f: + brightness = int(f.read()) + + percentage = (brightness / self.max_brightness) * 100 + self.output = { + "full_text" : self.format.format(brightness=brightness, max_brightness=self.max_brightness, percentage=percentage), + "color": self.color, + } diff --git a/i3pystatus/mail/__init__.py b/i3pystatus/mail/__init__.py index 8c925e8..785d31c 100644 --- a/i3pystatus/mail/__init__.py +++ b/i3pystatus/mail/__init__.py @@ -23,7 +23,8 @@ class Mail(IntervalModule): settings = ( ("backends", "List of backends (instances of i3pystatus.mail.xxx)"), - "color", "color_unread", "format", "format_plural" + "color", "color_unread", "format", "format_plural", + ("hide_if_null", "Don't output anything if there are no new mails"), ) required = ("backends",) @@ -31,6 +32,7 @@ class Mail(IntervalModule): color_unread ="#ff0000" format = "{unread} new email" format_plural = "{unread} new emails" + hide_if_null = True def init(self): for backend in self.backends: @@ -42,6 +44,9 @@ class Mail(IntervalModule): if not unread: color = self.color urgent = "false" + if self.hide_if_null: + self.output = None + return else: color = self.color_unread urgent = "true"