From a8693dcadaf296b58ff9547d9e9dbfca606de44d Mon Sep 17 00:00:00 2001 From: Abin Simon Date: Fri, 21 Apr 2017 11:40:02 +0530 Subject: [PATCH] seperate up and down speeds for traffic widget --- bumblebee/modules/traffic.py | 38 ++++++++++++++++++++++++--------- themes/icons/awesome-fonts.json | 3 ++- 2 files changed, 30 insertions(+), 11 deletions(-) diff --git a/bumblebee/modules/traffic.py b/bumblebee/modules/traffic.py index 067f4a5..d076854 100644 --- a/bumblebee/modules/traffic.py +++ b/bumblebee/modules/traffic.py @@ -8,10 +8,21 @@ import bumblebee.engine class Module(bumblebee.engine.Module): def __init__(self, engine, config): - widgets = [] + widgets = [ + bumblebee.output.Widget(name="traffic.down"), + bumblebee.output.Widget(name="traffic.up"), + ] super(Module, self).__init__(engine, config, widgets) self._exclude = tuple(filter(len, self.parameter("exclude", "lo,virbr,docker,vboxnet,veth").split(","))) self._update_widgets(widgets) + self._status = None + + def state(self, widget): + if widget.name == "traffic.down": + return "down" + if widget.name == "traffic.up": + return "up" + return self._status def update(self, widgets): self._update_widgets(widgets) @@ -30,16 +41,23 @@ class Module(bumblebee.engine.Module): _up = re.compile(r"TX packets .* bytes (.*) \(", re.MULTILINE) _current_up = re.search(_up,re.search(_block,_ifconfdata).group(0)).group(1) - widget = self.widget("traffic") - if not widget: - widget = bumblebee.output.Widget(name="traffic") - widgets.append(widget) - _prev_up = widget.get("absup", 0) - _prev_down = widget.get("absdown", 0) + widget_down = self.widget("traffic.down") + widget_up = self.widget("traffic.up") + if not widget_down: + widget_down = bumblebee.output.Widget(name="traffic.down") + widgets.append(widget_down) + if not widget_up: + widget_up = bumblebee.output.Widget(name="traffic.down") + widgets.append(widget_up) + + _prev_down = widget_down.get("absdown", 0) _speed_down = bumblebee.util.bytefmt(int(_current_down) - int(_prev_down)) + widget_down.full_text("{}".format(_speed_down)) + widget_down.set("absdown", _current_down) + + _prev_up = widget_up.get("absup", 0) _speed_up = bumblebee.util.bytefmt(int(_current_up) - int(_prev_up)) - widget.full_text("{} {}".format(_speed_down, _speed_up)) - widget.set("absdown", _current_down) - widget.set("absup", _current_up) + widget_up.full_text("{}".format(_speed_up)) + widget_up.set("absup", _current_up) # vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4 diff --git a/themes/icons/awesome-fonts.json b/themes/icons/awesome-fonts.json index b12f73e..526b6b7 100644 --- a/themes/icons/awesome-fonts.json +++ b/themes/icons/awesome-fonts.json @@ -80,6 +80,7 @@ "prefix": "🌡" }, "traffic":{ - "prefix": "" + "down": { "prefix": "" }, + "up": { "prefix": "" } } }