Browse Source

fix imports in hardware wallets

283
ThomasV 9 years ago
parent
commit
d5f43610ed
  1. 89
      plugins/keepkey/keepkey.py
  2. 93
      plugins/keepkey/qt.py
  3. 2
      plugins/ledger/ledger.py
  4. 4
      plugins/ledger/qt.py
  5. 2
      plugins/trezor/qt.py

89
plugins/keepkey/keepkey.py

@ -420,7 +420,7 @@ class KeepKeyPlugin(BasePlugin):
class CmdlinePlugin(Plugin):
class CmdlinePlugin(KeepKeyPlugin):
@hook
def cmdline_load_wallet(self, wallet):
@ -499,92 +499,6 @@ class KeepKeyCmdLineHandler:
print_msg(msg)
class KeepKeyQtHandler:
def __init__(self, win):
self.win = win
self.win.connect(win, SIGNAL('keepkey_done'), self.dialog_stop)
self.win.connect(win, SIGNAL('message_dialog'), self.message_dialog)
self.win.connect(win, SIGNAL('pin_dialog'), self.pin_dialog)
self.win.connect(win, SIGNAL('passphrase_dialog'), self.passphrase_dialog)
self.done = threading.Event()
def stop(self):
self.win.emit(SIGNAL('keepkey_done'))
def show_message(self, msg_code, msg, client):
self.messsage_code = msg_code
self.message = msg
self.client = client
self.win.emit(SIGNAL('message_dialog'))
def get_pin(self, msg):
self.done.clear()
self.message = msg
self.win.emit(SIGNAL('pin_dialog'))
self.done.wait()
return self.response
def get_passphrase(self, msg):
self.done.clear()
self.message = msg
self.win.emit(SIGNAL('passphrase_dialog'))
self.done.wait()
return self.passphrase
def pin_dialog(self):
d = QDialog(None)
d.setModal(1)
d.setWindowTitle(_("Enter PIN"))
d.setWindowFlags(d.windowFlags() | QtCore.Qt.WindowStaysOnTopHint)
matrix = PinMatrixWidget()
vbox = QVBoxLayout()
vbox.addWidget(QLabel(self.message))
vbox.addWidget(matrix)
vbox.addLayout(Buttons(CancelButton(d), OkButton(d)))
d.setLayout(vbox)
if not d.exec_():
self.response = None
self.response = str(matrix.get_value())
self.done.set()
def passphrase_dialog(self):
if type(self.win) is ElectrumWindow:
passphrase = self.win.password_dialog(_("Please enter your KeepKey passphrase"))
self.passphrase = unicodedata.normalize('NFKD', unicode(passphrase)) if passphrase else ''
else:
assert type(self.win) is InstallWizard
from electrum_gui.qt.password_dialog import make_password_dialog, run_password_dialog
d = QDialog()
d.setModal(1)
d.setLayout(make_password_dialog(d, None, self.message, False))
confirmed, p, passphrase = run_password_dialog(d, None, None)
if not confirmed:
QMessageBox.critical(None, _('Error'), _("Password request canceled"), _('OK'))
self.passphrase = None
else:
self.passphrase = unicodedata.normalize('NFKD', unicode(passphrase)) if passphrase else ''
self.done.set()
def message_dialog(self):
self.d = QDialog()
self.d.setModal(1)
self.d.setWindowTitle('Please Check KeepKey Device')
self.d.setWindowFlags(self.d.windowFlags() | QtCore.Qt.WindowStaysOnTopHint)
l = QLabel(self.message)
vbox = QVBoxLayout(self.d)
vbox.addWidget(l)
if self.messsage_code in (3, 8):
vbox.addLayout(Buttons(CancelButton(self.d)))
self.d.connect(self.d, SIGNAL('rejected()'), self.client.cancel)
self.d.show()
def dialog_stop(self):
self.d.hide()
if KEEPKEY:
class QtGuiKeepKeyClient(ProtocolMixin, KeepKeyGuiMixin, BaseClient):
def call_raw(self, msg):
@ -595,3 +509,4 @@ if KEEPKEY:
raise
return resp

93
plugins/keepkey/qt.py

@ -5,7 +5,11 @@ from electrum_gui.qt.main_window import StatusBarButton, ElectrumWindow
from electrum_gui.qt.installwizard import InstallWizard
from keepkeylib.qt.pinmatrix import PinMatrixWidget
from keepkey import KeepKeyPlugin
from functools import partial
from keepkey import KeepKeyPlugin, KeepKeyWallet
from electrum.plugins import hook
from electrum.i18n import _
class Plugin(KeepKeyPlugin):
@ -93,3 +97,90 @@ class Plugin(KeepKeyPlugin):
layout.addWidget(change_label_button,3,1)
d.exec_()
class KeepKeyQtHandler:
def __init__(self, win):
self.win = win
self.win.connect(win, SIGNAL('keepkey_done'), self.dialog_stop)
self.win.connect(win, SIGNAL('message_dialog'), self.message_dialog)
self.win.connect(win, SIGNAL('pin_dialog'), self.pin_dialog)
self.win.connect(win, SIGNAL('passphrase_dialog'), self.passphrase_dialog)
self.done = threading.Event()
def stop(self):
self.win.emit(SIGNAL('keepkey_done'))
def show_message(self, msg_code, msg, client):
self.messsage_code = msg_code
self.message = msg
self.client = client
self.win.emit(SIGNAL('message_dialog'))
def get_pin(self, msg):
self.done.clear()
self.message = msg
self.win.emit(SIGNAL('pin_dialog'))
self.done.wait()
return self.response
def get_passphrase(self, msg):
self.done.clear()
self.message = msg
self.win.emit(SIGNAL('passphrase_dialog'))
self.done.wait()
return self.passphrase
def pin_dialog(self):
d = QDialog(None)
d.setModal(1)
d.setWindowTitle(_("Enter PIN"))
d.setWindowFlags(d.windowFlags() | QtCore.Qt.WindowStaysOnTopHint)
matrix = PinMatrixWidget()
vbox = QVBoxLayout()
vbox.addWidget(QLabel(self.message))
vbox.addWidget(matrix)
vbox.addLayout(Buttons(CancelButton(d), OkButton(d)))
d.setLayout(vbox)
if not d.exec_():
self.response = None
self.response = str(matrix.get_value())
self.done.set()
def passphrase_dialog(self):
if type(self.win) is ElectrumWindow:
passphrase = self.win.password_dialog(_("Please enter your KeepKey passphrase"))
self.passphrase = unicodedata.normalize('NFKD', unicode(passphrase)) if passphrase else ''
else:
assert type(self.win) is InstallWizard
from electrum_gui.qt.password_dialog import make_password_dialog, run_password_dialog
d = QDialog()
d.setModal(1)
d.setLayout(make_password_dialog(d, None, self.message, False))
confirmed, p, passphrase = run_password_dialog(d, None, None)
if not confirmed:
QMessageBox.critical(None, _('Error'), _("Password request canceled"), _('OK'))
self.passphrase = None
else:
self.passphrase = unicodedata.normalize('NFKD', unicode(passphrase)) if passphrase else ''
self.done.set()
def message_dialog(self):
self.d = QDialog()
self.d.setModal(1)
self.d.setWindowTitle('Please Check KeepKey Device')
self.d.setWindowFlags(self.d.windowFlags() | QtCore.Qt.WindowStaysOnTopHint)
l = QLabel(self.message)
vbox = QVBoxLayout(self.d)
vbox.addWidget(l)
if self.messsage_code in (3, 8):
vbox.addLayout(Buttons(CancelButton(self.d)))
self.d.connect(self.d, SIGNAL('rejected()'), self.client.cancel)
self.d.show()
def dialog_stop(self):
self.d.hide()

2
plugins/ledger/ledger.py

@ -496,7 +496,7 @@ class LedgerPlugin(BasePlugin):
tx.error = str(e)
class CmdlinePlugin(Plugin):
class CmdlinePlugin(LedgerPlugin):
@hook
def cmdline_load_wallet(self, wallet):
self.wallet = wallet

4
plugins/ledger/qt.py

@ -1,6 +1,10 @@
from PyQt4.Qt import QApplication, QMessageBox, QDialog, QInputDialog, QLineEdit, QVBoxLayout, QLabel, QThread, SIGNAL
import PyQt4.QtCore as QtCore
from electrum_gui.qt.password_dialog import make_password_dialog, run_password_dialog
from electrum.plugins import BasePlugin, hook
from ledger import LedgerPlugin
class Plugin(LedgerPlugin):

2
plugins/trezor/qt.py

@ -12,7 +12,7 @@ import unicodedata
from electrum.i18n import _
from electrum.plugins import hook, always_hook, run_hook
from trezor import TrezorPlugin
from trezor import TrezorPlugin, TrezorWallet
class TrezorQtHandler:

Loading…
Cancel
Save