Moved backlight into submodule
This commit is contained in:
parent
2196c27ad4
commit
a06c4ef580
40
README.md
40
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
|
||||
|
@ -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)
|
||||
|
38
i3pystatus/backlight.py
Normal file
38
i3pystatus/backlight.py
Normal file
@ -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()
|
@ -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()
|
||||
|
Loading…
Reference in New Issue
Block a user