[output] Allow modules to pass back a single widget
Since "single widget" is the 99% use-case, make it easier for a module to return a single widget.
This commit is contained in:
parent
2cfb0997a0
commit
286aff2aa0
5 changed files with 9 additions and 14 deletions
|
@ -22,9 +22,7 @@ class Module(bumblebee.module.Module):
|
||||||
self._capacity = int(f.read())
|
self._capacity = int(f.read())
|
||||||
self._capacity = self._capacity if self._capacity < 100 else 100
|
self._capacity = self._capacity if self._capacity < 100 else 100
|
||||||
|
|
||||||
return [
|
return bumblebee.output.Widget(self,"{:02d}%".format(self._capacity))
|
||||||
bumblebee.output.Widget(self,"{:02d}%".format(self._capacity))
|
|
||||||
]
|
|
||||||
|
|
||||||
def warning(self):
|
def warning(self):
|
||||||
return self._capacity < self._config.parameter("battery.warning", 20)
|
return self._capacity < self._config.parameter("battery.warning", 20)
|
||||||
|
|
|
@ -21,11 +21,7 @@ class Module(bumblebee.module.Module):
|
||||||
|
|
||||||
def widgets(self):
|
def widgets(self):
|
||||||
self._perc = psutil.cpu_percent(percpu=False)
|
self._perc = psutil.cpu_percent(percpu=False)
|
||||||
return [
|
return bumblebee.output.Widget(self, "{:05.02f}%".format(self._perc))
|
||||||
bumblebee.output.Widget(self,
|
|
||||||
"{:05.02f}%".format(self._perc)
|
|
||||||
)
|
|
||||||
]
|
|
||||||
|
|
||||||
def warning(self):
|
def warning(self):
|
||||||
return self._perc > self._config.parameter("cpu.warning", 70)
|
return self._perc > self._config.parameter("cpu.warning", 70)
|
||||||
|
|
|
@ -32,10 +32,6 @@ class Module(bumblebee.module.Module):
|
||||||
self._fmt = config.parameter(param_name, default)
|
self._fmt = config.parameter(param_name, default)
|
||||||
|
|
||||||
def widgets(self):
|
def widgets(self):
|
||||||
return [
|
return bumblebee.output.Widget(self, datetime.datetime.now().strftime(self._fmt))
|
||||||
bumblebee.output.Widget(self,
|
|
||||||
datetime.datetime.now().strftime(self._fmt)
|
|
||||||
)
|
|
||||||
]
|
|
||||||
|
|
||||||
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|
||||||
|
|
|
@ -66,6 +66,11 @@ class Output(object):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def draw(self, widgets, theme):
|
def draw(self, widgets, theme):
|
||||||
|
if not type(widgets) is list:
|
||||||
|
widgets = [ widgets ]
|
||||||
|
self._draw(widgets, theme)
|
||||||
|
|
||||||
|
def _draw(self, widgets, theme):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def flush(self):
|
def flush(self):
|
||||||
|
|
|
@ -42,7 +42,7 @@ class Output(bumblebee.output.Output):
|
||||||
def start(self):
|
def start(self):
|
||||||
print json.dumps({ "version": 1, "click_events": True }) + "["
|
print json.dumps({ "version": 1, "click_events": True }) + "["
|
||||||
|
|
||||||
def draw(self, widgets, theme):
|
def _draw(self, widgets, theme):
|
||||||
for widget in widgets:
|
for widget in widgets:
|
||||||
if theme.separator(widget):
|
if theme.separator(widget):
|
||||||
self._data.append({
|
self._data.append({
|
||||||
|
|
Loading…
Reference in a new issue