From 2b5c85cb8c6a8164a25179f9f652fb9814d98c91 Mon Sep 17 00:00:00 2001 From: Justin Wheeler Date: Mon, 12 Jun 2017 22:18:49 -0400 Subject: [PATCH 1/5] Add packet loss to ping. Show packet loss in ping response. --- bumblebee/modules/ping.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/bumblebee/modules/ping.py b/bumblebee/modules/ping.py index 469871a..e19d603 100644 --- a/bumblebee/modules/ping.py +++ b/bumblebee/modules/ping.py @@ -30,6 +30,11 @@ def get_rtt(module, widget): )) for line in res.split("\n"): + if line.startswith( "{} packets transmitted".format( widget.get( "rtt-probes" ) ) ): + m = re.search( r'(\d+)% packet loss', line ) + + widget.set( 'packet-loss', m.group(1) ) + if not line.startswith("rtt"): continue m = re.search(r'([0-9\.]+)/([0-9\.]+)/([0-9\.]+)/([0-9\.]+)\s+(\S+)', line) @@ -51,16 +56,18 @@ class Module(bumblebee.engine.Module): widget.set("rtt-timeout", self.parameter("timeout", 5.0)) widget.set("rtt-avg", 0.0) widget.set("rtt-unit", "") + widget.set('packet-loss', 0) self._next_check = 0 def rtt(self, widget): if widget.get("rtt-unreachable"): return "{}: unreachable".format(widget.get("address")) - return "{}: {:.1f}{}".format( + return "{}: {:.1f}{} ({}%)".format( widget.get("address"), widget.get("rtt-avg"), - widget.get("rtt-unit") + widget.get("rtt-unit"), + widget.get( 'packet-loss' ) ) def state(self, widget): From e93e1120f735b60db9a7184f233cad3f31af592a Mon Sep 17 00:00:00 2001 From: Justin Wheeler Date: Mon, 12 Jun 2017 22:19:30 -0400 Subject: [PATCH 2/5] Show CPU MHz in sensors output. This may need some tweaking (specifically parameters settings) to show at what speed your CPU is running when showing sensors output. --- bumblebee/modules/sensors.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/bumblebee/modules/sensors.py b/bumblebee/modules/sensors.py index d76d10e..4f1a879 100644 --- a/bumblebee/modules/sensors.py +++ b/bumblebee/modules/sensors.py @@ -11,6 +11,9 @@ Parameters: """ import re +import decimal + +from subprocess import call import bumblebee.input import bumblebee.output @@ -36,10 +39,21 @@ class Module(bumblebee.engine.Module): return temperature + def get_mhz( self ): + output = open( '/proc/cpuinfo' ).read() + m = re.search( r"cpu MHz\s+:\s+(\d+)", output ) + mhz = int( m.group( 1 ) ) + + if mhz < 1000: + return "{} MHz".format( mhz ) + else: + return "%.1f GHz" % ( decimal.Decimal( mhz ) / 1000 ) + def temperature(self, _): - return self._temperature + return u"{}°c @ {}".format( self._temperature, self._mhz ) def update(self, widgets): self._temperature = self.get_temp() + self._mhz = self.get_mhz() # vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4 From 5d89c3dfc17bb073131c1faf5e009c4b649cbab7 Mon Sep 17 00:00:00 2001 From: Justin Wheeler Date: Mon, 12 Jun 2017 22:25:10 -0400 Subject: [PATCH 3/5] Fix icons. The moon icon seems to make more sense for night time. Add a datetime icon so you get a clock when using datetime. Change the CPU icon to the microchip character. --- themes/icons/awesome-fonts.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/themes/icons/awesome-fonts.json b/themes/icons/awesome-fonts.json index 7ce09e9..5a602a6 100644 --- a/themes/icons/awesome-fonts.json +++ b/themes/icons/awesome-fonts.json @@ -5,8 +5,9 @@ }, "date": { "prefix": "" }, "time": { "prefix": "" }, + "datetime": { "prefix": "" }, "memory": { "prefix": "" }, - "cpu": { "prefix": "" }, + "cpu": { "prefix": "" }, "disk": { "prefix": "" }, "dnf": { "prefix": "" }, "pacman": { "prefix": "" }, @@ -79,7 +80,7 @@ "on": { "prefix": " "}, "off": { "prefix": " " } }, "redshift": { - "day": { "prefix": "" }, "night": { "prefix": "" }, "transition": { "prefix": "" } + "day": { "prefix": "" }, "night": { "prefix": "" }, "transition": { "prefix": "" } }, "sensors": { "prefix": "" From 29f3e7b5158bdaaf67438053871b71d8ef417907 Mon Sep 17 00:00:00 2001 From: Justin Wheeler Date: Mon, 12 Jun 2017 22:26:33 -0400 Subject: [PATCH 4/5] Add weather icons. Add icons to the weather output to show condition to go with current temperature. --- bumblebee/modules/weather.py | 22 ++++++++++++++++++++++ themes/icons/awesome-fonts.json | 7 +++++++ 2 files changed, 29 insertions(+) diff --git a/bumblebee/modules/weather.py b/bumblebee/modules/weather.py index 01420e3..92a2745 100644 --- a/bumblebee/modules/weather.py +++ b/bumblebee/modules/weather.py @@ -51,6 +51,27 @@ class Module(bumblebee.engine.Module): return u"?" return u"{}°{}".format(self._temperature, self._unit_suffix()) + def state( self, widget ): + if self._valid: + if "thunderstorm" in self._weather: + return [ 'thunder' ] + elif "drizzle" in self._weather: + return [ 'rain' ] + elif "rain" in self._weather: + return [ 'rain' ] + elif "snow" in self._weather: + return [ 'snow' ] + elif "sleet" in self._weather: + return [ 'sleet' ] + elif "clear" in self._weather: + return [ 'clear' ] + elif "cloud" in self._weather: + return [ 'clouds' ] + else: + return [] + + return [] + def update(self, widgets): timestamp = int(time.time()) if self._nextcheck < int(time.time()): @@ -67,6 +88,7 @@ class Module(bumblebee.engine.Module): weather_url = "{url}&q={city}".format(url=weather_url, city=self._location) weather = json.loads(requests.get(weather_url).text) self._temperature = int(weather['main']['temp']) + self._weather = weather['weather'][0]['main'].lower() self._valid = True except RequestException: self._valid = False diff --git a/themes/icons/awesome-fonts.json b/themes/icons/awesome-fonts.json index 5a602a6..bf95f55 100644 --- a/themes/icons/awesome-fonts.json +++ b/themes/icons/awesome-fonts.json @@ -108,5 +108,12 @@ }, "publicip": { "prefix": "  " + }, + "weather": { + "clouds": { "prefix": "" }, + "rain": { "prefix": "" }, + "snow": { "prefix": "" }, + "clear": { "prefix": "" }, + "thunder": { "prefix": "" } } } From 215bfd23dfde50d86d7cf6181000bd73000e0ce8 Mon Sep 17 00:00:00 2001 From: Tobias Witek Date: Thu, 15 Jun 2017 07:48:25 +0200 Subject: [PATCH 5/5] [modules/sensors] Remove unused imports and minor reformatting --- bumblebee/modules/sensors.py | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/bumblebee/modules/sensors.py b/bumblebee/modules/sensors.py index 4f1a879..b8d77d7 100644 --- a/bumblebee/modules/sensors.py +++ b/bumblebee/modules/sensors.py @@ -1,3 +1,4 @@ +# -*- coding: UTF-8 -*- # pylint: disable=C0111,R0903 """Displays sensor temperature @@ -11,9 +12,6 @@ Parameters: """ import re -import decimal - -from subprocess import call import bumblebee.input import bumblebee.output @@ -24,6 +22,7 @@ class Module(bumblebee.engine.Module): super(Module, self).__init__(engine, config, bumblebee.output.Widget(full_text=self.temperature)) self._temperature = "unknown" + self._mhz = "n/a" pattern = self.parameter("match", "temp1_input") pattern_string = r"^\s*{}:\s*([\d.]+)$".format(pattern) self._match_number = int(self.parameter("match_number", "-1")) @@ -40,17 +39,17 @@ class Module(bumblebee.engine.Module): return temperature def get_mhz( self ): - output = open( '/proc/cpuinfo' ).read() - m = re.search( r"cpu MHz\s+:\s+(\d+)", output ) - mhz = int( m.group( 1 ) ) + output = open("/proc/cpuinfo").read() + m = re.search(r"cpu MHz\s+:\s+(\d+)", output) + mhz = int(m.group(1)) if mhz < 1000: - return "{} MHz".format( mhz ) + return "{} MHz".format(mhz) else: - return "%.1f GHz" % ( decimal.Decimal( mhz ) / 1000 ) + return "{:0.01f} GHz".format(float(mhz)/1000.0) def temperature(self, _): - return u"{}°c @ {}".format( self._temperature, self._mhz ) + return u"{}°c @ {}".format(self._temperature, self._mhz) def update(self, widgets): self._temperature = self.get_temp()