From bcc2bf123eebf8d908d19c7a4416405214698709 Mon Sep 17 00:00:00 2001 From: Daniel Pavel Date: Sun, 11 Nov 2012 20:11:30 +0200 Subject: [PATCH] fixed initialization sequence for newly detected devices --- app/receiver.py | 4 ++-- app/ui/status_icon.py | 15 +++++++++++---- lib/logitech/unifying_receiver/constants.py | 3 +-- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/app/receiver.py b/app/receiver.py index 0aaf0236..9924cbdb 100644 --- a/app/receiver.py +++ b/app/receiver.py @@ -307,12 +307,12 @@ class ReceiverListener(_EventsListener): dev = DeviceInfo(self.handle, event.devnumber, status, self.status_changed) self.LOG.info("new device %s", dev) - self.receiver.devices[event.devnumber] = dev - self.change_status(STATUS.CONNECTED + len(self.receiver.devices)) + self.change_status(STATUS.CONNECTED + 1 + len(self.receiver.devices)) if status == STATUS.CONNECTED: dev.protocol, dev.name, dev.kind self.status_changed(dev, STATUS.UI_NOTIFY) + self.receiver.devices[event.devnumber] = dev if status == STATUS.CONNECTED: dev.serial, dev.firmware return dev diff --git a/app/ui/status_icon.py b/app/ui/status_icon.py index 869218b1..889998f1 100644 --- a/app/ui/status_icon.py +++ b/app/ui/status_icon.py @@ -4,6 +4,7 @@ from gi.repository import Gtk import ui +from logitech.devices.constants import (STATUS, PROPS) def create(window, menu_actions=None): @@ -33,22 +34,28 @@ def create(window, menu_actions=None): def update(icon, receiver): icon.set_from_icon_name(ui.appicon(receiver.status)) + # device_with_battery = None + if receiver.devices: lines = [] - if receiver.status < 1: + if receiver.status < STATUS.CONNECTED: lines += (receiver.status_text, '') - devlist = [receiver.devices[d] for d in range(1, 1 + receiver.max_devices) if d in receiver.devices] + devlist = list(receiver.devices.values()) + devlist.sort(lambda x, y: x.number < y.number) for dev in devlist: name = '' + dev.name + '' - if dev.status < 1: + if dev.status < STATUS.CONNECTED: lines.append(name + ' (' + dev.status_text + ')') else: lines.append(name) - if dev.status > 1: + if dev.status > STATUS.CONNECTED: lines.append(' ' + dev.status_text) lines.append('') + # if device_with_battery is None and PROPS.BATTERY_LEVEL in dev.props: + # device_with_battery = dev + text = '\n'.join(lines).rstrip('\n') icon.set_tooltip_markup(ui.NAME + ':\n' + text) else: diff --git a/lib/logitech/unifying_receiver/constants.py b/lib/logitech/unifying_receiver/constants.py index 83803365..cce5c6e9 100644 --- a/lib/logitech/unifying_receiver/constants.py +++ b/lib/logitech/unifying_receiver/constants.py @@ -63,8 +63,7 @@ FIRMWARE_KIND = FallbackDict(lambda x: 'Unknown', list2dict(_FIRMWARE_KINDS)) _BATTERY_STATUSES = ('Discharging (in use)', 'Recharging', 'Almost full', - 'Full', 'Slow recharge', 'Invalid battery', 'Thermal error', - 'Charging error') + 'Full', 'Slow recharge', 'Invalid battery', 'Thermal error') BATTERY_OK = lambda status: status < 5 """Names for possible battery status values."""