show charging status in device icon
This commit is contained in:
parent
39862034e1
commit
c61eb3f039
|
@ -34,6 +34,7 @@ ALERT = _NamedInts(NONE=0x00, NOTIFICATION=0x01, SHOW_WINDOW=0x02, ALL=0xFF)
|
||||||
ENCRYPTED='encrypted'
|
ENCRYPTED='encrypted'
|
||||||
BATTERY_LEVEL='battery-level'
|
BATTERY_LEVEL='battery-level'
|
||||||
BATTERY_STATUS='battery-status'
|
BATTERY_STATUS='battery-status'
|
||||||
|
BATTERY_CHARGING='battery-charging'
|
||||||
LIGHT_LEVEL='light-level'
|
LIGHT_LEVEL='light-level'
|
||||||
ERROR='error'
|
ERROR='error'
|
||||||
|
|
||||||
|
@ -142,16 +143,20 @@ class DeviceStatus(dict):
|
||||||
|
|
||||||
def set_battery_info(self, level, status, timestamp=None):
|
def set_battery_info(self, level, status, timestamp=None):
|
||||||
if _log.isEnabledFor(_DEBUG):
|
if _log.isEnabledFor(_DEBUG):
|
||||||
_log.debug("%s: battery %d%% charged, %s", self._device, level, status)
|
_log.debug("%s: battery %d%%, %s", self._device, level, status)
|
||||||
|
|
||||||
# TODO: this is also executed when pressing Fn+F7 on K800.
|
# TODO: this is also executed when pressing Fn+F7 on K800.
|
||||||
old_level, self[BATTERY_LEVEL] = self.get(BATTERY_LEVEL), level
|
old_level, self[BATTERY_LEVEL] = self.get(BATTERY_LEVEL), level
|
||||||
old_status, self[BATTERY_STATUS] = self.get(BATTERY_STATUS), status
|
old_status, self[BATTERY_STATUS] = self.get(BATTERY_STATUS), status
|
||||||
changed = old_level != level or old_status != status
|
|
||||||
|
charging = status in ('charging', 'recharging', 'slow recharge')
|
||||||
|
old_charging, self[BATTERY_CHARGING] = self.get(BATTERY_CHARGING), charging
|
||||||
|
|
||||||
|
changed = old_level != level or old_status != status or old_charging != charging
|
||||||
alert, reason = ALERT.NONE, None
|
alert, reason = ALERT.NONE, None
|
||||||
|
|
||||||
if not _hidpp20.BATTERY_OK(status) or level <= 5:
|
if not _hidpp20.BATTERY_OK(status) or level <= 5:
|
||||||
_log.warn("%s: battery %d%% charged, ALERT %s", self._device, level, status)
|
_log.warn("%s: battery %d%%, ALERT %s", self._device, level, status)
|
||||||
alert = ALERT.NOTIFICATION
|
alert = ALERT.NOTIFICATION
|
||||||
reason = 'Battery: %d%% (%s)' % (level, status)
|
reason = 'Battery: %d%% (%s)' % (level, status)
|
||||||
|
|
||||||
|
@ -376,11 +381,11 @@ class DeviceStatus(dict):
|
||||||
self[BATTERY_STATUS] = '%1.2fV' % (adc * 2.67793237653 / 0x0672)
|
self[BATTERY_STATUS] = '%1.2fV' % (adc * 2.67793237653 / 0x0672)
|
||||||
if n.address == 0x00:
|
if n.address == 0x00:
|
||||||
self[LIGHT_LEVEL] = None
|
self[LIGHT_LEVEL] = None
|
||||||
|
self[BATTERY_CHARGING] = None
|
||||||
self._changed()
|
self._changed()
|
||||||
elif n.address == 0x10:
|
elif n.address == 0x10:
|
||||||
self[LIGHT_LEVEL] = lux
|
self[LIGHT_LEVEL] = lux
|
||||||
if lux > 200: # guesstimate
|
self[BATTERY_CHARGING] = lux > 200
|
||||||
self[BATTERY_STATUS] += ', charging'
|
|
||||||
self._changed()
|
self._changed()
|
||||||
elif n.address == 0x20:
|
elif n.address == 0x20:
|
||||||
_log.debug("%s: Light Check button pressed", self._device)
|
_log.debug("%s: Light Check button pressed", self._device)
|
||||||
|
|
|
@ -50,27 +50,24 @@ def battery(level=None, charging=False):
|
||||||
return icon_name
|
return icon_name
|
||||||
|
|
||||||
def _battery_icon_name(level, charging):
|
def _battery_icon_name(level, charging):
|
||||||
level_approx = None if level is None else 20 * ((level + 10) // 20)
|
if level is None or level < 0:
|
||||||
|
return 'gpm-battery-missing' if _has_gpm_icons and _default_theme.has_icon('gpm-battery-missing') \
|
||||||
|
else 'battery-missing'
|
||||||
|
|
||||||
|
level_approx = 20 * ((level + 10) // 20)
|
||||||
|
|
||||||
if _has_gpm_icons:
|
if _has_gpm_icons:
|
||||||
if level is None or level < 0:
|
|
||||||
return 'gpm-battery-missing' if _default_theme.has_icon('gpm-battery-missing') \
|
|
||||||
else 'battery-missing'
|
|
||||||
if level == 100 and charging:
|
if level == 100 and charging:
|
||||||
return 'gpm-battery-charged'
|
return 'gpm-battery-charged'
|
||||||
return 'gpm-battery-%03d%s' % (level_approx, '-charging' if charging else '')
|
return 'gpm-battery-%03d%s' % (level_approx, '-charging' if charging else '')
|
||||||
|
|
||||||
if _has_oxygen_icons:
|
if _has_oxygen_icons:
|
||||||
if level is None or level < 0:
|
|
||||||
return 'battery-missing'
|
|
||||||
if level_approx == 100 and charging:
|
if level_approx == 100 and charging:
|
||||||
return 'battery-charging'
|
return 'battery-charging'
|
||||||
level_name = ('low', 'caution', '040', '060', '080', '100')[level_approx // 20]
|
level_name = ('low', 'caution', '040', '060', '080', '100')[level_approx // 20]
|
||||||
return 'battery%s-%s' % ('-charging' if charging else '', level_name)
|
return 'battery%s-%s' % ('-charging' if charging else '', level_name)
|
||||||
|
|
||||||
if _has_gnome_icons:
|
if _has_gnome_icons:
|
||||||
if level is None or level < 0:
|
|
||||||
return 'battery-missing'
|
|
||||||
if level == 100 and charging:
|
if level == 100 and charging:
|
||||||
return 'battery-full-charged'
|
return 'battery-full-charged'
|
||||||
if level_approx == 0 and charging:
|
if level_approx == 0 and charging:
|
||||||
|
|
|
@ -132,13 +132,13 @@ def _make_device_box(index):
|
||||||
label.set_padding(4, 0)
|
label.set_padding(4, 0)
|
||||||
frame._label = label
|
frame._label = label
|
||||||
|
|
||||||
battery_icon = Gtk.Image.new_from_icon_name(_icons.battery(-1), _STATUS_ICON_SIZE)
|
battery_icon = Gtk.Image.new_from_icon_name(_icons.battery(), _STATUS_ICON_SIZE)
|
||||||
|
|
||||||
battery_label = Gtk.Label()
|
battery_label = Gtk.Label()
|
||||||
battery_label.set_width_chars(6)
|
battery_label.set_width_chars(6)
|
||||||
battery_label.set_alignment(0, 0.5)
|
battery_label.set_alignment(0, 0.5)
|
||||||
|
|
||||||
light_icon = Gtk.Image.new_from_icon_name('light_unknown', _STATUS_ICON_SIZE)
|
light_icon = Gtk.Image.new_from_icon_name(_icons.lux(), _STATUS_ICON_SIZE)
|
||||||
|
|
||||||
light_label = Gtk.Label()
|
light_label = Gtk.Label()
|
||||||
light_label.set_alignment(0, 0.5)
|
light_label.set_alignment(0, 0.5)
|
||||||
|
@ -423,11 +423,12 @@ def _update_device_box(frame, dev):
|
||||||
|
|
||||||
if battery_level is None:
|
if battery_level is None:
|
||||||
battery_icon.set_sensitive(False)
|
battery_icon.set_sensitive(False)
|
||||||
battery_icon.set_from_icon_name(_icons.battery(None), _STATUS_ICON_SIZE)
|
battery_icon.set_from_icon_name(_icons.battery(), _STATUS_ICON_SIZE)
|
||||||
battery_label.set_markup('<small>no status</small>')
|
battery_label.set_markup('<small>no status</small>')
|
||||||
battery_label.set_sensitive(True)
|
battery_label.set_sensitive(True)
|
||||||
else:
|
else:
|
||||||
icon_name = _icons.battery(battery_level)
|
battery_charging = dev.status.get(_status.BATTERY_CHARGING)
|
||||||
|
icon_name = _icons.battery(battery_level, battery_charging)
|
||||||
battery_icon.set_from_icon_name(icon_name, _STATUS_ICON_SIZE)
|
battery_icon.set_from_icon_name(icon_name, _STATUS_ICON_SIZE)
|
||||||
battery_icon.set_sensitive(True)
|
battery_icon.set_sensitive(True)
|
||||||
battery_label.set_text('%d%%' % battery_level)
|
battery_label.set_text('%d%%' % battery_level)
|
||||||
|
|
|
@ -138,8 +138,11 @@ def _generate_image(icon):
|
||||||
if battery_status is None:
|
if battery_status is None:
|
||||||
return _icons.APP_ICON[1]
|
return _icons.APP_ICON[1]
|
||||||
else:
|
else:
|
||||||
charging = battery_status.get(_status.BATTERY_CHARGING)
|
charging = bool(battery_status.get(_status.BATTERY_CHARGING))
|
||||||
return _icons.battery(battery_level, charging) or _icons.APP_ICON[1]
|
icon_name = _icons.battery(battery_level, charging)
|
||||||
|
if icon_name and 'missing' in icon_name:
|
||||||
|
icon_name = None
|
||||||
|
return icon_name or _icons.APP_ICON[1]
|
||||||
|
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
|
|
Loading…
Reference in New Issue