more fixes for device unpairing

This commit is contained in:
Daniel Pavel 2013-06-19 17:21:28 +02:00
parent d5b311760e
commit 7e1a2a6e4f
3 changed files with 14 additions and 13 deletions

View File

@ -41,12 +41,12 @@ def _parse_arguments():
def _run(args): def _run(args):
import solaar.ui as ui import solaar.ui as ui
ui.init()
import solaar.listener as listener import solaar.listener as listener
listener.start_scanner(ui.status_changed, ui.error_dialog) listener.start_scanner(ui.status_changed, ui.error_dialog)
# main UI event loop # main UI event loop
ui.init()
ui.run_loop() ui.run_loop()
ui.destroy() ui.destroy()

View File

@ -439,9 +439,9 @@ def update(device=None):
if device is not None: if device is not None:
if device.kind is None: if device.kind is None:
# receiver # receiver
receiver = device is_alive = bool(device)
receiver_path = receiver.path receiver_path = device.path
if receiver: if is_alive:
index = None index = None
for idx, (path, _, _, _, _) in enumerate(_devices_info): for idx, (path, _, _, _, _) in enumerate(_devices_info):
if path == receiver_path: if path == receiver_path:
@ -449,26 +449,27 @@ def update(device=None):
break break
if index is None: if index is None:
_add_receiver(receiver) _add_receiver(device)
else: else:
_remove_receiver(receiver) _remove_receiver(device)
else: else:
receiver_path = device.receiver.path
# peripheral # peripheral
is_alive = device.status is not None
receiver_path = device.receiver.path
index = None index = None
for idx, (path, serial, name, _, _) in enumerate(_devices_info): for idx, (path, serial, name, _, _) in enumerate(_devices_info):
if path == receiver_path and serial == device.serial: if path == receiver_path and serial == device.serial:
index = idx index = idx
if device.status is None: if is_alive:
# was just unpaired
assert index is not None
_remove_device(index)
else:
if index is None: if index is None:
index = _add_device(device) index = _add_device(device)
_update_menu_item(index, device.status) _update_menu_item(index, device.status)
else:
# was just unpaired
if index:
_remove_device(index)
menu_items = _menu.get_children() menu_items = _menu.get_children()
no_receivers_index = len(_devices_info) no_receivers_index = len(_devices_info)

View File

@ -685,7 +685,7 @@ def update(device, need_popup=False):
elif item: elif item:
_model.remove(item) _model.remove(item)
_config_panel.clean(device.path) _config_panel.clean(device.serial)
# make sure all rows are visible # make sure all rows are visible
_tree.expand_all() _tree.expand_all()