[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:
|
||||
|
|
|
@ -11,8 +11,8 @@ def description():
|
|||
return "Displays CPU utilization across all CPUs."
|
||||
|
||||
class Module(bumblebee.module.Module):
|
||||
def __init__(self, output, config):
|
||||
super(Module, self).__init__(output, config)
|
||||
def __init__(self, output, config, alias):
|
||||
super(Module, self).__init__(output, config, alias)
|
||||
self._perc = psutil.cpu_percent(percpu=False)
|
||||
|
||||
# TODO
|
||||
|
@ -24,9 +24,9 @@ class Module(bumblebee.module.Module):
|
|||
return bumblebee.output.Widget(self, "{:05.02f}%".format(self._perc))
|
||||
|
||||
def warning(self, widget):
|
||||
return self._perc > self._config.parameter("cpu.warning", 70)
|
||||
return self._perc > self._config.parameter("warning", 70)
|
||||
|
||||
def critical(self, widget):
|
||||
return self._perc > self._config.parameter("cpu.critical", 80)
|
||||
return self._perc > self._config.parameter("critical", 80)
|
||||
|
||||
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|
||||
|
|
|
@ -12,9 +12,9 @@ def description():
|
|||
return "Shows free diskspace, total diskspace and the percentage of free disk space."
|
||||
|
||||
class Module(bumblebee.module.Module):
|
||||
def __init__(self, output, config):
|
||||
super(Module, self).__init__(output, config)
|
||||
self._path = self._config.parameter("disk.path", "/")
|
||||
def __init__(self, output, config, alias):
|
||||
super(Module, self).__init__(output, config, alias)
|
||||
self._path = self._config.parameter("path", "/")
|
||||
|
||||
# TODO
|
||||
# output.add_callback(module=self.__module__, button=1,
|
||||
|
@ -33,13 +33,10 @@ class Module(bumblebee.module.Module):
|
|||
bumblebee.util.bytefmt(self._size), self._perc)
|
||||
)
|
||||
|
||||
def instance(self, widget):
|
||||
return self._path
|
||||
|
||||
def warning(self, widget):
|
||||
return self._perc > self._config.parameter("disk.warning", 80)
|
||||
return self._perc > self._config.parameter("warning", 80)
|
||||
|
||||
def critical(self, widget):
|
||||
return self._perc > self._config.parameter("disk.critical", 90)
|
||||
return self._perc > self._config.parameter("critical", 90)
|
||||
|
||||
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|
||||
|
|
|
@ -12,12 +12,13 @@ def description():
|
|||
return "Shows available RAM, total amount of RAM and the percentage of available RAM."
|
||||
|
||||
class Module(bumblebee.module.Module):
|
||||
def __init__(self, output, config):
|
||||
super(Module, self).__init__(output, config)
|
||||
def __init__(self, output, config, alias):
|
||||
super(Module, self).__init__(output, config, alias)
|
||||
self._mem = psutil.virtual_memory()
|
||||
|
||||
output.add_callback(module=self.__module__, button=1,
|
||||
cmd="gnome-system-monitor")
|
||||
# TODO
|
||||
# output.add_callback(module=self.__module__, button=1,
|
||||
# cmd="gnome-system-monitor")
|
||||
|
||||
def widgets(self):
|
||||
self._mem = psutil.virtual_memory()
|
||||
|
@ -31,9 +32,9 @@ class Module(bumblebee.module.Module):
|
|||
)
|
||||
|
||||
def warning(self, widget):
|
||||
return self._mem.percent < self._config.parameter("memory.warning", 20)
|
||||
return self._mem.percent < self._config.parameter("warning", 20)
|
||||
|
||||
def critical(self, widget):
|
||||
return self._mem.percent < self._config.parameter("memory.critical", 10)
|
||||
return self._mem.percent < self._config.parameter("critical", 10)
|
||||
|
||||
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|
||||
|
|
|
@ -12,8 +12,8 @@ def description():
|
|||
return "Displays the names, IP addresses and status of each available interface."
|
||||
|
||||
class Module(bumblebee.module.Module):
|
||||
def __init__(self, output, config):
|
||||
super(Module, self).__init__(output, config)
|
||||
def __init__(self, output, config, alias):
|
||||
super(Module, self).__init__(output, config, alias)
|
||||
self._exclude = ( "lo", "virbr", "docker", "vboxnet" )
|
||||
self._state = "down"
|
||||
self._typecache = {}
|
||||
|
|
|
@ -26,8 +26,8 @@ def description():
|
|||
return "See 'pasource'."
|
||||
|
||||
class Module(bumblebee.module.Module):
|
||||
def __init__(self, output, config):
|
||||
super(Module, self).__init__(output, config)
|
||||
def __init__(self, output, config, alias):
|
||||
super(Module, self).__init__(output, config, alias)
|
||||
|
||||
self._module = self.__module__.split(".")[-1]
|
||||
self._left = 0
|
||||
|
|
|
@ -11,10 +11,10 @@ def description():
|
|||
return "Draws an empty field."
|
||||
|
||||
class Module(bumblebee.module.Module):
|
||||
def __init__(self, output, config):
|
||||
super(Module, self).__init__(output, config)
|
||||
def __init__(self, output, config, alias):
|
||||
super(Module, self).__init__(output, config, alias)
|
||||
|
||||
def widgets(self):
|
||||
return bumblebee.output.Widget(self, "")
|
||||
return bumblebee.output.Widget(self, self._config.parameter("text", ""))
|
||||
|
||||
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|
||||
|
|
|
@ -18,8 +18,8 @@ def description():
|
|||
return "Displays the current time, using the optional format string as input for strftime."
|
||||
|
||||
class Module(bumblebee.module.Module):
|
||||
def __init__(self, output, config):
|
||||
super(Module, self).__init__(output, config)
|
||||
def __init__(self, output, config, alias):
|
||||
super(Module, self).__init__(output, config, alias)
|
||||
|
||||
module = self.__module__.split(".")[-1]
|
||||
default = "%x %X"
|
||||
|
@ -28,8 +28,7 @@ class Module(bumblebee.module.Module):
|
|||
if module == "time":
|
||||
default = "%X"
|
||||
|
||||
param_name = "{}.format".format(module)
|
||||
self._fmt = config.parameter(param_name, default)
|
||||
self._fmt = config.parameter("format", default)
|
||||
|
||||
def widgets(self):
|
||||
return bumblebee.output.Widget(self, datetime.datetime.now().strftime(self._fmt))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue