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