electrum

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

commit 01cfb8f8f1202f4f7f42648256715787d32c49e8
parent 94c0d8682161f480fcf52f66db1b1049dcb0bd94
Author: ThomasV <thomasv@gitorious>
Date:   Sat, 14 Mar 2015 12:28:19 +0100

new Button widgets

Diffstat:
Mgui/qt/installwizard.py | 31++++++++++++-------------------
Mgui/qt/main_window.py | 64+++++++++++++++++++---------------------------------------------
Mgui/qt/network_dialog.py | 2+-
Mgui/qt/password_dialog.py | 2+-
Mgui/qt/seed_dialog.py | 3+--
Mgui/qt/util.py | 57++++++++++++++++++++++++++++++---------------------------
Mplugins/btchipwallet.py | 1-
Mplugins/openalias.py | 13+++++++------
Mplugins/trezor.py | 4++--
Mplugins/trustedcoin.py | 15+++++++--------
10 files changed, 80 insertions(+), 112 deletions(-)

diff --git a/gui/qt/installwizard.py b/gui/qt/installwizard.py @@ -89,12 +89,10 @@ class InstallWizard(QDialog): button.setChecked(True) vbox.addStretch(1) - hbox, button = ok_cancel_buttons2(self, _('Next')) - vbox.addLayout(hbox) + vbox.addLayout(Buttons(CancelButton(self), OkButton(self, _('Next')))) self.set_layout(vbox) self.show() self.raise_() - button.setDefault(True) if not self.exec_(): return None, None @@ -131,8 +129,8 @@ class InstallWizard(QDialog): func = self.is_any vbox, seed_e = seed_dialog.enter_seed_box(msg, self, sid) vbox.addStretch(1) - hbox, button = ok_cancel_buttons2(self, _('Next')) - vbox.addLayout(hbox) + button = OkButton(self, _('Next')) + vbox.addLayout(Buttons(CancelButton(self), button)) button.setEnabled(False) seed_e.textChanged.connect(lambda: button.setEnabled(func(self.get_seed_text(seed_e)))) self.set_layout(vbox) @@ -151,8 +149,8 @@ class InstallWizard(QDialog): vbox.addLayout(vbox2) entries.append(seed_e2) vbox.addStretch(1) - hbox, button = ok_cancel_buttons2(self, _('Next')) - vbox.addLayout(hbox) + button = OkButton(self, _('Next')) + vbox.addLayout(Buttons(CancelButton(self), button)) button.setEnabled(False) f = lambda: button.setEnabled( map(lambda e: Wallet.is_xpub(self.get_seed_text(e)), entries) == [True]*len(entries)) for e in entries: @@ -173,23 +171,18 @@ class InstallWizard(QDialog): vbox.addLayout(vbox2) entries.append(seed_e2) vbox.addStretch(1) - hbox, button = ok_cancel_buttons2(self, _('Next')) - vbox.addLayout(hbox) + button = OkButton(self, _('Next')) + vbox.addLayout(Buttons(CancelButton(self), button)) button.setEnabled(False) - f = lambda: button.setEnabled( map(lambda e: self.is_any(self.get_seed_text(e)), entries) == [True]*len(entries)) for e in entries: e.textChanged.connect(f) - self.set_layout(vbox) if not self.exec_(): return return map(lambda e: self.get_seed_text(e), entries) - - - def waiting_dialog(self, task, msg= _("Electrum is generating your addresses, please wait.")): def target(): task() @@ -239,7 +232,7 @@ class InstallWizard(QDialog): vbox.addLayout(grid) vbox.addStretch(1) - vbox.addLayout(ok_cancel_buttons(self, _('Next'))) + vbox.addLayout(Buttons(CancelButton(self), OkButton(self, _('Next')))) self.set_layout(vbox) if not self.exec_(): @@ -261,7 +254,7 @@ class InstallWizard(QDialog): vbox.addWidget(logo) vbox.addWidget(QLabel(msg)) vbox.addStretch(1) - vbox.addLayout(close_button(self, _('Next'))) + vbox.addLayout(Buttons(CloseButton(self, _('Next')))) if not self.exec_(): return None @@ -282,7 +275,7 @@ class InstallWizard(QDialog): if i==0: button.setChecked(True) vbox.addStretch(1) - vbox.addLayout(ok_cancel_buttons(self, _("Next"))) + vbox.addLayout(Buttons(CancelButton(self), OkButton(self, _('Next')))) if not self.exec_(): return wallet_type = choices[group2.checkedId()][0] @@ -300,7 +293,7 @@ class InstallWizard(QDialog): label.setWordWrap(True) vbox.addWidget(label) vbox.addStretch(1) - vbox.addLayout(ok_cancel_buttons(self, yes_label, no_label)) + vbox.addLayout(Buttons(CancelButton(self, no_label), OkButton(self, yes_label))) if not self.exec_(): return None return True @@ -308,7 +301,7 @@ class InstallWizard(QDialog): def show_seed(self, seed, sid): vbox = seed_dialog.show_seed_box_msg(seed, sid) - vbox.addLayout(ok_cancel_buttons(self, _("Next"))) + vbox.addLayout(Buttons(CancelButton(self), OkButton(self, _("Next")))) self.set_layout(vbox) return self.exec_() diff --git a/gui/qt/main_window.py b/gui/qt/main_window.py @@ -61,10 +61,7 @@ import csv from electrum import ELECTRUM_VERSION import re -from util import MyTreeWidget, HelpButton, EnterButton, line_dialog, text_dialog, ok_cancel_buttons, close_button, WaitingDialog -from util import filename_field, ok_cancel_buttons2, address_field -from util import MONOSPACE_FONT - +from util import * class StatusBarButton(QPushButton): @@ -1849,7 +1846,7 @@ class ElectrumWindow(QMainWindow): grid.addWidget(line2, 2, 1) vbox.addLayout(grid) - vbox.addLayout(ok_cancel_buttons(d)) + vbox.addLayout(Buttons(CancelButton(d), OkButton(d))) if not d.exec_(): return @@ -1873,11 +1870,9 @@ class ElectrumWindow(QMainWindow): @protected def new_account_dialog(self, password): - dialog = QDialog(self) dialog.setModal(1) dialog.setWindowTitle(_("New Account")) - vbox = QVBoxLayout() vbox.addWidget(QLabel(_('Account name')+':')) e = QLineEdit() @@ -1887,22 +1882,18 @@ class ElectrumWindow(QMainWindow): l = QLabel(msg) l.setWordWrap(True) vbox.addWidget(l) - - vbox.addLayout(ok_cancel_buttons(dialog)) + vbox.addLayout(Buttons(CancelButton(dialog), OkButton(dialog))) dialog.setLayout(vbox) r = dialog.exec_() - if not r: return - + if not r: + return name = str(e.text()) - self.wallet.create_pending_account(name, password) self.update_address_tab() self.update_account_selector() self.tabs.setCurrentIndex(3) - - def show_master_public_keys(self): dialog = QDialog(self) @@ -1933,22 +1924,17 @@ class ElectrumWindow(QMainWindow): name = str(b.text()) mpk = mpk_dict.get(name, "") mpk_text.setText(mpk) - mpk_text.selectAll() # for easy copying group.buttonReleased.connect(show_mpk) first_button.setChecked(True) show_mpk(first_button) - - #combobox.currentIndexChanged[str].connect(lambda acc: show_mpk(acc)) elif len(mpk_dict) == 1: mpk = mpk_dict.values()[0] mpk_text = ShowQRTextEdit(text=mpk) mpk_text.setMaximumHeight(170) - mpk_text.selectAll() # for easy copying vbox.addWidget(mpk_text) - vbox.addLayout(close_button(dialog)) - + vbox.addLayout(Buttons(CopyButton(mpk_text, self.app), CloseButton(dialog))) dialog.setLayout(vbox) dialog.exec_() @@ -2009,7 +1995,7 @@ class ElectrumWindow(QMainWindow): vbox.addWidget( QLabel(_("Public key") + ':')) keys = ShowQRTextEdit(text='\n'.join(pubkey_list)) vbox.addWidget(keys) - vbox.addLayout(close_button(d)) + vbox.addLayout(Buttons(CopyButton(keys, self.app), CloseButton(d))) d.setLayout(vbox) d.exec_() @@ -2032,7 +2018,7 @@ class ElectrumWindow(QMainWindow): vbox.addWidget( QLabel(_("Private key") + ':')) keys = ShowQRTextEdit(text='\n'.join(pk_list)) vbox.addWidget(keys) - vbox.addLayout(close_button(d)) + vbox.addLayout(Buttons(CopyButton(keys, self.app), CloseButton(d))) d.setLayout(vbox) d.exec_() @@ -2187,7 +2173,7 @@ class ElectrumWindow(QMainWindow): grid.addWidget(pw, 1, 1) vbox.addLayout(grid) - vbox.addLayout(ok_cancel_buttons(d)) + vbox.addLayout(Buttons(CancelButton(d), OkButton(d))) d.setLayout(vbox) run_hook('password_dialog', pw, grid, 1) @@ -2384,9 +2370,9 @@ class ElectrumWindow(QMainWindow): hbox, filename_e, csv_button = filename_field(self, self.config, defaultname, select_msg) vbox.addLayout(hbox) - h, b = ok_cancel_buttons2(d, _('Export')) + b = OkButton(d, _('Export')) b.setEnabled(False) - vbox.addLayout(h) + vbox.addLayout(Buttons(CancelButton(d), b)) private_keys = {} addresses = self.wallet.addresses(True) @@ -2469,40 +2455,30 @@ class ElectrumWindow(QMainWindow): def export_history_dialog(self): - d = QDialog(self) d.setWindowTitle(_('Export History')) d.setMinimumSize(400, 200) vbox = QVBoxLayout(d) - defaultname = os.path.expanduser('~/electrum-history.csv') select_msg = _('Select file to export your wallet transactions to') - hbox, filename_e, csv_button = filename_field(self, self.config, defaultname, select_msg) vbox.addLayout(hbox) - vbox.addStretch(1) - - h, b = ok_cancel_buttons2(d, _('Export')) - vbox.addLayout(h) - - run_hook('export_history_dialog', self,hbox) + hbox = Buttons(CancelButton(d), OkButton(d, _('Export'))) + vbox.addLayout(hbox) + run_hook('export_history_dialog', self, hbox) self.update() - if not d.exec_(): return - filename = filename_e.text() if not filename: return - try: self.do_export_history(self.wallet, filename, csv_button.isChecked()) except (IOError, os.error), reason: export_error_label = _("Electrum was unable to produce a transaction export.") QMessageBox.critical(self, _("Unable to export history"), export_error_label + "\n" + str(reason)) return - QMessageBox.information(self,_("History exported"), _("Your wallet history has been successfully exported.")) @@ -2572,8 +2548,8 @@ class ElectrumWindow(QMainWindow): vbox.addLayout(h) vbox.addStretch(1) - hbox, button = ok_cancel_buttons2(d, _('Sweep')) - vbox.addLayout(hbox) + button = OkButton(d, _('Sweep')) + vbox.addLayout(Buttons(CancelButton(d), button)) button.setEnabled(False) def get_address(): @@ -2787,7 +2763,7 @@ class ElectrumWindow(QMainWindow): vbox.addLayout(grid) vbox.addStretch(1) - vbox.addLayout(close_button(d)) + vbox.addLayout(Buttons(CloseButton(d))) d.setLayout(vbox) # run the dialog @@ -2873,7 +2849,7 @@ class ElectrumWindow(QMainWindow): print_msg("Error: cannot display plugin", p) traceback.print_exc(file=sys.stdout) grid.setRowStretch(i+1,1) - vbox.addLayout(close_button(d)) + vbox.addLayout(Buttons(CloseButton(d))) d.exec_() def show_account_details(self, k): @@ -2898,9 +2874,7 @@ class ElectrumWindow(QMainWindow): text.setReadOnly(True) text.setMaximumHeight(170) vbox.addWidget(text) - mpk_text = '\n'.join( account.get_master_pubkeys() ) text.setText(mpk_text) - - vbox.addLayout(close_button(d)) + vbox.addLayout(Buttons(CloseButton(d))) d.exec_() diff --git a/gui/qt/network_dialog.py b/gui/qt/network_dialog.py @@ -166,7 +166,7 @@ class NetworkDialog(QDialog): grid.addWidget(self.proxy_port, 4, 3) # buttons - vbox.addLayout(ok_cancel_buttons(self)) + vbox.addLayout(Buttons(CancelButton(self), OkButton(self))) self.setLayout(vbox) diff --git a/gui/qt/password_dialog.py b/gui/qt/password_dialog.py @@ -74,7 +74,7 @@ def make_password_dialog(self, wallet, msg, new_pass=True): self.new_pw.textChanged.connect(lambda: update_password_strength(self.pw_strength, self.new_pw.text())) vbox.addStretch(1) - vbox.addLayout(ok_cancel_buttons(self)) + vbox.addLayout(Buttons(CancelButton(self), OkButton(self))) return vbox diff --git a/gui/qt/seed_dialog.py b/gui/qt/seed_dialog.py @@ -22,7 +22,6 @@ import PyQt4.QtCore as QtCore from electrum.i18n import _ from electrum import mnemonic from qrcodewidget import QRCodeWidget, QRDialog -from util import close_button from qrtextedit import ShowQRTextEdit, ScanQRTextEdit class SeedDialog(QDialog): @@ -34,7 +33,7 @@ class SeedDialog(QDialog): vbox = show_seed_box_msg(seed) if imported_keys: vbox.addWidget(QLabel("<b>"+_("WARNING")+":</b> " + _("Your wallet contains imported keys. These keys cannot be recovered from seed.") + "</b><p>")) - vbox.addLayout(close_button(self)) + vbox.addLayout(Buttons(CloseButton(self))) self.setLayout(vbox) diff --git a/gui/qt/util.py b/gui/qt/util.py @@ -93,33 +93,36 @@ class HelpButton(QPushButton): else: QMessageBox.information(self, 'Help', self.help_text, 'OK') +class Buttons(QHBoxLayout): + def __init__(self, *buttons): + QHBoxLayout.__init__(self) + self.addStretch(1) + for b in buttons: + self.addWidget(b) + +class CloseButton(QPushButton): + def __init__(self, dialog): + QPushButton.__init__(self, _("Close")) + self.clicked.connect(dialog.close) + self.setDefault(True) + +class CopyButton(QPushButton): + def __init__(self, text, app): + QPushButton.__init__(self, _("Copy")) + self.clicked.connect(lambda: app.clipboard().setText(str(text.toPlainText()))) + +class OkButton(QPushButton): + def __init__(self, dialog, label=None): + QPushButton.__init__(self, label or _("OK")) + self.clicked.connect(dialog.accept) + self.setDefault(True) + +class CancelButton(QPushButton): + def __init__(self, dialog, label=None): + QPushButton.__init__(self, label or _("Cancel")) + self.clicked.connect(dialog.reject) -def close_button(dialog, label=None): - hbox = QHBoxLayout() - hbox.addStretch(1) - b = QPushButton(label or _("Close")) - hbox.addWidget(b) - b.clicked.connect(dialog.close) - b.setDefault(True) - return hbox - -def ok_cancel_buttons2(dialog, ok_label=None, cancel_label=None): - hbox = QHBoxLayout() - hbox.addStretch(1) - b = QPushButton(cancel_label or _('Cancel')) - hbox.addWidget(b) - b.clicked.connect(dialog.reject) - b = QPushButton(ok_label or _("OK")) - hbox.addWidget(b) - b.clicked.connect(dialog.accept) - b.setDefault(True) - return hbox, b - -def ok_cancel_buttons(dialog, ok_label=None, cancel_label=None): - hbox, b = ok_cancel_buttons2(dialog, ok_label, cancel_label) - return hbox - def line_dialog(parent, title, label, ok_label, default=None): dialog = QDialog(parent) dialog.setMinimumWidth(500) @@ -132,7 +135,7 @@ def line_dialog(parent, title, label, ok_label, default=None): if default: txt.setText(default) l.addWidget(txt) - l.addLayout(ok_cancel_buttons(dialog, ok_label)) + l.addLayout(Buttons(CancelButton(dialog), OkButton(dialog, ok_label))) if dialog.exec_(): return unicode(txt.text()) @@ -149,7 +152,7 @@ def text_dialog(parent, title, label, ok_label, default=None): if default: txt.setText(default) l.addWidget(txt) - l.addLayout(ok_cancel_buttons(dialog, ok_label)) + l.addLayout(Buttons(CancelButton(dialog), OkButton(dialog, ok_label))) if dialog.exec_(): return unicode(txt.toPlainText()) diff --git a/plugins/btchipwallet.py b/plugins/btchipwallet.py @@ -9,7 +9,6 @@ from base64 import b64encode, b64decode import electrum from electrum_gui.qt.password_dialog import make_password_dialog, run_password_dialog -from electrum_gui.qt.util import ok_cancel_buttons from electrum.account import BIP32_Account from electrum.bitcoin import EncodeBase58Check, DecodeBase58Check, public_key_to_bc_address, bc_address_to_hash_160 from electrum.i18n import _ diff --git a/plugins/openalias.py b/plugins/openalias.py @@ -15,14 +15,15 @@ # Version: 0.1 # Todo: optionally use OA resolvers; add DNSCrypt support -from electrum_gui.qt.util import EnterButton +import re +from PyQt4.QtGui import * +from PyQt4.QtCore import * + +from electrum_gui.qt.util import * from electrum.plugins import BasePlugin, hook from electrum.util import print_error from electrum.i18n import _ -from PyQt4.QtGui import * -from PyQt4.QtCore import * -import re # Import all of the rdtypes, as py2app and similar get confused with the dnspython # autoloader and won't include all the rdatatypes @@ -182,7 +183,7 @@ class Plugin(BasePlugin): grid.addWidget(line1, 1, 1) vbox.addLayout(grid) - vbox.addLayout(ok_cancel_buttons(d)) + vbox.addLayout(Buttons(CancelButton(d), OkButton(d))) if not d.exec_(): return @@ -224,7 +225,7 @@ class Plugin(BasePlugin): grid2.addWidget(QLabel(address), 4, 1) vbox2.addLayout(grid2) - vbox2.addLayout(ok_cancel_buttons(d2)) + vbox2.addLayout(Buttons(CancelButton(d2), OkButton(d2))) if not d2.exec_(): return diff --git a/plugins/trezor.py b/plugins/trezor.py @@ -16,7 +16,7 @@ from electrum.transaction import deserialize from electrum.wallet import BIP32_HD_Wallet from electrum.util import print_error -from electrum_gui.qt.util import ok_cancel_buttons, EnterButton +from electrum_gui.qt.util import * try: from trezorlib.client import types @@ -519,7 +519,7 @@ class TrezorQtGuiMixin(object): vbox = QVBoxLayout() vbox.addWidget(QLabel(msg)) vbox.addWidget(matrix) - vbox.addLayout(ok_cancel_buttons(d)) + vbox.addLayout(Buttons(CancelButton(d), OkButton(d))) d.setLayout(vbox) if not d.exec_(): return diff --git a/plugins/trustedcoin.py b/plugins/trustedcoin.py @@ -38,9 +38,8 @@ from electrum.wallet import Wallet_2of3 from electrum.i18n import _ from electrum.plugins import BasePlugin, run_hook, hook -from electrum_gui.qt.util import text_dialog, EnterButton, WaitingDialog +from electrum_gui.qt.util import * from electrum_gui.qt.qrcodewidget import QRCodeWidget -from electrum_gui.qt import ok_cancel_buttons, ok_cancel_buttons2, close_button from electrum_gui.qt.amountedit import AmountEdit from electrum_gui.qt.main_window import StatusBarButton @@ -532,7 +531,7 @@ class Plugin(BasePlugin): grid.addWidget(QLabel(_('Code')), 1, 0) grid.addWidget(pw, 1, 1) vbox.addLayout(grid) - vbox.addLayout(ok_cancel_buttons(d)) + vbox.addLayout(Buttons(CancelButton(d), OkButton(d))) if not d.exec_(): return return pw.get_amount() @@ -617,7 +616,7 @@ class Plugin(BasePlugin): #grid.addWidget(QLabel(_("Next Billing Address:")), i, 0) #grid.addWidget(QLabel(self.billing_info['billing_address']), i, 1) - vbox.addLayout(close_button(d)) + vbox.addLayout(Buttons(CloseButton(d))) d.exec_() @@ -642,9 +641,9 @@ class Plugin(BasePlugin): email_e = QLineEdit() vbox.addWidget(email_e) vbox.addStretch() - hbox, accept_button = ok_cancel_buttons2(window, _('Accept')) + accept_button = OkButton(window, _('Accept')) accept_button.setEnabled(False) - vbox.addLayout(hbox) + vbox.addLayout(Buttons(CancelButton(window), accept_button)) def request_TOS(): tos = server.get_terms_of_service() @@ -688,9 +687,9 @@ class Plugin(BasePlugin): hbox.addStretch(1) vbox.addLayout(hbox) - hbox, b = ok_cancel_buttons2(window, _('Next')) + b = OkButton(window, _('Next')) b.setEnabled(False) - vbox.addLayout(hbox) + vbox.addLayout(Buttons(CancelButton(window), b)) pw.textChanged.connect(lambda: b.setEnabled(len(pw.text())==6)) window.exec_()