fixed initialization sequence for newly detected devices

This commit is contained in:
Daniel Pavel 2012-11-11 20:11:30 +02:00
parent 50fedab19e
commit bcc2bf123e
3 changed files with 14 additions and 8 deletions

View File

@ -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

View File

@ -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 = '<b>' + dev.name + '</b>'
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:

View File

@ -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."""