ui: don't include separator after receiver in tray menu

This commit is contained in:
Peter F. Patel-Schneider 2021-11-24 12:11:57 -05:00
parent c515de9b09
commit 07e55c188a
1 changed files with 4 additions and 24 deletions

View File

@ -44,7 +44,6 @@ del getLogger
_TRAY_ICON_SIZE = 48 _TRAY_ICON_SIZE = 48
_MENU_ICON_SIZE = Gtk.IconSize.LARGE_TOOLBAR _MENU_ICON_SIZE = Gtk.IconSize.LARGE_TOOLBAR
_RECEIVER_SEPARATOR = ('~', None, None, None)
# #
# #
@ -56,7 +55,7 @@ def _create_menu(quit_handler):
# per-device menu entries will be generated as-needed # per-device menu entries will be generated as-needed
no_receiver = Gtk.MenuItem.new_with_label(_('No Logitech receiver found')) no_receiver = Gtk.MenuItem.new_with_label(_('No Logitech device found'))
no_receiver.set_sensitive(False) no_receiver.set_sensitive(False)
menu.append(no_receiver) menu.append(no_receiver)
menu.append(Gtk.SeparatorMenuItem.new()) menu.append(Gtk.SeparatorMenuItem.new())
@ -87,7 +86,7 @@ def _scroll(tray_icon, event, direction=None):
if len(_devices_info) < 4: if len(_devices_info) < 4:
# don't bother with scrolling when there's only one receiver # don't bother with scrolling when there's only one receiver
# with only one device (3 = [receiver, device, separator]) # with only one or two devices
return return
# scroll events come way too fast (at least 5-6 at once) # scroll events come way too fast (at least 5-6 at once)
@ -334,7 +333,7 @@ def _pick_device_with_lowest_battery():
picked_level = 1000 picked_level = 1000
for info in _devices_info: for info in _devices_info:
if info[1] is None: # is receiver/separator if info[1] is None: # is receiver
continue continue
level = info[-1].get(_K.BATTERY_LEVEL) level = info[-1].get(_K.BATTERY_LEVEL)
# print ("checking %s -> %s", info, level) # print ("checking %s -> %s", info, level)
@ -353,13 +352,6 @@ def _pick_device_with_lowest_battery():
# #
def _add_separator(index):
_devices_info.insert(index + 1, _RECEIVER_SEPARATOR)
separator = Gtk.SeparatorMenuItem.new()
separator.set_visible(True)
_menu.insert(separator, index + 1)
def _add_device(device): def _add_device(device):
assert device assert device
@ -372,7 +364,7 @@ def _add_device(device):
break break
while index < len(_devices_info): while index < len(_devices_info):
path, number, _ignore, _ignore = _devices_info[index] path, number, _ignore, _ignore = _devices_info[index]
if path == _RECEIVER_SEPARATOR[0]: if not path == receiver_path:
break break
assert number != device.number assert number != device.number
if number > device.number: if number > device.number:
@ -380,7 +372,6 @@ def _add_device(device):
index = index + 1 index = index + 1
new_device_info = (receiver_path, device.number, device.name, device.status) new_device_info = (receiver_path, device.number, device.name, device.status)
assert len(new_device_info) == len(_RECEIVER_SEPARATOR)
_devices_info.insert(index, new_device_info) _devices_info.insert(index, new_device_info)
label_prefix = ' ' label_prefix = ' '
@ -410,7 +401,6 @@ def _add_receiver(receiver):
index = len(_devices_info) index = len(_devices_info)
new_receiver_info = (receiver.path, None, receiver.name, None) new_receiver_info = (receiver.path, None, receiver.name, None)
assert len(new_receiver_info) == len(_RECEIVER_SEPARATOR)
_devices_info.insert(index, new_receiver_info) _devices_info.insert(index, new_receiver_info)
new_menu_item = Gtk.ImageMenuItem.new_with_label(receiver.name) new_menu_item = Gtk.ImageMenuItem.new_with_label(receiver.name)
@ -420,25 +410,16 @@ def _add_receiver(receiver):
new_menu_item.connect('activate', _window_popup, receiver.path) new_menu_item.connect('activate', _window_popup, receiver.path)
_menu.insert(new_menu_item, index) _menu.insert(new_menu_item, index)
_add_separator(index)
return 0 return 0
def _remove_receiver(receiver): def _remove_receiver(receiver):
index = 0 index = 0
found = False
# remove all entries in devices_info that match this receiver # remove all entries in devices_info that match this receiver
while index < len(_devices_info): while index < len(_devices_info):
path, _ignore, _ignore, _ignore = _devices_info[index] path, _ignore, _ignore, _ignore = _devices_info[index]
if path == receiver.path: if path == receiver.path:
found = True
_remove_device(index) _remove_device(index)
elif found and path == _RECEIVER_SEPARATOR[0]:
# the separator after this receiver
_remove_device(index)
break
else: else:
index += 1 index += 1
@ -537,7 +518,6 @@ def update(device=None):
menu_items = _menu.get_children() menu_items = _menu.get_children()
no_receivers_index = len(_devices_info) no_receivers_index = len(_devices_info)
menu_items[no_receivers_index].set_visible(not _devices_info) menu_items[no_receivers_index].set_visible(not _devices_info)
menu_items[no_receivers_index + 1].set_visible(not _devices_info)
global _picked_device global _picked_device
if (not _picked_device or _last_scroll == 0) and device is not None and device.kind is not None: if (not _picked_device or _last_scroll == 0) and device is not None and device.kind is not None: