Browse Source

Prettified code for BrainWallet dialog.

283
Amir Taaki 13 years ago
parent
commit
7f81bcf05f
  1. 75
      lib/gui_qt.py

75
lib/gui_qt.py

@ -899,68 +899,65 @@ class ElectrumWindow(QMainWindow):
@staticmethod @staticmethod
def show_seed_dialog(wallet, parent=None): def show_seed_dialog(wallet, parent=None):
if not wallet.seed: if not wallet.seed:
QMessageBox.information(parent, _('Message'), _('No seed'), _('OK')) QMessageBox.information(parent, _('Message'),
_('No seed'), _('OK'))
return return
if wallet.use_encryption: if wallet.use_encryption:
password = parent.password_dialog() password = parent.password_dialog()
if not password: return if not password:
return
else: else:
password = None password = None
try: try:
seed = wallet.pw_decode(wallet.seed, password) seed = wallet.pw_decode(wallet.seed, password)
except: except:
QMessageBox.warning(parent, _('Error'), _('Incorrect Password'), _('OK')) QMessageBox.warning(parent, _('Error'),
_('Incorrect Password'), _('OK'))
return return
msg = '"' + ' '.join(mnemonic.mn_encode(seed)) + '"\n\n' + \ dialog = QDialog(None)
_("If you memorise or write down these 12 words, you will always be able to\nrecover your wallet.\n\nThis is called a 'BrainWallet'. The order of words is important. Case does not\nmatter (capitals or lowercase).") dialog.setModal(1)
#msg = _("Your wallet generation seed is") + ":\n\n" + seed + "\n\n"\ dialog.setWindowTitle(_("Seed"))
# + _("Please keep it in a safe place; if you lose it, you will not be able to restore your wallet.") + "\n\n" \
# + _("Equivalently, your wallet seed can be stored and recovered with the following mnemonic code") + ":\n\n\"" \
# + ' '.join(mnemonic.mn_encode(seed)) + "\"\n\n\n"
d = QDialog(None) brainwallet = ' '.join(mnemonic.mn_encode(seed))
d.setModal(1)
d.setWindowTitle(_("Seed"))
d.setMinimumSize(400, 270)
vbox = QVBoxLayout() msg = _('<p>"%s"</p>'
hbox = QHBoxLayout() "<p>If you memorise or write down these 12 words, you will always be able to recover your wallet.</p>"
vbox2 = QVBoxLayout() "<p>This is called a 'BrainWallet'. The order of words is important. Case does not matter (capitals or lowercase).</p>") % brainwallet
l = QLabel() main_text = QLabel(msg)
l.setPixmap(QPixmap(":icons/seed.png").scaledToWidth(56)) main_text.setWordWrap(True)
vbox2.addWidget(l)
vbox2.addStretch(1)
hbox.addLayout(vbox2)
hbox.addWidget(QLabel(msg))
vbox.addLayout(hbox)
hbox = QHBoxLayout()
hbox.addStretch(1)
logo = QLabel()
logo.setPixmap(QPixmap(":icons/seed.png").scaledToWidth(56))
if parent: if parent:
app = parent.app app = parent.app
else: else:
app = QApplication app = QApplication
b = QPushButton(_("Copy to Clipboard")) copy_function = lambda: app.clipboard().setText(brainwallet)
b.clicked.connect(lambda: app.clipboard().setText(' '.join(mnemonic.mn_encode(seed)))) copy_button = QPushButton(_("Copy to Clipboard"))
hbox.addWidget(b) copy_button.clicked.connect(copy_function)
b = QPushButton(_("View as QR Code"))
b.clicked.connect(lambda: ElectrumWindow.show_seed_qrcode(seed))
hbox.addWidget(b)
b = QPushButton(_("OK")) show_qr_function = lambda: ElectrumWindow.show_seed_qrcode(seed)
b.clicked.connect(d.accept) qr_button = QPushButton(_("View as QR Code"))
hbox.addWidget(b) qr_button.clicked.connect(show_qr_function)
vbox.addLayout(hbox)
d.setLayout(vbox) ok_button = QPushButton(_("OK"))
d.exec_() ok_button.clicked.connect(dialog.accept)
main_layout = QGridLayout()
main_layout.addWidget(logo, 0, 0)
main_layout.addWidget(main_text, 0, 1, 1, -1)
main_layout.addWidget(copy_button, 1, 1)
main_layout.addWidget(qr_button, 1, 2)
main_layout.addWidget(ok_button, 1, 3)
dialog.setLayout(main_layout)
dialog.exec_()
@staticmethod @staticmethod
def show_seed_qrcode(seed): def show_seed_qrcode(seed):

Loading…
Cancel
Save