[modules] Add module-specific configuration
Big oversight in my previous commits: Widgets need to be able to have specific configurations (i.e. the path for different instances of the "disk" module has to be different). To account for that, it is now possible to assign an "alias" to a module instance using ":" (for example: -m "disk:home"). This alias is then used for the configuration parameter resolution automatically, for example: -m disk:home -p home.path=/home As a consequence, parameter names in the module code are now relative to the module, which means: shorter!
This commit is contained in:
parent
9f9b27ad7a
commit
4e648cf009
11 changed files with 62 additions and 40 deletions
|
@ -11,9 +11,9 @@ def description():
|
|||
return "Displays battery status, percentage and whether it's charging or discharging."
|
||||
|
||||
class Module(bumblebee.module.Module):
|
||||
def __init__(self, output, config):
|
||||
super(Module, self).__init__(output, config)
|
||||
self._battery = config.parameter("battery.device", "BAT0")
|
||||
def __init__(self, output, config, alias):
|
||||
super(Module, self).__init__(output, config, alias)
|
||||
self._battery = config.parameter("device", "BAT0")
|
||||
self._capacity = 0
|
||||
self._status = "Unknown"
|
||||
|
||||
|
@ -25,10 +25,10 @@ class Module(bumblebee.module.Module):
|
|||
return bumblebee.output.Widget(self,"{:02d}%".format(self._capacity))
|
||||
|
||||
def warning(self, widget):
|
||||
return self._capacity < self._config.parameter("battery.warning", 20)
|
||||
return self._capacity < self._config.parameter("warning", 20)
|
||||
|
||||
def critical(self, widget):
|
||||
return self._capacity < self._config.parameter("battery.critical", 10)
|
||||
return self._capacity < self._config.parameter("critical", 10)
|
||||
|
||||
def state(self, widget):
|
||||
with open("/sys/class/power_supply/{}/status".format(self._battery)) as f:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue