diff --git a/README.md b/README.md index b497492..4e34420 100644 --- a/README.md +++ b/README.md @@ -37,6 +37,23 @@ as you like. ## Modules +### backlight + + +Screen backlight info + +Available formatters: +* brightness +* max_brightness +* percentage + + +* `format` — format string (default: `{brightness}/{max_brightness}`) +* `backlight` — backlight, see `/sys/class/backlight/` (default: `acpi_video0`) +* `color` — (default: `#FFFFFF`) + + + ### battery @@ -59,24 +76,7 @@ This class shows a clock -### file.Backlight - - -Screen backlight info - -Available formatters: -* brightness -* max_brightness -* percentage - - -* `format` — format string (default: `{brightness}/{max_brightness}`) -* `backlight` — backlight, see `/sys/class/backlight/` (default: `acpi_video0`) -* `color` — (default: `#FFFFFF`) - - - -### file.File +### file Rip information from text files @@ -91,8 +91,8 @@ the value of that component. 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` +transforms is a optional dict of callables taking a single argument (a dictionary containing the values +of all components). The return value is bound to the key. * `format` — format string diff --git a/i3pystatus/__init__.py b/i3pystatus/__init__.py index 92f783f..0345129 100644 --- a/i3pystatus/__init__.py +++ b/i3pystatus/__init__.py @@ -168,12 +168,19 @@ class ClassFinder: self.baseclass = baseclass self.exclude = exclude - def predicate(self, obj): - return inspect.isclass(obj) and issubclass(obj, self.baseclass) and obj not in self.exclude + def predicate_factory(self, module): + def predicate(obj): + return ( + inspect.isclass(obj) and + issubclass(obj, self.baseclass) and + obj not in self.exclude and + obj.__module__ == module.__name__ + ) + return predicate def search_module(self, module): # Neat trick: [(x,y),(u,v)] becomes [(x,u),(y,v)] - return list(zip(*inspect.getmembers(module, self.predicate)))[1] + return list(zip(*inspect.getmembers(module, self.predicate_factory(module))))[1] def get_class(self, module): classes = self.search_module(module) diff --git a/i3pystatus/backlight.py b/i3pystatus/backlight.py new file mode 100644 index 0000000..1c2b5a3 --- /dev/null +++ b/i3pystatus/backlight.py @@ -0,0 +1,38 @@ +from i3pystatus.file import File + +__imported__ = [File] + +class Backlight(File): + """ + Screen backlight info + + Available formatters: + * brightness + * max_brightness + * percentage + """ + + settings = ( + ("format", "format string"), + ("backlight", "backlight, see `/sys/class/backlight/`"), + "color", + ) + required = () + + backlight="acpi_video0" + format="{brightness}/{max_brightness}" + + interval=1 + base_path = "/sys/class/backlight/{backlight}/" + components={ + "brightness": (int, "brightness"), + "max_brightness": (int, "max_brightness"), + } + transforms={ + "percentage": lambda cdict: (cdict["brightness"] / cdict["max_brightness"]) * 100, + } + + def init(self): + self.base_path = self.base_path.format(backlight=self.backlight) + + super().init() diff --git a/i3pystatus/file.py b/i3pystatus/file.py index f998c0d..193f339 100644 --- a/i3pystatus/file.py +++ b/i3pystatus/file.py @@ -16,8 +16,8 @@ class File(IntervalModule): 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` + transforms is a optional dict of callables taking a single argument (a dictionary containing the values + of all components). The return value is bound to the key. """ settings = ( @@ -46,38 +46,3 @@ class File(IntervalModule): "full_text": self.format.format(**cdict), "color": self.color } - -class Backlight(File): - """ - Screen backlight info - - Available formatters: - * brightness - * max_brightness - * percentage - """ - - settings = ( - ("format", "format string"), - ("backlight", "backlight, see `/sys/class/backlight/`"), - "color", - ) - required = () - - backlight="acpi_video0" - format="{brightness}/{max_brightness}" - - interval=1 - base_path = "/sys/class/backlight/{backlight}/" - components={ - "brightness": (int, "brightness"), - "max_brightness": (int, "max_brightness"), - } - transforms={ - "percentage": lambda cdict: (cdict["brightness"] / cdict["max_brightness"]) * 100, - } - - def init(self): - self.base_path = self.base_path.format(backlight=self.backlight) - - super().init()