show battery icon in tray if any available

This commit is contained in:
Daniel Pavel 2012-11-11 21:59:50 +02:00
parent bcc2bf123e
commit 2c312c1a5b
10 changed files with 18 additions and 10 deletions

View File

@ -19,6 +19,9 @@ _ICON_THEME = Gtk.IconTheme.get_default()
def get_icon(name, fallback):
return name if name and _ICON_THEME.has_icon(name) else fallback
def get_battery_icon(level):
return 'battery_%03d' % (10 * ((level + 5) // 10))
def icon_file(name):
if name and _ICON_THEME.has_icon(name):
return _ICON_THEME.lookup_icon(name, 0, 0).get_filename()

View File

@ -272,6 +272,8 @@ def _update_device_box(frame, dev):
status_icons = status.get_children()
if dev.status < STATUS.CONNECTED:
label.set_sensitive(True)
battery_icon, battery_label = status_icons[0:2]
battery_icon.set_sensitive(False)
battery_label.set_markup('<small>%s</small>' % dev.status_text)
@ -280,6 +282,8 @@ def _update_device_box(frame, dev):
c.set_visible(False)
else:
label.set_sensitive(True)
battery_icon, battery_label = status_icons[0:2]
battery_level = dev.props.get(PROPS.BATTERY_LEVEL)
if battery_level is None:
@ -289,8 +293,7 @@ def _update_device_box(frame, dev):
battery_label.set_markup('<small>%s</small>' % text)
battery_label.set_sensitive(False)
else:
icon_name = 'battery_%03d' % (20 * ((battery_level + 10) // 20))
battery_icon.set_from_icon_name(icon_name, _STATUS_ICON_SIZE)
battery_icon.set_from_icon_name(ui.get_battery_icon(battery_level), _STATUS_ICON_SIZE)
battery_icon.set_sensitive(True)
battery_label.set_text('%d%%' % battery_level)
battery_label.set_sensitive(True)

View File

@ -32,17 +32,14 @@ def create(window, menu_actions=None):
def update(icon, receiver):
icon.set_from_icon_name(ui.appicon(receiver.status))
battery_level = None
# device_with_battery = None
if receiver.devices:
if receiver.status > STATUS.CONNECTED and receiver.devices:
lines = []
if receiver.status < STATUS.CONNECTED:
lines += (receiver.status_text, '')
devlist = list(receiver.devices.values())
devlist.sort(lambda x, y: x.number < y.number)
devlist = sorted(receiver.devices.values(), key=lambda x: x.number)
for dev in devlist:
name = '<b>' + dev.name + '</b>'
if dev.status < STATUS.CONNECTED:
@ -53,10 +50,15 @@ def update(icon, receiver):
lines.append(' ' + dev.status_text)
lines.append('')
# if device_with_battery is None and PROPS.BATTERY_LEVEL in dev.props:
# device_with_battery = dev
if battery_level is None and PROPS.BATTERY_LEVEL in dev.props:
battery_level = dev.props[PROPS.BATTERY_LEVEL]
text = '\n'.join(lines).rstrip('\n')
icon.set_tooltip_markup(ui.NAME + ':\n' + text)
else:
icon.set_tooltip_text(ui.NAME + ': ' + receiver.status_text)
if battery_level is None:
icon.set_from_icon_name(ui.appicon(receiver.status))
else:
icon.set_from_icon_name(ui.get_battery_icon(battery_level))

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.9 KiB

After

Width:  |  Height:  |  Size: 7.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.0 KiB

After

Width:  |  Height:  |  Size: 7.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.4 KiB