From 0d14781463b7ffcffc2ce58db3020aee1bb02f08 Mon Sep 17 00:00:00 2001 From: Neil Booth Date: Thu, 21 Jan 2016 23:33:15 +0900 Subject: [PATCH] Trezor: GUI fixes Trezor window was doing GUI stuff outside the GUI thread --- lib/plugins.py | 10 ++++++++++ plugins/trezor/plugin.py | 3 ++- plugins/trezor/qt_generic.py | 4 ++-- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/lib/plugins.py b/lib/plugins.py index 97698a3a..a87e82db 100644 --- a/lib/plugins.py +++ b/lib/plugins.py @@ -281,6 +281,10 @@ class DeviceMgr(PrintError): self.recognised_hardware.add(pair) def create_client(self, device, handler, plugin): + # Get from cache first + client = self.client_lookup(device.id_) + if client: + return client client = plugin.create_client(device, handler) if client: self.print_error("Registering", client) @@ -301,6 +305,8 @@ class DeviceMgr(PrintError): def unpair_wallet(self, wallet): with self.lock: + if not wallet in self.wallets: + return wallet_id = self.wallets.pop(wallet) client = self.client_lookup(wallet_id) self.clients.pop(client, None) @@ -322,6 +328,10 @@ class DeviceMgr(PrintError): def paired_wallets(self): return list(self.wallets.keys()) + def unpaired_devices(self, handler): + devices = self.scan_devices(handler) + return [dev for dev in devices if not self.wallet_by_id(dev.id_)] + def client_lookup(self, id_): with self.lock: for client, (path, client_id) in self.clients.items(): diff --git a/plugins/trezor/plugin.py b/plugins/trezor/plugin.py index fe90a77e..54d5fb91 100644 --- a/plugins/trezor/plugin.py +++ b/plugins/trezor/plugin.py @@ -314,13 +314,14 @@ class TrezorCompatiblePlugin(BasePlugin, ThreadJob): devmgr = self.device_manager() devices = devmgr.unpaired_devices(handler) + states = [_("wiped"), _("initialized")] good_devices, descrs = [], [] for device in devices: client = self.device_manager().create_client(device, handler, self) if not client: continue state = states[client.is_initialized()] - label = device.info['label'] or _("An unnamed device") + label = client.label() or _("An unnamed device") good_devices.append(device) descrs.append("%s: device ID %s (%s)" % (label, device.id_, state)) diff --git a/plugins/trezor/qt_generic.py b/plugins/trezor/qt_generic.py index c9c2b701..88245de7 100644 --- a/plugins/trezor/qt_generic.py +++ b/plugins/trezor/qt_generic.py @@ -312,9 +312,9 @@ class SettingsDialog(WindowModalDialog): raise RuntimeError("Device not connected") if method: getattr(client, method)(*args, **kw_args) - update(client.features) + return client.features - thread.add(task) + thread.add(task, on_success=update) def update(features): self.current_label = features.label