Browse Source

PEP8-ify most of plugins/trezor

283
Neil Booth 9 years ago
parent
commit
7372e0e082
  1. 4
      plugins/trezor/client.py
  2. 5
      plugins/trezor/plugin.py
  3. 1
      plugins/trezor/qt.py
  4. 18
      plugins/trezor/qt_generic.py

4
plugins/trezor/client.py

@ -2,6 +2,7 @@ from sys import stderr
from electrum.i18n import _ from electrum.i18n import _
class GuiMixin(object): class GuiMixin(object):
# Requires: self.proto, self.device # Requires: self.proto, self.device
@ -47,12 +48,13 @@ class GuiMixin(object):
return self.proto.PassphraseAck(passphrase=passphrase) return self.proto.PassphraseAck(passphrase=passphrase)
def callback_WordRequest(self, msg): def callback_WordRequest(self, msg):
#TODO # TODO
stderr.write("Enter one word of mnemonic:\n") stderr.write("Enter one word of mnemonic:\n")
stderr.flush() stderr.flush()
word = raw_input() word = raw_input()
return self.proto.WordAck(word=word) return self.proto.WordAck(word=word)
def trezor_client_class(protocol_mixin, base_client, proto): def trezor_client_class(protocol_mixin, base_client, proto):
'''Returns a class dynamically.''' '''Returns a class dynamically.'''

5
plugins/trezor/plugin.py

@ -6,6 +6,7 @@ from electrum.i18n import _
from electrum.plugins import BasePlugin, hook from electrum.plugins import BasePlugin, hook
from electrum.transaction import deserialize, is_extended_pubkey from electrum.transaction import deserialize, is_extended_pubkey
class TrezorCompatiblePlugin(BasePlugin): class TrezorCompatiblePlugin(BasePlugin):
# Derived classes provide: # Derived classes provide:
# #
@ -123,7 +124,7 @@ class TrezorCompatiblePlugin(BasePlugin):
txinputtype = self.types.TxInputType() txinputtype = self.types.TxInputType()
if txin.get('is_coinbase'): if txin.get('is_coinbase'):
prev_hash = "\0"*32 prev_hash = "\0"*32
prev_index = 0xffffffff # signed int -1 prev_index = 0xffffffff # signed int -1
else: else:
if for_sig: if for_sig:
x_pubkeys = txin['x_pubkeys'] x_pubkeys = txin['x_pubkeys']
@ -149,7 +150,7 @@ class TrezorCompatiblePlugin(BasePlugin):
) )
txinputtype = self.types.TxInputType( txinputtype = self.types.TxInputType(
script_type=self.types.SPENDMULTISIG, script_type=self.types.SPENDMULTISIG,
multisig= multisig multisig=multisig
) )
# find which key is mine # find which key is mine
for x_pubkey in x_pubkeys: for x_pubkey in x_pubkeys:

1
plugins/trezor/qt.py

@ -1,6 +1,7 @@
from plugins.trezor.qt_generic import QtPlugin from plugins.trezor.qt_generic import QtPlugin
from trezorlib.qt.pinmatrix import PinMatrixWidget from trezorlib.qt.pinmatrix import PinMatrixWidget
class Plugin(QtPlugin): class Plugin(QtPlugin):
pin_matrix_widget_class = PinMatrixWidget pin_matrix_widget_class = PinMatrixWidget
icon_file = ":icons/trezor.png" icon_file = ":icons/trezor.png"

18
plugins/trezor/qt_generic.py

@ -13,6 +13,7 @@ from electrum_gui.qt.util import *
from electrum.i18n import _ from electrum.i18n import _
from electrum.plugins import hook from electrum.plugins import hook
class QtHandler: class QtHandler:
'''An interface between the GUI (here, QT) and the device handling '''An interface between the GUI (here, QT) and the device handling
logic for handling I/O. This is a generic implementation of the logic for handling I/O. This is a generic implementation of the
@ -129,7 +130,7 @@ class QtPlugin(TrezorPlugin):
if storage.get('wallet_type') != self.wallet_class.wallet_type: if storage.get('wallet_type') != self.wallet_class.wallet_type:
return return
seed = wizard.enter_seed_dialog(_("Enter your %s seed") % self.device, seed = wizard.enter_seed_dialog(_("Enter your %s seed") % self.device,
None, func=lambda x:True) None, func=lambda x: True)
if not seed: if not seed:
return return
wallet = self.wallet_class(storage) wallet = self.wallet_class(storage)
@ -150,8 +151,8 @@ class QtPlugin(TrezorPlugin):
@hook @hook
def receive_menu(self, menu, addrs): def receive_menu(self, menu, addrs):
if (not self.wallet.is_watching_only() and self.atleast_version(1, 3) if (not self.wallet.is_watching_only() and
and len(addrs) == 1): self.atleast_version(1, 3) and len(addrs) == 1):
menu.addAction(_("Show on %s") % self.device, menu.addAction(_("Show on %s") % self.device,
lambda: self.show_address(addrs[0])) lambda: self.show_address(addrs[0]))
@ -175,8 +176,11 @@ class QtPlugin(TrezorPlugin):
except BaseException as e: except BaseException as e:
window.show_error(str(e)) window.show_error(str(e))
return return
get_label = lambda: self.get_client().features.label
update_label = lambda: current_label.setText("Label: %s" % get_label()) def update_label():
label = self.get_client().features.label
current_label.setText("Label: %s" % label)
d = WindowModalDialog(window, _("%s Settings") % self.device) d = WindowModalDialog(window, _("%s Settings") % self.device)
layout = QGridLayout(d) layout = QGridLayout(d)
layout.addWidget(QLabel(_("%s Options") % self.device), 0, 0) layout.addWidget(QLabel(_("%s Options") % self.device), 0, 0)
@ -200,6 +204,6 @@ class QtPlugin(TrezorPlugin):
update_label() update_label()
change_label_button = QPushButton("Modify") change_label_button = QPushButton("Modify")
change_label_button.clicked.connect(modify_label) change_label_button.clicked.connect(modify_label)
layout.addWidget(current_label,3,0) layout.addWidget(current_label, 3, 0)
layout.addWidget(change_label_button,3,1) layout.addWidget(change_label_button, 3, 1)
d.exec_() d.exec_()

Loading…
Cancel
Save