From f64942b51de767e2604895499873712cc0fc0416 Mon Sep 17 00:00:00 2001 From: Daniel Pavel Date: Mon, 24 Jun 2013 17:02:00 +0200 Subject: [PATCH] if the battery level is approximative, show a string instead of percentage --- lib/logitech/unifying_receiver/status.py | 11 ++++++++--- lib/solaar/ui/window.py | 9 ++++++--- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/lib/logitech/unifying_receiver/status.py b/lib/logitech/unifying_receiver/status.py index ff8bd150..ce3577aa 100644 --- a/lib/logitech/unifying_receiver/status.py +++ b/lib/logitech/unifying_receiver/status.py @@ -20,7 +20,7 @@ from logging import getLogger, DEBUG as _DEBUG _log = getLogger('LUR.status') del getLogger -from .common import NamedInts as _NamedInts, strhex as _strhex +from .common import NamedInts as _NamedInts, NamedInt as _NamedInt, strhex as _strhex from . import hidpp10 as _hidpp10 from . import hidpp20 as _hidpp20 @@ -146,6 +146,7 @@ class DeviceStatus(dict): return format % value def _items(): + # TODO properly string approximative battery levels battery_level = _item(KEYS.BATTERY_LEVEL, 'Battery: %d%%') if battery_level: yield battery_level @@ -168,8 +169,9 @@ class DeviceStatus(dict): __nonzero__ = __bool__ def set_battery_info(self, level, status, timestamp=None): + assert isinstance(level, int) if _log.isEnabledFor(_DEBUG): - _log.debug("%s: battery %d%%, %s", self._device, level, status) + _log.debug("%s: battery %s, %s", self._device, level, status) # TODO: this is also executed when pressing Fn+F7 on K800. old_level, self[KEYS.BATTERY_LEVEL] = self.get(KEYS.BATTERY_LEVEL), level @@ -184,7 +186,10 @@ class DeviceStatus(dict): if not _hidpp20.BATTERY_OK(status) or level <= _BATTERY_ATTENTION_LEVEL: _log.warn("%s: battery %d%%, ALERT %s", self._device, level, status) alert = ALERT.NOTIFICATION | ALERT.ATTENTION - reason = 'Battery: %d%% (%s)' % (level, status) + if isinstance(level, _NamedInt): + reason = 'battery: %s (%s)' % (level, status) + else: + reason = 'battery: %d%% (%s)' % (level, status) if changed or reason: # update the leds on the device, if any diff --git a/lib/solaar/ui/window.py b/lib/solaar/ui/window.py index 1ac30118..cb242650 100644 --- a/lib/solaar/ui/window.py +++ b/lib/solaar/ui/window.py @@ -8,13 +8,13 @@ from logging import getLogger, DEBUG as _DEBUG _log = getLogger(__name__) del getLogger -from gi.repository import Gtk, Gdk, GLib +from gi.repository import Gtk, Gdk from gi.repository.GObject import TYPE_PYOBJECT from solaar import NAME # from solaar import __version__ as VERSION from logitech.unifying_receiver import hidpp10 as _hidpp10 -from logitech.unifying_receiver.common import NamedInts as _NamedInts +from logitech.unifying_receiver.common import NamedInts as _NamedInts, NamedInt as _NamedInt from logitech.unifying_receiver.status import KEYS as _K from . import config_panel as _config_panel from . import action as _action, icons as _icons @@ -552,7 +552,10 @@ def _update_device_panel(device, panel, buttons, full=False): panel._battery._icon.set_from_icon_name(icon_name, _INFO_ICON_SIZE) panel._battery._icon.set_sensitive(True) - text = '%d%%' % battery_level + if isinstance(battery_level, _NamedInt): + text = str(battery_level) + else: + text = '%d%%' % battery_level if is_online: if charging: text += ' (charging)'