Remove backlight module, add file module (kinda overpowered :-)
This commit is contained in:
parent
a5bcf9bfa2
commit
20da1dbb08
@ -1,31 +0,0 @@
|
|||||||
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,
|
|
||||||
}
|
|
47
i3pystatus/file.py
Normal file
47
i3pystatus/file.py
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
from os.path import join
|
||||||
|
|
||||||
|
from i3pystatus import IntervalModule
|
||||||
|
|
||||||
|
class File(IntervalModule):
|
||||||
|
"""
|
||||||
|
Rip information from text files
|
||||||
|
|
||||||
|
components is a dict of pairs of the form:
|
||||||
|
|
||||||
|
name => (callable, file)
|
||||||
|
|
||||||
|
* Where `name` is a valid identifier, which is used in the format string to access
|
||||||
|
the value of that component.
|
||||||
|
* `callable` is some callable to convert the contents of `file`. A common choice is
|
||||||
|
float or int.
|
||||||
|
* `file` names a file, relative to `base_path`.
|
||||||
|
|
||||||
|
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"
|
||||||
|
)
|
||||||
|
required = ("format", "components")
|
||||||
|
base_path = "/"
|
||||||
|
transforms = tuple()
|
||||||
|
color = "#FFFFFF"
|
||||||
|
|
||||||
|
def run(self):
|
||||||
|
cdict = {}
|
||||||
|
|
||||||
|
for key, (component, file) in self.components.items():
|
||||||
|
with open(join(self.base_path, file), "r") as f:
|
||||||
|
cdict[key] = component(f.read().strip())
|
||||||
|
|
||||||
|
for key, transform in self.transforms.items():
|
||||||
|
cdict[key] = transform(cdict)
|
||||||
|
|
||||||
|
self.output = {
|
||||||
|
"full_text": self.format.format(**cdict),
|
||||||
|
"color": self.color
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user