diff --git a/bumblebee/module.py b/bumblebee/module.py index c2fc585..2b60381 100644 --- a/bumblebee/module.py +++ b/bumblebee/module.py @@ -48,7 +48,12 @@ class Module(object): def state(self): return "default" + def instance(self): + return None + def next(self): return False + + # vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4 diff --git a/bumblebee/modules/disk.py b/bumblebee/modules/disk.py index 2089761..506d9d2 100644 --- a/bumblebee/modules/disk.py +++ b/bumblebee/modules/disk.py @@ -12,29 +12,34 @@ def description(): return "Shows free diskspace, total diskspace and the percentage of free disk space." class Module(bumblebee.module.Module): - def __init__(self, output, args): - super(Module, self).__init__(args) - self._path = args[0] if args else "/" + def __init__(self, output, config): + super(Module, self).__init__(output, config) + self._path = self._config.parameter("disk.path", "/") - output.add_callback(module=self.__module__, button=1, - cmd="nautilus {instance}") +# TODO +# output.add_callback(module=self.__module__, button=1, +# cmd="nautilus {instance}") - def data(self): + def widgets(self): st = os.statvfs(self._path) self._size = st.f_frsize*st.f_blocks self._used = self._size - st.f_frsize*st.f_bavail self._perc = 100.0*self._used/self._size - return "{} {}/{} ({:05.02f}%)".format(self._path, bumblebee.util.bytefmt(self._used), bumblebee.util.bytefmt(self._size), self._perc) + return bumblebee.output.Widget(self, + "{} {}/{} ({:05.02f}%)".format(self._path, + bumblebee.util.bytefmt(self._used), + bumblebee.util.bytefmt(self._size), self._perc) + ) def instance(self): return self._path def warning(self): - return self._perc > 80 + return self._perc > self._config.parameter("disk.warning", 80) def critical(self): - return self._perc > 90 + return self._perc > self._config.parameter("disk.critical", 90) # vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4 diff --git a/bumblebee/output.py b/bumblebee/output.py index ac5a57d..7613add 100644 --- a/bumblebee/output.py +++ b/bumblebee/output.py @@ -24,6 +24,9 @@ class Widget(object): def name(self): return self._obj.__module__ + def instance(self): + rv = getattr(self._obj, "instance")() + def text(self): return self._text diff --git a/bumblebee/outputs/i3.py b/bumblebee/outputs/i3.py index 2259e1a..4ed3970 100644 --- a/bumblebee/outputs/i3.py +++ b/bumblebee/outputs/i3.py @@ -62,7 +62,7 @@ class Output(bumblebee.output.Output): "color": theme.color(widget), "background": theme.background(widget), "name": widget.name(), - "instance": getattr(widget, "instance", None), + "instance": widget.instance(), "separator": theme.default_separators(widget), "separator_block_width": theme.separator_block_width(widget), })