fast mapping of receiver status to app icon name
This commit is contained in:
parent
893c7e3ab2
commit
ff5a1ac7cb
|
@ -14,11 +14,7 @@ Gtk.IconSize.LARGE = Gtk.icon_size_register('large', _LARGE_SIZE, _LARGE_SIZE)
|
|||
from . import notify, status_icon, main_window, pair_window, action
|
||||
|
||||
from solaar import NAME
|
||||
_APP_ICONS = (NAME + '-init', NAME + '-fail', NAME)
|
||||
def appicon(receiver_status):
|
||||
return (_APP_ICONS[1] if isinstance(receiver_status, basestring)
|
||||
else _APP_ICONS[2] if receiver_status
|
||||
else _APP_ICONS[0])
|
||||
APP_ICON = { 1: NAME, 2: NAME + '-mask', 0: NAME + '-init', -1: NAME + '-fail' }
|
||||
|
||||
|
||||
def get_battery_icon(level):
|
||||
|
|
|
@ -243,7 +243,7 @@ def _make_device_box(index):
|
|||
def create(title, name, max_devices, systray=False):
|
||||
window = Gtk.Window()
|
||||
window.set_title(title)
|
||||
window.set_icon_name(ui.appicon(0))
|
||||
window.set_icon_name(ui.APP_ICON[0])
|
||||
window.set_role('status-window')
|
||||
|
||||
vbox = Gtk.VBox(homogeneous=False, spacing=12)
|
||||
|
@ -417,8 +417,8 @@ def _update_device_box(frame, dev):
|
|||
|
||||
def update(window, receiver, device=None):
|
||||
assert receiver is not None
|
||||
# print ("update %s %s, %s" % (receiver, receiver.status, device))
|
||||
window.set_icon_name(ui.appicon(receiver.status))
|
||||
# print ("update", receiver, receiver.status, len(receiver), device)
|
||||
window.set_icon_name(ui.APP_ICON[1 if receiver else -1])
|
||||
|
||||
vbox = window.get_child()
|
||||
frames = list(vbox.get_children())
|
||||
|
|
|
@ -20,7 +20,7 @@ def create(window, menu_actions=None):
|
|||
icon = Gtk.StatusIcon()
|
||||
icon.set_title(name)
|
||||
icon.set_name(name)
|
||||
icon.set_from_icon_name(ui.appicon(False))
|
||||
icon.set_from_icon_name(ui.APP_ICON[0])
|
||||
icon._devices = list(_NO_DEVICES)
|
||||
|
||||
icon.set_tooltip_text(name)
|
||||
|
@ -55,7 +55,7 @@ def _icon_with_battery(s):
|
|||
|
||||
name = '%s-%s' % (battery_icon, bool(s))
|
||||
if name not in _PIXMAPS:
|
||||
mask = ui.icon_file(ui.appicon(True) + '-mask', 128)
|
||||
mask = ui.icon_file(ui.APP_ICON[2], 128)
|
||||
assert mask
|
||||
mask = GdkPixbuf.Pixbuf.new_from_file(mask)
|
||||
assert mask.get_width() == 128 and mask.get_height() == 128
|
||||
|
@ -112,6 +112,6 @@ def update(icon, receiver, device=None):
|
|||
icon.set_tooltip_markup('\n'.join(lines).rstrip('\n'))
|
||||
|
||||
if battery_status is None:
|
||||
icon.set_from_icon_name(ui.appicon(receiver.status))
|
||||
icon.set_from_icon_name(ui.APP_ICON[1 if receiver else -1])
|
||||
else:
|
||||
icon.set_from_pixbuf(_icon_with_battery(battery_status))
|
||||
|
|
Loading…
Reference in New Issue