From 14943a69cb5a0161a6646d1bcf44cad8f2099b60 Mon Sep 17 00:00:00 2001 From: Abin Simon Date: Fri, 21 Apr 2017 10:46:16 +0530 Subject: [PATCH 01/14] traffic module added --- bumblebee/modules/traffic.py | 45 +++++++++++++++++++++++++++++++++ themes/icons/awesome-fonts.json | 3 +++ 2 files changed, 48 insertions(+) create mode 100644 bumblebee/modules/traffic.py diff --git a/bumblebee/modules/traffic.py b/bumblebee/modules/traffic.py new file mode 100644 index 0000000..6e2a6b2 --- /dev/null +++ b/bumblebee/modules/traffic.py @@ -0,0 +1,45 @@ +import netifaces +import re + +import bumblebee.util +import bumblebee.input +import bumblebee.output +import bumblebee.engine + +class Module(bumblebee.engine.Module): + def __init__(self, engine, config): + widgets = [] + 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) + + def update(self, widgets): + self._update_widgets(widgets) + + def _update_widgets(self, widgets): + _ifconfdata = bumblebee.util.execute('ifconfig') + interfaces = [ i for i in netifaces.interfaces() if not i.startswith(self._exclude) ] + + interface = interfaces[0] + if interface is '': + interface = 'lo' + + _block = re.compile(r"" + interface + ":(.*\n)*", re.MULTILINE) + _down = re.compile(r"RX packets .* bytes (.*) \(", re.MULTILINE) + _current_down = re.search(_down,re.search(_block,_ifconfdata).group(0)).group(1) + _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) + _speed_down = bumblebee.util.bytefmt(int(_current_down) - int(_prev_down)) + _speed_up = bumblebee.util.bytefmt(int(_current_up) - int(_prev_up)) + widget.full_text("{} {} {}".format(interface, _speed_down, _speed_up)) + widget.set("absdown", _current_down) + widget.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 b3b2867..b12f73e 100644 --- a/themes/icons/awesome-fonts.json +++ b/themes/icons/awesome-fonts.json @@ -78,5 +78,8 @@ }, "sensors": { "prefix": "🌡" + }, + "traffic":{ + "prefix": "" } } From ed3d9bd5954c3e2d15ed7d225c966912f73a02e6 Mon Sep 17 00:00:00 2001 From: Abin Simon Date: Fri, 21 Apr 2017 10:52:34 +0530 Subject: [PATCH 02/14] remove interface name from traffic --- bumblebee/modules/traffic.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bumblebee/modules/traffic.py b/bumblebee/modules/traffic.py index 6e2a6b2..067f4a5 100644 --- a/bumblebee/modules/traffic.py +++ b/bumblebee/modules/traffic.py @@ -38,7 +38,7 @@ class Module(bumblebee.engine.Module): _prev_down = widget.get("absdown", 0) _speed_down = bumblebee.util.bytefmt(int(_current_down) - int(_prev_down)) _speed_up = bumblebee.util.bytefmt(int(_current_up) - int(_prev_up)) - widget.full_text("{} {} {}".format(interface, _speed_down, _speed_up)) + widget.full_text("{} {}".format(_speed_down, _speed_up)) widget.set("absdown", _current_down) widget.set("absup", _current_up) From d3e24c0eeacd83d3ac8b94a6be02d408bea050fd Mon Sep 17 00:00:00 2001 From: Abin Simon Date: Fri, 21 Apr 2017 10:59:25 +0530 Subject: [PATCH 03/14] add ascii icon for traffic --- themes/icons/ascii.json | 3 +++ 1 file changed, 3 insertions(+) diff --git a/themes/icons/ascii.json b/themes/icons/ascii.json index c29c6d5..c50cbce 100644 --- a/themes/icons/ascii.json +++ b/themes/icons/ascii.json @@ -60,4 +60,7 @@ "redshift": { "day": { "prefix": "day" }, "night": { "prefix": "night" }, "transition": { "prefix": "trans" } } + "traffic": { + "prefix": "traffic" + } } From a8693dcadaf296b58ff9547d9e9dbfca606de44d Mon Sep 17 00:00:00 2001 From: Abin Simon Date: Fri, 21 Apr 2017 11:40:02 +0530 Subject: [PATCH 04/14] 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": "" } } } From 8c45a63b4780ceb90f7098e625f5c1d2ab175f5c Mon Sep 17 00:00:00 2001 From: Abin Simon Date: Fri, 21 Apr 2017 11:44:25 +0530 Subject: [PATCH 05/14] update ascii icons for traffic --- themes/icons/ascii.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/themes/icons/ascii.json b/themes/icons/ascii.json index c50cbce..3e4a559 100644 --- a/themes/icons/ascii.json +++ b/themes/icons/ascii.json @@ -61,6 +61,7 @@ "day": { "prefix": "day" }, "night": { "prefix": "night" }, "transition": { "prefix": "trans" } } "traffic": { - "prefix": "traffic" + "down": { "prefix": "down"}, + "up": {"prefix": "up"} } } From bc26cd5dd6a63e07bf22a7e594ecaf84c951c4db Mon Sep 17 00:00:00 2001 From: Abin Simon Date: Fri, 21 Apr 2017 14:52:19 +0530 Subject: [PATCH 06/14] basic exception handling --- bumblebee/modules/traffic.py | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/bumblebee/modules/traffic.py b/bumblebee/modules/traffic.py index d076854..2a2509f 100644 --- a/bumblebee/modules/traffic.py +++ b/bumblebee/modules/traffic.py @@ -35,11 +35,15 @@ class Module(bumblebee.engine.Module): if interface is '': interface = 'lo' - _block = re.compile(r"" + interface + ":(.*\n)*", re.MULTILINE) - _down = re.compile(r"RX packets .* bytes (.*) \(", re.MULTILINE) - _current_down = re.search(_down,re.search(_block,_ifconfdata).group(0)).group(1) - _up = re.compile(r"TX packets .* bytes (.*) \(", re.MULTILINE) - _current_up = re.search(_up,re.search(_block,_ifconfdata).group(0)).group(1) + try: + _block = re.compile(r"" + interface + ":(.*\n)*", re.MULTILINE) + _down = re.compile(r"RX packets .* bytes (.*) \(", re.MULTILINE) + _current_down = re.search(_down,re.search(_block,_ifconfdata).group(0)).group(1) + _up = re.compile(r"TX packets .* bytes (.*) \(", re.MULTILINE) + _current_up = re.search(_up,re.search(_block,_ifconfdata).group(0)).group(1) + except: + _current_up = -1 + _current_down = -1 widget_down = self.widget("traffic.down") widget_up = self.widget("traffic.up") @@ -51,13 +55,21 @@ class Module(bumblebee.engine.Module): widgets.append(widget_up) _prev_down = widget_down.get("absdown", 0) - _speed_down = bumblebee.util.bytefmt(int(_current_down) - int(_prev_down)) + if _current_down is not -1: + _speed_down = bumblebee.util.bytefmt(int(_current_down) - int(_prev_down)) + widget_down.set("absdown", _current_down) + else: + _speed_down = bumblebee.util.bytefmt(0) + widget_down.set("absdown", _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)) + if _current_up is not -1: + _speed_up = bumblebee.util.bytefmt(int(_current_up) - int(_prev_up)) + widget_up.set("absup", _current_up) + else: + _speed_up = bumblebee.util.bytefmt(0) + widget_up.set("absup", _prev_up) widget_up.full_text("{}".format(_speed_up)) - widget_up.set("absup", _current_up) # vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4 From 430c9f5e93eed4912fb2e7f1bf5b3a6bf4e79f2e Mon Sep 17 00:00:00 2001 From: Tobias Witek Date: Sat, 22 Apr 2017 08:11:55 +0200 Subject: [PATCH 07/14] [modules/traffic] Minor refactoring * use psutil instead of "ifconfig" in order to avoid external command calls * fix a small bug in the ascii theme (missing colon) * show statistics per-nic --- bumblebee/modules/traffic.py | 92 ++++++++++++++++----------------- themes/icons/ascii.json | 6 +-- themes/icons/awesome-fonts.json | 4 +- 3 files changed, 50 insertions(+), 52 deletions(-) diff --git a/bumblebee/modules/traffic.py b/bumblebee/modules/traffic.py index 2a2509f..b7a0b39 100644 --- a/bumblebee/modules/traffic.py +++ b/bumblebee/modules/traffic.py @@ -1,75 +1,73 @@ -import netifaces import re +import psutil +import netifaces import bumblebee.util import bumblebee.input import bumblebee.output import bumblebee.engine +"""Displays network IO for interfaces. + +Parameters: + * traffic.exclude: Comma-separated list of interface prefixes to exclude (defaults to "lo,virbr,docker,vboxnet,veth") +""" + class Module(bumblebee.engine.Module): def __init__(self, engine, config): - widgets = [ - bumblebee.output.Widget(name="traffic.down"), - bumblebee.output.Widget(name="traffic.up"), - ] + widgets = [] 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 + self._status = "" def state(self, widget): - if widget.name == "traffic.down": - return "down" - if widget.name == "traffic.up": - return "up" + if "traffic.rx" in widget.name: + return "rx" + if "traffic.tx" in widget.name: + return "tx" return self._status def update(self, widgets): self._update_widgets(widgets) def _update_widgets(self, widgets): - _ifconfdata = bumblebee.util.execute('ifconfig') interfaces = [ i for i in netifaces.interfaces() if not i.startswith(self._exclude) ] - interface = interfaces[0] - if interface is '': - interface = 'lo' + counters = psutil.net_io_counters(pernic=True) + for interface in interfaces: + if not interface: interface = "lo" + rx = counters[interface].bytes_recv + tx = counters[interface].bytes_sent - try: - _block = re.compile(r"" + interface + ":(.*\n)*", re.MULTILINE) - _down = re.compile(r"RX packets .* bytes (.*) \(", re.MULTILINE) - _current_down = re.search(_down,re.search(_block,_ifconfdata).group(0)).group(1) - _up = re.compile(r"TX packets .* bytes (.*) \(", re.MULTILINE) - _current_up = re.search(_up,re.search(_block,_ifconfdata).group(0)).group(1) - except: - _current_up = -1 - _current_down = -1 + name = "traffic-{}".format(interface) + txname = "traffic.tx-{}".format(interface) + rxname = "traffic.rx-{}".format(interface) - 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) + widget = self.widget(name) + if not widget: + widget = bumblebee.output.Widget(name=name) + widgets.append(widget) + widget.full_text(interface) - _prev_down = widget_down.get("absdown", 0) - if _current_down is not -1: - _speed_down = bumblebee.util.bytefmt(int(_current_down) - int(_prev_down)) - widget_down.set("absdown", _current_down) - else: - _speed_down = bumblebee.util.bytefmt(0) - widget_down.set("absdown", _prev_down) - widget_down.full_text("{}".format(_speed_down)) + widget_rx = self.widget(rxname) + widget_tx = self.widget(txname) + if not widget_rx: + widget_rx = bumblebee.output.Widget(name=rxname) + widgets.append(widget_rx) + if not widget_tx: + widget_tx = bumblebee.output.Widget(name=txname) + widgets.append(widget_tx) - _prev_up = widget_up.get("absup", 0) - if _current_up is not -1: - _speed_up = bumblebee.util.bytefmt(int(_current_up) - int(_prev_up)) - widget_up.set("absup", _current_up) - else: - _speed_up = bumblebee.util.bytefmt(0) - widget_up.set("absup", _prev_up) - widget_up.full_text("{}".format(_speed_up)) + prev_rx = widget_rx.get("rx", 0) + prev_tx = widget_tx.get("tx", 0) + rxspeed = bumblebee.util.bytefmt(int(rx) - int(prev_rx)) + txspeed = bumblebee.util.bytefmt(int(tx) - int(prev_tx)) + + widget_rx.full_text(rxspeed) + widget_tx.full_text(txspeed) + + widget_rx.set("rx", rx) + widget_tx.set("tx", tx) # vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4 diff --git a/themes/icons/ascii.json b/themes/icons/ascii.json index 976a021..5d4b916 100644 --- a/themes/icons/ascii.json +++ b/themes/icons/ascii.json @@ -62,9 +62,9 @@ }, "sensors": { "prefix": "sensors" - } + }, "traffic": { - "down": { "prefix": "down"}, - "up": {"prefix": "up"} + "rx": { "prefix": "down"}, + "tx": {"prefix": "up"} } } diff --git a/themes/icons/awesome-fonts.json b/themes/icons/awesome-fonts.json index 526b6b7..4263a19 100644 --- a/themes/icons/awesome-fonts.json +++ b/themes/icons/awesome-fonts.json @@ -80,7 +80,7 @@ "prefix": "🌡" }, "traffic":{ - "down": { "prefix": "" }, - "up": { "prefix": "" } + "rx": { "prefix": "" }, + "tx": { "prefix": "" } } } From 5db5e02086d51fe52c1afa65587d2087ef928888 Mon Sep 17 00:00:00 2001 From: Tobias Witek Date: Sat, 22 Apr 2017 08:24:52 +0200 Subject: [PATCH 08/14] [core] Added min-width and alignment themeing Added theme-options ("minwidth" and "align") for setting the minimum width and the alignment of a widget. Also, allow widget to provide defaults for the theme options by setting an attribute in their store called "theme-". For example, a widget can now define a default alignment by using: widget.set("theme-align", "default-value"). --- bumblebee/output.py | 2 ++ bumblebee/theme.py | 9 +++++++++ 2 files changed, 11 insertions(+) diff --git a/bumblebee/output.py b/bumblebee/output.py index 578fb30..bf6a689 100644 --- a/bumblebee/output.py +++ b/bumblebee/output.py @@ -89,6 +89,8 @@ class I3BarOutput(object): "background": self._theme.bg(widget), "separator_block_width": self._theme.separator_block_width(widget), "separator": True if separator is None else False, + "min_width": self._theme.minwidth(widget), + "align": self._theme.align(widget), "instance": widget.id, "name": module.id, }) diff --git a/bumblebee/theme.py b/bumblebee/theme.py index 08584c7..a424f4a 100644 --- a/bumblebee/theme.py +++ b/bumblebee/theme.py @@ -74,6 +74,14 @@ class Theme(object): """Return the background color for this widget""" return self._get(widget, "bg", None) + def align(self, widget): + """Return the widget alignment""" + return self._get(widget, "align", None) + + def minwidth(self, widget): + """Return the minimum width string for this widget""" + return self._get(widget, "minwidth", "") + def separator(self, widget): """Return the separator between widgets""" return self._get(widget, "separator", None) @@ -131,6 +139,7 @@ class Theme(object): state_themes.append(self._get(widget, state, {})) value = self._defaults.get(name, default) + value = widget.get("theme-{}".format(name), value) value = self._cycle.get(name, value) value = module_theme.get(name, value) From e6357f4c90ba6b218cb5a4d4e6126827c08736e9 Mon Sep 17 00:00:00 2001 From: Tobias Witek Date: Sat, 22 Apr 2017 08:26:28 +0200 Subject: [PATCH 09/14] [modules/traffic] Add alignment and minimum width Set the minimum width for uplink and downlink widgets to "down 1000MB", which should be plenty, and change alignment to right (personally, I find this looks nicer). To not have the icons on the left side "jump around" depending on the value, make them suffixes. If this solution is not sufficient, alternatively, the widget itself could perform value padding. In that case, the whole alignment and min-width settings would be obsolete and the icons could remain on the left side. --- bumblebee/modules/traffic.py | 4 ++++ themes/icons/ascii.json | 4 ++-- themes/icons/awesome-fonts.json | 4 ++-- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/bumblebee/modules/traffic.py b/bumblebee/modules/traffic.py index b7a0b39..d1d4c0f 100644 --- a/bumblebee/modules/traffic.py +++ b/bumblebee/modules/traffic.py @@ -54,9 +54,13 @@ class Module(bumblebee.engine.Module): widget_tx = self.widget(txname) if not widget_rx: widget_rx = bumblebee.output.Widget(name=rxname) + widget_rx.set("theme-minwidth", "down 1000MB") + widget_rx.set("theme-align", "right") widgets.append(widget_rx) if not widget_tx: widget_tx = bumblebee.output.Widget(name=txname) + widget_tx.set("theme-minwidth", "down 1000MB") + widget_tx.set("theme-align", "right") widgets.append(widget_tx) prev_rx = widget_rx.get("rx", 0) diff --git a/themes/icons/ascii.json b/themes/icons/ascii.json index 5d4b916..cc34773 100644 --- a/themes/icons/ascii.json +++ b/themes/icons/ascii.json @@ -64,7 +64,7 @@ "prefix": "sensors" }, "traffic": { - "rx": { "prefix": "down"}, - "tx": {"prefix": "up"} + "rx": { "suffix": "down"}, + "tx": {"suffix": "up"} } } diff --git a/themes/icons/awesome-fonts.json b/themes/icons/awesome-fonts.json index 4263a19..5358b04 100644 --- a/themes/icons/awesome-fonts.json +++ b/themes/icons/awesome-fonts.json @@ -80,7 +80,7 @@ "prefix": "🌡" }, "traffic":{ - "rx": { "prefix": "" }, - "tx": { "prefix": "" } + "rx": { "suffix": "" }, + "tx": { "suffix": "" } } } From 547910611c19bce55fc71755b43aeb03fd32617f Mon Sep 17 00:00:00 2001 From: Tobias Witek Date: Sat, 22 Apr 2017 11:10:01 +0200 Subject: [PATCH 10/14] [modules/traffic] fix docstring location --- bumblebee/modules/traffic.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/bumblebee/modules/traffic.py b/bumblebee/modules/traffic.py index d1d4c0f..08d838c 100644 --- a/bumblebee/modules/traffic.py +++ b/bumblebee/modules/traffic.py @@ -1,3 +1,11 @@ +# pylint: disable=C0111,R0903 + +"""Displays network IO for interfaces. + +Parameters: + * traffic.exclude: Comma-separated list of interface prefixes to exclude (defaults to "lo,virbr,docker,vboxnet,veth") +""" + import re import psutil import netifaces @@ -7,12 +15,6 @@ import bumblebee.input import bumblebee.output import bumblebee.engine -"""Displays network IO for interfaces. - -Parameters: - * traffic.exclude: Comma-separated list of interface prefixes to exclude (defaults to "lo,virbr,docker,vboxnet,veth") -""" - class Module(bumblebee.engine.Module): def __init__(self, engine, config): widgets = [] From b59ea4d5ab01b9794612ca1668ef4c1080449db8 Mon Sep 17 00:00:00 2001 From: Tobias Witek Date: Sat, 22 Apr 2017 11:11:26 +0200 Subject: [PATCH 11/14] [tests] Fix broken tests caused by new theme methods Add "minwidth()" and "align()" mocks for i3bar output tests. --- tests/test_i3baroutput.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/test_i3baroutput.py b/tests/test_i3baroutput.py index 9b81c42..68f77df 100644 --- a/tests/test_i3baroutput.py +++ b/tests/test_i3baroutput.py @@ -24,6 +24,8 @@ class TestI3BarOutput(unittest.TestCase): self.theme.separator_block_width.return_value = 1 self.theme.fg.return_value = "#ababab" self.theme.bg.return_value = "#ababab" + self.theme.align.return_value = None + self.theme.minwidth.return_value = "" self.output = I3BarOutput(self.theme) self._stdout = mock.patch("bumblebee.output.sys.stdout", new_callable=StringIO) From 434473c87553387e54b84edac9fa1f657e60fa72 Mon Sep 17 00:00:00 2001 From: Tobias Witek Date: Sat, 22 Apr 2017 13:11:59 +0200 Subject: [PATCH 12/14] [general] Minor edit: Move from "theme-" to "theme." prefix Thinking about it, I find domain delimitors using "." more intuitive than "-", so fix that. --- bumblebee/modules/traffic.py | 8 ++++---- bumblebee/theme.py | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/bumblebee/modules/traffic.py b/bumblebee/modules/traffic.py index 08d838c..f74f7f9 100644 --- a/bumblebee/modules/traffic.py +++ b/bumblebee/modules/traffic.py @@ -56,13 +56,13 @@ class Module(bumblebee.engine.Module): widget_tx = self.widget(txname) if not widget_rx: widget_rx = bumblebee.output.Widget(name=rxname) - widget_rx.set("theme-minwidth", "down 1000MB") - widget_rx.set("theme-align", "right") + widget_rx.set("theme.minwidth", "down 1000MB") + widget_rx.set("theme.align", "right") widgets.append(widget_rx) if not widget_tx: widget_tx = bumblebee.output.Widget(name=txname) - widget_tx.set("theme-minwidth", "down 1000MB") - widget_tx.set("theme-align", "right") + widget_tx.set("theme.minwidth", "down 1000MB") + widget_tx.set("theme.align", "right") widgets.append(widget_tx) prev_rx = widget_rx.get("rx", 0) diff --git a/bumblebee/theme.py b/bumblebee/theme.py index a424f4a..0b2a724 100644 --- a/bumblebee/theme.py +++ b/bumblebee/theme.py @@ -139,7 +139,7 @@ class Theme(object): state_themes.append(self._get(widget, state, {})) value = self._defaults.get(name, default) - value = widget.get("theme-{}".format(name), value) + value = widget.get("theme.{}".format(name), value) value = self._cycle.get(name, value) value = module_theme.get(name, value) From 1a82a717fa1415998f13990a7baf75eeddc5490f Mon Sep 17 00:00:00 2001 From: Tobias Witek Date: Sun, 23 Apr 2017 07:15:07 +0200 Subject: [PATCH 13/14] [core] Calculate minwidth including pre/suffix Add the length of the prefix and suffix to the minimum width, if applicable. --- bumblebee/output.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/bumblebee/output.py b/bumblebee/output.py index bf6a689..cf1de79 100644 --- a/bumblebee/output.py +++ b/bumblebee/output.py @@ -70,10 +70,13 @@ class I3BarOutput(object): padding = self._theme.padding(widget) prefix = self._theme.prefix(widget, padding) suffix = self._theme.suffix(widget, padding) + minwidth = self._theme.minwidth(widget) if prefix: full_text = u"{}{}".format(prefix, full_text) + if minwidth: minwidth += "A"*len(prefix) if suffix: full_text = u"{}{}".format(full_text, suffix) + if minwidth: minwidth += "A"*len(suffix) separator = self._theme.separator(widget) if separator: self._widgets.append({ @@ -89,7 +92,7 @@ class I3BarOutput(object): "background": self._theme.bg(widget), "separator_block_width": self._theme.separator_block_width(widget), "separator": True if separator is None else False, - "min_width": self._theme.minwidth(widget), + "min_width": minwidth, "align": self._theme.align(widget), "instance": widget.id, "name": module.id, From 30bdab2767c4316edf17d3e623f50cb947304718 Mon Sep 17 00:00:00 2001 From: Tobias Witek Date: Sun, 23 Apr 2017 07:15:30 +0200 Subject: [PATCH 14/14] [modules/traffic] Make traffic icons prefixes again For consistent look, make the traffic icons prefixes, and change the alignment to left again, in order to avoid "jumping" of the icons. --- bumblebee/modules/traffic.py | 6 ++---- themes/icons/ascii.json | 4 ++-- themes/icons/awesome-fonts.json | 4 ++-- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/bumblebee/modules/traffic.py b/bumblebee/modules/traffic.py index f74f7f9..73ef673 100644 --- a/bumblebee/modules/traffic.py +++ b/bumblebee/modules/traffic.py @@ -56,13 +56,11 @@ class Module(bumblebee.engine.Module): widget_tx = self.widget(txname) if not widget_rx: widget_rx = bumblebee.output.Widget(name=rxname) - widget_rx.set("theme.minwidth", "down 1000MB") - widget_rx.set("theme.align", "right") + widget_rx.set("theme.minwidth", "1000.00MB") widgets.append(widget_rx) if not widget_tx: widget_tx = bumblebee.output.Widget(name=txname) - widget_tx.set("theme.minwidth", "down 1000MB") - widget_tx.set("theme.align", "right") + widget_tx.set("theme.minwidth", "1000.00MB") widgets.append(widget_tx) prev_rx = widget_rx.get("rx", 0) diff --git a/themes/icons/ascii.json b/themes/icons/ascii.json index cc34773..9b03a46 100644 --- a/themes/icons/ascii.json +++ b/themes/icons/ascii.json @@ -64,7 +64,7 @@ "prefix": "sensors" }, "traffic": { - "rx": { "suffix": "down"}, - "tx": {"suffix": "up"} + "rx": { "prefix": "down"}, + "tx": { "prefix": "up"} } } diff --git a/themes/icons/awesome-fonts.json b/themes/icons/awesome-fonts.json index 5358b04..4263a19 100644 --- a/themes/icons/awesome-fonts.json +++ b/themes/icons/awesome-fonts.json @@ -80,7 +80,7 @@ "prefix": "🌡" }, "traffic":{ - "rx": { "suffix": "" }, - "tx": { "suffix": "" } + "rx": { "prefix": "" }, + "tx": { "prefix": "" } } }