From 72deb7eaf80308d06773183c59f6cc3e6e95cf18 Mon Sep 17 00:00:00 2001 From: tobi-wan-kenobi Date: Thu, 25 Jun 2020 20:34:13 +0200 Subject: [PATCH] [modules] add speed test module --- bumblebee_status/core/output.py | 5 ++- bumblebee_status/modules/core/ping.py | 2 - bumblebee_status/modules/core/speedtest.py | 52 ++++++++++++++++++++++ themes/icons/awesome-fonts.json | 4 ++ 4 files changed, 59 insertions(+), 4 deletions(-) create mode 100644 bumblebee_status/modules/core/speedtest.py diff --git a/bumblebee_status/core/output.py b/bumblebee_status/core/output.py index 929f0f4..088678d 100644 --- a/bumblebee_status/core/output.py +++ b/bumblebee_status/core/output.py @@ -228,16 +228,17 @@ class i3(object): if affected_modules and not module.id in affected_modules: continue if not affected_modules and module.next_update: - if module.parameter("interval", "") == "never": - continue if now < module.next_update: continue + if not redraw_only: module.update_wrapper() if module.parameter("interval", "") != "never": module.next_update = now + util.format.seconds( module.parameter("interval", self.__config.interval()) ) + else: + module.next_update = sys.maxsize for widget in module.widgets(): if not widget.id in self.__content: self.__content[widget.id] = { "minimized": False } diff --git a/bumblebee_status/modules/core/ping.py b/bumblebee_status/modules/core/ping.py index d43c027..7d650cd 100644 --- a/bumblebee_status/modules/core/ping.py +++ b/bumblebee_status/modules/core/ping.py @@ -24,8 +24,6 @@ import core.decorators import util.cli - - class Module(core.module.Module): @core.decorators.every(seconds=60) def __init__(self, config, theme): diff --git a/bumblebee_status/modules/core/speedtest.py b/bumblebee_status/modules/core/speedtest.py new file mode 100644 index 0000000..8f08bf9 --- /dev/null +++ b/bumblebee_status/modules/core/speedtest.py @@ -0,0 +1,52 @@ +# pylint: disable=C0111,R0903 + +"""Performs a speedtest - only updates when the "play" button is clicked + +Requires the following python module: + * speedtest-cli + +""" + +import core.module +import core.widget +import core.decorators + +import speedtest + + +class Module(core.module.Module): + @core.decorators.never + def __init__(self, config, theme): + super().__init__(config, theme, []) + + self.background = True + self.__result = "waiting" + self.__running = False + + start = self.add_widget(name="start") + main = self.add_widget(name="main", full_text=self.result) + + def result(self, _): + return self.__result + + def update(self): + self.__running = True + s = speedtest.Speedtest() + s.get_best_server() + s.download(threads=None) + s.upload(threads=None) + + self.__result = "ping: {:.2f}ms down: {:.2f}Mbps up: {:.2f}Mbps".format( + s.results.ping, + s.results.download / 1024 / 1024, + s.results.upload / 1024 / 1024, + ) + self.__running = False + + def state(self, widget): + if widget.name == "start": + return "running" if self.__running else "not-running" + return None + + +# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4 diff --git a/themes/icons/awesome-fonts.json b/themes/icons/awesome-fonts.json index 5a5269c..f524de3 100644 --- a/themes/icons/awesome-fonts.json +++ b/themes/icons/awesome-fonts.json @@ -281,5 +281,9 @@ }, "arandr": { "prefix": "" + }, + "speedtest": { + "running": { "prefix": "\uf110" }, + "not-running": { "prefix": "\uf144" } } }