diff --git a/gui/qt/main_window.py b/gui/qt/main_window.py index c329ad93b..f3257c296 100644 --- a/gui/qt/main_window.py +++ b/gui/qt/main_window.py @@ -48,7 +48,7 @@ from electrum import Imported_Wallet, paymentrequest from amountedit import BTCAmountEdit, MyLineEdit, BTCkBEdit from network_dialog import NetworkDialog from qrcodewidget import QRCodeWidget, QRDialog -from qrtextedit import ScanQRTextEdit, ShowQRTextEdit +from qrtextedit import ShowQRTextEdit from transaction_dialog import show_transaction from installwizard import InstallWizard @@ -1568,6 +1568,13 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, PrintError): def paytomany(self): self.tabs.setCurrentIndex(1) self.payto_e.paytomany() + msg = '\n'.join([ + _('Enter a list of outputs in the \'Pay to\' field.'), + _('One output per line.'), + _('Format: address, amount'), + _('You may load a CSV file using the file icon.') + ]) + self.show_warning(msg, title=_('Pay to many')) def payto_contacts(self, labels): paytos = [self.get_contact_payto(label) for label in labels] @@ -2185,10 +2192,6 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, PrintError): layout.addLayout(hbox, 4, 1) d.exec_() - - def question(self, msg): - return QMessageBox.question(self, _('Message'), msg, QMessageBox.Yes | QMessageBox.No, QMessageBox.No) == QMessageBox.Yes - def password_dialog(self, msg=None, parent=None): if parent == None: parent = self @@ -2236,7 +2239,7 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, PrintError): from electrum import qrscanner try: data = qrscanner.scan_qr(self.config) - except BaseException as e: + except e: self.show_error(str(e)) return if not data: @@ -2526,10 +2529,10 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, PrintError): @protected def do_import_privkey(self, password): if not self.wallet.has_imported_keys(): - r = QMessageBox.question(None, _('Warning'), ''+_('Warning') +':\n
'+ _('Imported keys are not recoverable from seed.') + ' ' \ - + _('If you ever need to restore your wallet from its seed, these keys will be lost.') + '

' \ - + _('Are you sure you understand what you are doing?'), 3, 4) - if r == 4: return + if not self.question(''+_('Warning') +':\n
'+ _('Imported keys are not recoverable from seed.') + ' ' \ + + _('If you ever need to restore your wallet from its seed, these keys will be lost.') + '

' \ + + _('Are you sure you understand what you are doing?'), title=_('Warning')): + return text = text_dialog(self, _('Import private keys'), _("Enter private keys")+':', _("Import")) if not text: return diff --git a/gui/qt/paytoedit.py b/gui/qt/paytoedit.py index c1da6e0c1..0c654ea38 100644 --- a/gui/qt/paytoedit.py +++ b/gui/qt/paytoedit.py @@ -160,16 +160,8 @@ class PayToEdit(ScanQRTextEdit): return len(self.lines()) > 1 def paytomany(self): - from electrum.i18n import _ self.setText("\n\n\n") self.update_size() - msg = '\n'.join([ - _('Enter a list of outputs in the \'Pay to\' field.'), - _('One output per line.'), - _('Format: address, amount.'), - _('You may load a CSV file using the file icon.') - ]) - QMessageBox.warning(self, _('Pay to many'), msg, _('OK')) def update_size(self): docHeight = self.document().size().height() diff --git a/gui/qt/qrtextedit.py b/gui/qt/qrtextedit.py index 0d23e27a5..c46191926 100644 --- a/gui/qt/qrtextedit.py +++ b/gui/qt/qrtextedit.py @@ -3,7 +3,7 @@ from electrum.plugins import run_hook from PyQt4.QtGui import * from PyQt4.QtCore import * -from util import ButtonsTextEdit +from util import ButtonsTextEdit, MessageBoxMixin class ShowQRTextEdit(ButtonsTextEdit): @@ -29,7 +29,7 @@ class ShowQRTextEdit(ButtonsTextEdit): m.exec_(e.globalPos()) -class ScanQRTextEdit(ButtonsTextEdit): +class ScanQRTextEdit(ButtonsTextEdit, MessageBoxMixin): def __init__(self, text=""): ButtonsTextEdit.__init__(self, text) @@ -50,8 +50,8 @@ class ScanQRTextEdit(ButtonsTextEdit): from electrum import qrscanner, get_config try: data = qrscanner.scan_qr(get_config()) - except BaseException, e: - QMessageBox.warning(self, _('Error'), _(e), _('OK')) + except BaseException as e: + self.show_error(str(e)) return "" if type(data) != str: return diff --git a/gui/qt/transaction_dialog.py b/gui/qt/transaction_dialog.py index 8c1026c51..180ed2c6c 100644 --- a/gui/qt/transaction_dialog.py +++ b/gui/qt/transaction_dialog.py @@ -38,7 +38,7 @@ def show_transaction(tx, parent, desc=None, prompt_if_unsaved=False): dialogs.append(d) d.show() -class TxDialog(QDialog): +class TxDialog(QDialog, MessageBoxMixin): def __init__(self, tx, parent, desc, prompt_if_unsaved): '''Transactions in the wallet will show their description. @@ -122,10 +122,7 @@ class TxDialog(QDialog): def closeEvent(self, event): if (self.prompt_if_unsaved and not self.saved and not self.broadcast - and QMessageBox.question( - self, _('Warning'), - _('This transaction is not saved. Close anyway?'), - QMessageBox.Yes | QMessageBox.No) == QMessageBox.No): + and not self.question(_('This transaction is not saved. Close anyway?'), title=_("Warning"))): event.ignore() else: event.accept() @@ -291,8 +288,3 @@ class TxDialog(QDialog): cursor.insertText(format_amount(v), ext) cursor.insertBlock() vbox.addWidget(o_text) - - - - def show_message(self, msg): - QMessageBox.information(self, _('Message'), msg, _('OK')) diff --git a/gui/qt/util.py b/gui/qt/util.py index 3fa63681b..9ae383d33 100644 --- a/gui/qt/util.py +++ b/gui/qt/util.py @@ -193,18 +193,26 @@ class CancelButton(QPushButton): self.clicked.connect(dialog.reject) class MessageBoxMixin: + def question(self, msg, parent=None, title=None): + Yes, No = QMessageBox.Yes, QMessageBox.No + return WindowModalDialog.question(parent or self, title, msg, + buttons=Yes|No, + defaultButton=No) == Yes + def show_warning(self, msg, parent=None, title=None): - WindowModalDialog.warning(parent or self, title or _('Warning'), msg) + return WindowModalDialog.warning(parent or self, + title or _('Warning'), msg) def show_error(self, msg, parent=None): - self.show_warning(msg, parent=parent, title=_('Error')) + return self.show_warning(msg, parent=parent, title=_('Error')) def show_critical(self, msg, parent=None, title=None): - WindowModalDialog.critical(parent or self, - title or _('Critical Error'), msg) + return WindowModalDialog.critical(parent or self, + title or _('Critical Error'), msg) def show_message(self, msg, parent=None, title=None): - WindowModalDialog.information(self, title or _('Information'), msg) + return WindowModalDialog.information(self, title or _('Information'), + msg) class WindowModalDialog(QDialog): '''Handy wrapper; window modal dialogs are better for our multi-window @@ -215,6 +223,10 @@ class WindowModalDialog(QDialog): if title: self.setWindowTitle(title) + @staticmethod + def question(*args, **kwargs): + return WindowModalDialog.msg_box(QMessageBox.Question, *args, **kwargs) + @staticmethod def critical(*args, **kwargs): return WindowModalDialog.msg_box(QMessageBox.Critical, *args, **kwargs) diff --git a/lib/qrscanner.py b/lib/qrscanner.py index 419635c91..d38f7db77 100644 --- a/lib/qrscanner.py +++ b/lib/qrscanner.py @@ -12,7 +12,7 @@ proc = None def scan_qr(config): global proc if not zbar: - raise BaseException("\n".join([_("Cannot start QR scanner."),_("The zbar package is not available."),_("On Linux, try 'sudo pip install zbar'")])) + raise RuntimeError("\n".join([_("Cannot start QR scanner."),_("The zbar package is not available."),_("On Linux, try 'sudo pip install zbar'")])) if proc is None: device = config.get("video_device", "default") if device == 'default':