diff --git a/i3pystatus/backlight.py b/i3pystatus/backlight.py deleted file mode 100644 index cdddd21..0000000 --- a/i3pystatus/backlight.py +++ /dev/null @@ -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, - } diff --git a/i3pystatus/file.py b/i3pystatus/file.py new file mode 100644 index 0000000..7374561 --- /dev/null +++ b/i3pystatus/file.py @@ -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 + }