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.
This commit is contained in:
enkore 2013-02-24 02:12:32 +01:00
parent bde56dfdec
commit a5bcf9bfa2
3 changed files with 51 additions and 1 deletions

View File

@ -35,6 +35,18 @@ as you like.
## Modules ## 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 ### battery
@ -43,6 +55,7 @@ battery status
* battery_ident — (default: BAT0) * 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) * color_unread — (default: #ff0000)
* format — (default: {unread} new email) * format — (default: {unread} new email)
* format_plural — (default: {unread} new emails) * 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: Currently available backends are:

31
i3pystatus/backlight.py Normal file
View File

@ -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,
}

View File

@ -23,7 +23,8 @@ class Mail(IntervalModule):
settings = ( settings = (
("backends", "List of backends (instances of i3pystatus.mail.xxx)"), ("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",) required = ("backends",)
@ -31,6 +32,7 @@ class Mail(IntervalModule):
color_unread ="#ff0000" color_unread ="#ff0000"
format = "{unread} new email" format = "{unread} new email"
format_plural = "{unread} new emails" format_plural = "{unread} new emails"
hide_if_null = True
def init(self): def init(self):
for backend in self.backends: for backend in self.backends:
@ -42,6 +44,9 @@ class Mail(IntervalModule):
if not unread: if not unread:
color = self.color color = self.color
urgent = "false" urgent = "false"
if self.hide_if_null:
self.output = None
return
else: else:
color = self.color_unread color = self.color_unread
urgent = "true" urgent = "true"