faster tooltip text composition
This commit is contained in:
parent
ff5a1ac7cb
commit
a370afe94b
|
@ -43,17 +43,19 @@ def create(window, menu_actions=None):
|
||||||
def _size_changed(i, size, w):
|
def _size_changed(i, size, w):
|
||||||
def _check_systray(i2, w2):
|
def _check_systray(i2, w2):
|
||||||
w2.set_has_systray(i2.is_embedded() and i2.get_visible())
|
w2.set_has_systray(i2.is_embedded() and i2.get_visible())
|
||||||
|
# first guess
|
||||||
GObject.timeout_add(250, _check_systray, i, w)
|
GObject.timeout_add(250, _check_systray, i, w)
|
||||||
|
# just to make sure...
|
||||||
|
GObject.timeout_add(1000, _check_systray, i, w)
|
||||||
icon.connect('size-changed', _size_changed, window)
|
icon.connect('size-changed', _size_changed, window)
|
||||||
|
|
||||||
return icon
|
return icon
|
||||||
|
|
||||||
|
|
||||||
_PIXMAPS = {}
|
_PIXMAPS = {}
|
||||||
def _icon_with_battery(s):
|
def _icon_with_battery(level, active):
|
||||||
battery_icon = ui.get_battery_icon(s[_status.BATTERY_LEVEL])
|
battery_icon = ui.get_battery_icon(level)
|
||||||
|
name = '%s-%s' % (battery_icon, active)
|
||||||
name = '%s-%s' % (battery_icon, bool(s))
|
|
||||||
if name not in _PIXMAPS:
|
if name not in _PIXMAPS:
|
||||||
mask = ui.icon_file(ui.APP_ICON[2], 128)
|
mask = ui.icon_file(ui.APP_ICON[2], 128)
|
||||||
assert mask
|
assert mask
|
||||||
|
@ -65,7 +67,7 @@ def _icon_with_battery(s):
|
||||||
assert battery
|
assert battery
|
||||||
battery = GdkPixbuf.Pixbuf.new_from_file(battery)
|
battery = GdkPixbuf.Pixbuf.new_from_file(battery)
|
||||||
assert battery.get_width() == 128 and battery.get_height() == 128
|
assert battery.get_width() == 128 and battery.get_height() == 128
|
||||||
if not s:
|
if not active:
|
||||||
battery.saturate_and_pixelate(battery, 0, True)
|
battery.saturate_and_pixelate(battery, 0, True)
|
||||||
|
|
||||||
# TODO can the masking be done at runtime?
|
# TODO can the masking be done at runtime?
|
||||||
|
@ -76,8 +78,6 @@ def _icon_with_battery(s):
|
||||||
|
|
||||||
def update(icon, receiver, device=None):
|
def update(icon, receiver, device=None):
|
||||||
# print ("icon update", receiver, receiver.status, len(receiver), device)
|
# print ("icon update", receiver, receiver.status, len(receiver), device)
|
||||||
battery_status = None
|
|
||||||
|
|
||||||
if device:
|
if device:
|
||||||
icon._devices[device.number] = None if device.status is None else device
|
icon._devices[device.number] = None if device.status is None else device
|
||||||
if not receiver:
|
if not receiver:
|
||||||
|
@ -85,33 +85,42 @@ def update(icon, receiver, device=None):
|
||||||
if not icon.is_embedded():
|
if not icon.is_embedded():
|
||||||
return
|
return
|
||||||
|
|
||||||
lines = [ui.NAME + ': ' + str(receiver.status), '']
|
def _lines(r, devices):
|
||||||
for dev in icon._devices:
|
yield '<b>%s</b>: %s' % (ui.NAME, r.status)
|
||||||
if dev is None:
|
yield ''
|
||||||
continue
|
|
||||||
|
|
||||||
lines.append('<b>' + dev.name + '</b>')
|
for dev in devices:
|
||||||
|
if dev is None:
|
||||||
|
continue
|
||||||
|
|
||||||
assert hasattr(dev, 'status') and dev.status is not None
|
yield '<b>%s</b>' % dev.name
|
||||||
p = str(dev.status)
|
|
||||||
if p:
|
assert hasattr(dev, 'status') and dev.status is not None
|
||||||
if not dev.status:
|
p = str(dev.status)
|
||||||
p += ' <small>(inactive)</small>'
|
if p: # does it have any properties to print?
|
||||||
else:
|
if dev.status:
|
||||||
if dev.status:
|
yield '\t%s' % p
|
||||||
p = '<small>no status</small>'
|
else:
|
||||||
|
yield '\t%s <small>(inactive)</small>' % p
|
||||||
else:
|
else:
|
||||||
p = '<small>(inactive)</small>'
|
if dev.status:
|
||||||
|
yield '\t<small>no status</small>'
|
||||||
|
else:
|
||||||
|
yield '\t<small>(inactive)</small>'
|
||||||
|
yield ''
|
||||||
|
|
||||||
lines.append('\t' + p)
|
icon.set_tooltip_markup('\n'.join(_lines(receiver, icon._devices)).rstrip('\n'))
|
||||||
lines.append('')
|
|
||||||
|
|
||||||
if battery_status is None and dev.status.get(_status.BATTERY_LEVEL):
|
battery_status = None
|
||||||
battery_status = dev.status
|
battery_level = 1000
|
||||||
|
for dev in icon._devices:
|
||||||
icon.set_tooltip_markup('\n'.join(lines).rstrip('\n'))
|
if dev is not None:
|
||||||
|
level = dev.status.get(_status.BATTERY_LEVEL)
|
||||||
|
if level is not None and level < battery_level:
|
||||||
|
battery_status = dev.status
|
||||||
|
battery_level = level
|
||||||
|
|
||||||
if battery_status is None:
|
if battery_status is None:
|
||||||
icon.set_from_icon_name(ui.APP_ICON[1 if receiver else -1])
|
icon.set_from_icon_name(ui.APP_ICON[1 if receiver else -1])
|
||||||
else:
|
else:
|
||||||
icon.set_from_pixbuf(_icon_with_battery(battery_status))
|
icon.set_from_pixbuf(_icon_with_battery(battery_level, bool(battery_status)))
|
||||||
|
|
Loading…
Reference in New Issue