electrum

Electrum Bitcoin wallet
git clone https://git.parazyd.org/electrum
Log | Files | Refs | Submodules

commit ae779694dfcec3a5ae549006ca97cd723e981c46
parent 02db08504c19528e4dca6c1d00f439e1875c015b
Author: ThomasV <thomasv@electrum.org>
Date:   Wed, 31 Aug 2016 11:50:19 +0200

create common class for qt hardware plugins

Diffstat:
Mplugins/hw_wallet/qt.py | 28++++++++++++++++++++++++++++
Mplugins/ledger/qt.py | 41++++++++++-------------------------------
Mplugins/trezor/qt_generic.py | 22++--------------------
3 files changed, 40 insertions(+), 51 deletions(-)

diff --git a/plugins/hw_wallet/qt.py b/plugins/hw_wallet/qt.py @@ -168,3 +168,31 @@ class QtHandlerBase(QObject, PrintError): def win_yes_no_question(self, msg): self.ok = self.win.question(msg) self.done.set() + + + +from electrum.plugins import hook +from electrum_gui.qt.main_window import StatusBarButton + +class QtPluginBase(object): + + @hook + def load_wallet(self, wallet, window): + for keystore in wallet.get_keystores(): + if type(keystore) != self.keystore_class: + continue + tooltip = self.device + '\n' + (keystore.label or 'unnamed') + cb = partial(self.show_settings_dialog, window, keystore) + button = StatusBarButton(QIcon(self.icon_unpaired), tooltip, cb) + button.icon_paired = self.icon_paired + button.icon_unpaired = self.icon_unpaired + window.statusBar().addPermanentWidget(button) + handler = self.create_handler(window) + handler.button = button + keystore.handler = handler + keystore.thread = TaskThread(window, window.on_error) + # Trigger a pairing + keystore.thread.add(partial(self.get_client, keystore)) + + def show_settings_dialog(self, window, keystore): + pass diff --git a/plugins/ledger/qt.py b/plugins/ledger/qt.py @@ -3,46 +3,25 @@ import threading from PyQt4.Qt import (QDialog, QInputDialog, QLineEdit, QVBoxLayout, QLabel, SIGNAL) import PyQt4.QtCore as QtCore -from electrum_gui.qt.main_window import StatusBarButton from electrum.i18n import _ -from electrum.plugins import hook -from .ledger import LedgerPlugin, Ledger_KeyStore -from ..hw_wallet.qt import QtHandlerBase +from .ledger import LedgerPlugin +from ..hw_wallet.qt import QtHandlerBase, QtPluginBase from electrum_gui.qt.util import * -class Plugin(LedgerPlugin): + +class Plugin(LedgerPlugin, QtPluginBase): icon_unpaired = ":icons/ledger_unpaired.png" icon_paired = ":icons/ledger.png" - @hook - def load_wallet(self, wallet, window): - for keystore in wallet.get_keystores(): - if type(keystore) != self.keystore_class: - continue - tooltip = self.device - cb = partial(self.show_settings_dialog, window, keystore) - button = StatusBarButton(QIcon(self.icon_unpaired), tooltip, cb) - button.icon_paired = self.icon_paired - button.icon_unpaired = self.icon_unpaired - window.statusBar().addPermanentWidget(button) - handler = BTChipQTHandler(window) - handler.button = button - keystore.handler = handler - keystore.thread = TaskThread(window, window.on_error) - # Trigger a pairing - keystore.thread.add(partial(self.get_client, keystore)) - - def create_handler(self, wizard): - return BTChipQTHandler(wizard) - - def show_settings_dialog(self, window, keystore): - pass - -class BTChipQTHandler(QtHandlerBase): + def create_handler(self, window): + return Ledger_Handler(window) + + +class Ledger_Handler(QtHandlerBase): def __init__(self, win): - super(BTChipQTHandler, self).__init__(win, 'Ledger') + super(Ledger_Handler, self).__init__(win, 'Ledger') def word_dialog(self, msg): response = QInputDialog.getText(self.top_level_window(), "Ledger Wallet Authentication", msg, QLineEdit.Password) diff --git a/plugins/trezor/qt_generic.py b/plugins/trezor/qt_generic.py @@ -7,7 +7,7 @@ from PyQt4.Qt import QVBoxLayout, QLabel, SIGNAL from electrum_gui.qt.main_window import StatusBarButton from electrum_gui.qt.util import * from .plugin import TIM_NEW, TIM_RECOVER, TIM_MNEMONIC -from ..hw_wallet.qt import QtHandlerBase +from ..hw_wallet.qt import QtHandlerBase, QtPluginBase from electrum.i18n import _ from electrum.plugins import hook, DeviceMgr @@ -178,7 +178,7 @@ class QtHandler(QtHandlerBase): -class QtPlugin(object): +class QtPlugin(QtPluginBase): # Derived classes must provide the following class-static variables: # icon_file # pin_matrix_widget_class @@ -187,24 +187,6 @@ class QtPlugin(object): return QtHandler(window, self.pin_matrix_widget_class(), self.device) @hook - def load_wallet(self, wallet, window): - for keystore in wallet.get_keystores(): - if type(keystore) != self.keystore_class: - continue - tooltip = self.device + ' ' + (keystore.label or '') - cb = partial(self.show_settings_dialog, window, keystore) - button = StatusBarButton(QIcon(self.icon_unpaired), tooltip, cb) - button.icon_paired = self.icon_paired - button.icon_unpaired = self.icon_unpaired - window.statusBar().addPermanentWidget(button) - handler = self.create_handler(window) - handler.button = button - keystore.handler = handler - keystore.thread = TaskThread(window, window.on_error) - # Trigger a pairing - keystore.thread.add(partial(self.get_client, keystore)) - - @hook def receive_menu(self, menu, addrs, wallet): if type(wallet) is not Standard_Wallet: return