From f96844b906f88708ee61eec9f44ac5a15c77f3c8 Mon Sep 17 00:00:00 2001 From: Pi-Yueh Chuang Date: Wed, 18 Dec 2019 23:34:30 -0500 Subject: [PATCH 1/3] add icons to battery-upower The icons are the same set used by the module *battery*. --- themes/icons/ascii.json | 39 +++++++++++++++++++++++++++++++++ themes/icons/awesome-fonts.json | 20 +++++++++++++++++ 2 files changed, 59 insertions(+) diff --git a/themes/icons/ascii.json b/themes/icons/ascii.json index fc36b95..fea74a1 100644 --- a/themes/icons/ascii.json +++ b/themes/icons/ascii.json @@ -93,6 +93,45 @@ "prefix": "tun" } }, + "battery-upower": { + "charged": { + "suffix": "full" + }, + "charging": { + "suffix": "chr" + }, + "AC": { + "suffix": "ac" + }, + "discharging-10": { + "prefix": "!", + "suffix": "dis" + }, + "discharging-25": { + "suffix": "dis" + }, + "discharging-50": { + "suffix": "dis" + }, + "discharging-80": { + "suffix": "dis" + }, + "discharging-100": { + "suffix": "dis" + }, + "unknown-25": { + "suffix": "?" + }, + "unknown-50": { + "suffix": "?" + }, + "unknown-80": { + "suffix": "?" + }, + "unknown-100": { + "suffix": "?" + } + }, "battery": { "charged": { "suffix": "full" diff --git a/themes/icons/awesome-fonts.json b/themes/icons/awesome-fonts.json index 476d065..36ef75a 100644 --- a/themes/icons/awesome-fonts.json +++ b/themes/icons/awesome-fonts.json @@ -82,6 +82,26 @@ "OFF": { "prefix": "" }, "?": { "prefix": "" } }, + "battery-upower": { + "charged": { "prefix": "", "suffix": "" }, + "AC": { "suffix": "" }, + "charging": { + "prefix": ["", "", "", "", ""], + "suffix": "" + }, + "discharging-10": { "prefix": "", "suffix": "" }, + "discharging-25": { "prefix": "", "suffix": "" }, + "discharging-50": { "prefix": "", "suffix": "" }, + "discharging-80": { "prefix": "", "suffix": "" }, + "discharging-100": { "prefix": "", "suffix": "" }, + "unlimited": { "prefix": "", "suffix": "" }, + "estimate": { "prefix": "" }, + "unknown-10": { "prefix": "", "suffix": "" }, + "unknown-25": { "prefix": "", "suffix": "" }, + "unknown-50": { "prefix": "", "suffix": "" }, + "unknown-80": { "prefix": "", "suffix": "" }, + "unknown-100": { "prefix": "", "suffix": "" } + }, "battery": { "charged": { "prefix": "", "suffix": "" }, "AC": { "suffix": "" }, From 33a9787b2f6e4435b87cd8afcb7ddb43c0d61697 Mon Sep 17 00:00:00 2001 From: Pi-Yueh Chuang Date: Wed, 18 Dec 2019 23:43:10 -0500 Subject: [PATCH 2/3] improve battery-upower module: charging remaing time - fix the documentation of parameters - now also show the remaining time to fully charged when charging - modify the code to reduce the frequency of making requests to D-Bus --- bumblebee/modules/battery-upower.py | 31 +++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/bumblebee/modules/battery-upower.py b/bumblebee/modules/battery-upower.py index 2e9aa13..24efecf 100644 --- a/bumblebee/modules/battery-upower.py +++ b/bumblebee/modules/battery-upower.py @@ -3,9 +3,9 @@ """Displays battery status, remaining percentage and charging information. Parameters: - * battery.warning : Warning threshold in % of remaining charge (defaults to 20) - * battery.critical : Critical threshold in % of remaining charge (defaults to 10) - * battery.showremaining : If set to true (default) shows the remaining time until the batteries are completely discharged + * battery-upower.warning : Warning threshold in % of remaining charge (defaults to 20) + * battery-upower.critical : Critical threshold in % of remaining charge (defaults to 10) + * battery-upower.showremaining : If set to true (default) shows the remaining time until the batteries are completely discharged """ import dbus @@ -204,9 +204,8 @@ class Module(bumblebee.engine.Module): engine.input.register_callback(self, button=bumblebee.input.LEFT_MOUSE, cmd="gnome-power-statistics") - def remaining(self): - estimate = int(self.power.get_full_device_information(self.device)['TimeToEmpty']) - return bumblebee.util.durationfmt(estimate, shorten=True, suffix=True) # estimate is in minutes + self._showremaining = bumblebee.util.asbool( + self.parameter("showremaining", True)) def capacity(self, widget): widget.set("capacity", -1) @@ -218,13 +217,25 @@ class Module(bumblebee.engine.Module): widget.set("capacity", capacity) output = "{}%".format(capacity) widget.set("theme.minwidth", "100%") - - if bumblebee.util.asbool(self.parameter("showremaining", True)) \ - and self.power.get_state(self.device) == "Discharging": - output = "{} {}".format(output, self.remaining()) except Exception as e: logging.exception("unable to get battery capacity: {}".format(str(e))) + if self._showremaining: + try: + p = self.power # an alias to make each line of code shorter + proxy = p.bus.get_object(p.UPOWER_NAME, self.device) + interface = dbus.Interface(proxy, p.DBUS_PROPERTIES) + state = int(interface.Get(p.UPOWER_NAME+".Device", "State")) + # state: 1 => charging, 2 => discharging, other => don't care + remain = int(interface.Get( + p.UPOWER_NAME+".Device", ["TimeToFull", "TimeToEmpty"][state-1])) + remain = bumblebee.util.durationfmt(remain, shorten=True, suffix=True) + output = "{} {}".format(output, remain) + except IndexError: + pass + except Exception as e: + logging.exception("unable to get battery remaining time: {}".format(str(e))) + return output def state(self, widget): From 9161d63c25de6a244507ed9686c10f6b5d44c43a Mon Sep 17 00:00:00 2001 From: Pi-Yueh Chuang Date: Thu, 19 Dec 2019 00:08:29 -0500 Subject: [PATCH 3/3] modify arch-update header to help displaying battery-upower help Modify the header of arch-update.py so that when using `bumblebee-status -l modules`, the content of arch-update and batter-upower will be separated (i.e., one more blank line between the doc of arch-update and battery-upower). --- bumblebee/modules/arch-update.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/bumblebee/modules/arch-update.py b/bumblebee/modules/arch-update.py index 116f0b6..faae680 100644 --- a/bumblebee/modules/arch-update.py +++ b/bumblebee/modules/arch-update.py @@ -1,4 +1,5 @@ -"""Check updates to Arch Linux.""" +"""Check updates to Arch Linux. +""" import subprocess