show battery icon in tray if any available
|
|
@ -19,6 +19,9 @@ _ICON_THEME = Gtk.IconTheme.get_default()
|
||||||
def get_icon(name, fallback):
|
def get_icon(name, fallback):
|
||||||
return name if name and _ICON_THEME.has_icon(name) else 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):
|
def icon_file(name):
|
||||||
if name and _ICON_THEME.has_icon(name):
|
if name and _ICON_THEME.has_icon(name):
|
||||||
return _ICON_THEME.lookup_icon(name, 0, 0).get_filename()
|
return _ICON_THEME.lookup_icon(name, 0, 0).get_filename()
|
||||||
|
|
|
||||||
|
|
@ -272,6 +272,8 @@ def _update_device_box(frame, dev):
|
||||||
status_icons = status.get_children()
|
status_icons = status.get_children()
|
||||||
|
|
||||||
if dev.status < STATUS.CONNECTED:
|
if dev.status < STATUS.CONNECTED:
|
||||||
|
label.set_sensitive(True)
|
||||||
|
|
||||||
battery_icon, battery_label = status_icons[0:2]
|
battery_icon, battery_label = status_icons[0:2]
|
||||||
battery_icon.set_sensitive(False)
|
battery_icon.set_sensitive(False)
|
||||||
battery_label.set_markup('<small>%s</small>' % dev.status_text)
|
battery_label.set_markup('<small>%s</small>' % dev.status_text)
|
||||||
|
|
@ -280,6 +282,8 @@ def _update_device_box(frame, dev):
|
||||||
c.set_visible(False)
|
c.set_visible(False)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
|
label.set_sensitive(True)
|
||||||
|
|
||||||
battery_icon, battery_label = status_icons[0:2]
|
battery_icon, battery_label = status_icons[0:2]
|
||||||
battery_level = dev.props.get(PROPS.BATTERY_LEVEL)
|
battery_level = dev.props.get(PROPS.BATTERY_LEVEL)
|
||||||
if battery_level is None:
|
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_markup('<small>%s</small>' % text)
|
||||||
battery_label.set_sensitive(False)
|
battery_label.set_sensitive(False)
|
||||||
else:
|
else:
|
||||||
icon_name = 'battery_%03d' % (20 * ((battery_level + 10) // 20))
|
battery_icon.set_from_icon_name(ui.get_battery_icon(battery_level), _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)
|
||||||
battery_label.set_sensitive(True)
|
battery_label.set_sensitive(True)
|
||||||
|
|
|
||||||
|
|
@ -32,17 +32,14 @@ def create(window, menu_actions=None):
|
||||||
|
|
||||||
|
|
||||||
def update(icon, receiver):
|
def update(icon, receiver):
|
||||||
icon.set_from_icon_name(ui.appicon(receiver.status))
|
battery_level = None
|
||||||
|
|
||||||
# device_with_battery = None
|
if receiver.status > STATUS.CONNECTED and receiver.devices:
|
||||||
|
|
||||||
if receiver.devices:
|
|
||||||
lines = []
|
lines = []
|
||||||
if receiver.status < STATUS.CONNECTED:
|
if receiver.status < STATUS.CONNECTED:
|
||||||
lines += (receiver.status_text, '')
|
lines += (receiver.status_text, '')
|
||||||
|
|
||||||
devlist = list(receiver.devices.values())
|
devlist = sorted(receiver.devices.values(), key=lambda x: x.number)
|
||||||
devlist.sort(lambda x, y: x.number < y.number)
|
|
||||||
for dev in devlist:
|
for dev in devlist:
|
||||||
name = '<b>' + dev.name + '</b>'
|
name = '<b>' + dev.name + '</b>'
|
||||||
if dev.status < STATUS.CONNECTED:
|
if dev.status < STATUS.CONNECTED:
|
||||||
|
|
@ -53,10 +50,15 @@ def update(icon, receiver):
|
||||||
lines.append(' ' + dev.status_text)
|
lines.append(' ' + dev.status_text)
|
||||||
lines.append('')
|
lines.append('')
|
||||||
|
|
||||||
# if device_with_battery is None and PROPS.BATTERY_LEVEL in dev.props:
|
if battery_level is None and PROPS.BATTERY_LEVEL in dev.props:
|
||||||
# device_with_battery = dev
|
battery_level = dev.props[PROPS.BATTERY_LEVEL]
|
||||||
|
|
||||||
text = '\n'.join(lines).rstrip('\n')
|
text = '\n'.join(lines).rstrip('\n')
|
||||||
icon.set_tooltip_markup(ui.NAME + ':\n' + text)
|
icon.set_tooltip_markup(ui.NAME + ':\n' + text)
|
||||||
else:
|
else:
|
||||||
icon.set_tooltip_text(ui.NAME + ': ' + receiver.status_text)
|
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))
|
||||||
|
|
|
||||||
|
Before Width: | Height: | Size: 7.9 KiB After Width: | Height: | Size: 7.9 KiB |
|
After Width: | Height: | Size: 7.6 KiB |
|
After Width: | Height: | Size: 7.0 KiB |
|
Before Width: | Height: | Size: 7.0 KiB After Width: | Height: | Size: 7.4 KiB |
|
After Width: | Height: | Size: 7.3 KiB |
|
After Width: | Height: | Size: 8.3 KiB |
|
After Width: | Height: | Size: 8.4 KiB |