diff --git a/gui/qt/installwizard.py b/gui/qt/installwizard.py index 03619bb88..a54a47de1 100644 --- a/gui/qt/installwizard.py +++ b/gui/qt/installwizard.py @@ -62,7 +62,7 @@ class CosignWidget(QWidget): -class InstallWizard(WindowModalDialog): +class InstallWizard(WindowModalDialog, MessageBoxMixin): def __init__(self, app, config, network, storage): title = 'Electrum' + ' - ' + _('Install Wizard') @@ -157,7 +157,7 @@ class InstallWizard(WindowModalDialog): if not r: return if prepare_seed(r) != prepare_seed(seed): - QMessageBox.warning(None, _('Error'), _('Incorrect seed'), _('OK')) + self.show_error(_('Incorrect seed')) return False else: return True @@ -421,8 +421,7 @@ class InstallWizard(WindowModalDialog): if not question(msg): if question(_("Do you want to delete '%s'?") % path): os.remove(path) - QMessageBox.information(self, _('Warning'), - _('The file was removed'), _('OK')) + self.show_warning(_('The file was removed')) return return self.show() @@ -434,7 +433,7 @@ class InstallWizard(WindowModalDialog): wallet = self.run_wallet_type(action, wallet_type) except BaseException as e: traceback.print_exc(file=sys.stdout) - QMessageBox.information(None, _('Error'), str(e), _('OK')) + self.show_error(str(e)) return return wallet @@ -527,7 +526,7 @@ class InstallWizard(WindowModalDialog): if self.config.get('server') is None: self.network_dialog() else: - QMessageBox.information(None, _('Warning'), _('You are offline'), _('OK')) + self.show_warning(_('You are offline')) # start wallet threads @@ -539,7 +538,7 @@ class InstallWizard(WindowModalDialog): msg = _("Recovery successful") if wallet.is_found() else _("No transactions found for this seed") else: msg = _("This wallet was restored offline. It may contain more addresses than displayed.") - QMessageBox.information(None, _('Information'), msg, _('OK')) + self.show_message(msg) return wallet diff --git a/gui/qt/main_window.py b/gui/qt/main_window.py index 6771fe235..a65fa358f 100644 --- a/gui/qt/main_window.py +++ b/gui/qt/main_window.py @@ -102,7 +102,7 @@ expiration_values = [ -class ElectrumWindow(QMainWindow, PrintError): +class ElectrumWindow(QMainWindow, MessageBoxMixin, PrintError): def __init__(self, gui_object, wallet): QMainWindow.__init__(self) @@ -338,7 +338,7 @@ class ElectrumWindow(QMainWindow, PrintError): if new_path != path: try: shutil.copy2(path, new_path) - QMessageBox.information(None,"Wallet backup created", _("A copy of your wallet file was created in")+" '%s'" % str(new_path)) + self.show_message(_("A copy of your wallet file was created in")+" '%s'" % str(new_path), title=_("Wallet backup created")) except (IOError, os.error), reason: self.show_critical(_("Electrum was unable to copy your wallet file to the specified location.") + "\n" + str(reason), title=_("Unable to create backup")) @@ -458,7 +458,7 @@ class ElectrumWindow(QMainWindow, PrintError): _("Before reporting a bug, upgrade to the most recent version of Electrum (latest release or git HEAD), and include the version number in your report."), _("Try to explain not only what the bug is, but how it occurs.") ]) - QMessageBox.information(self, "Electrum - " + _("Reporting Bugs"), msg) + self.show_message(msg, title="Electrum - " + _("Reporting Bugs")) def notify_transactions(self): if not self.network or not self.network.is_connected(): @@ -1318,7 +1318,7 @@ class ElectrumWindow(QMainWindow, PrintError): if status: if tx_desc is not None and tx.is_complete(): self.wallet.set_label(tx.hash(), tx_desc) - QMessageBox.information(parent, '', _('Payment sent.') + '\n' + msg, _('OK')) + self.show_message(_('Payment sent.') + '\n' + msg, parent=parent) self.invoices_list.update() self.do_clear() else: @@ -1971,7 +1971,7 @@ class ElectrumWindow(QMainWindow, PrintError): @protected def show_seed_dialog(self, password): if not self.wallet.has_seed(): - QMessageBox.information(self, _('Message'), _('This wallet has no seed'), _('OK')) + self.show_message(_('This wallet has no seed')) return try: @@ -2158,19 +2158,6 @@ class ElectrumWindow(QMainWindow, PrintError): def question(self, msg): return QMessageBox.question(self, _('Message'), msg, QMessageBox.Yes | QMessageBox.No, QMessageBox.No) == QMessageBox.Yes - def show_message(self, msg): - QMessageBox.information(self, _('Message'), msg, _('OK')) - - def show_warning(self, msg, parent=None, title=None): - WindowModalDialog.warning(parent or self, title or _('Warning'), msg) - - def show_error(self, msg, parent=None): - 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) - def password_dialog(self, msg=None, parent=None): if parent == None: parent = self @@ -2376,7 +2363,7 @@ class ElectrumWindow(QMainWindow, PrintError): f.close() for key, value in json.loads(data).items(): self.wallet.set_label(key, value) - QMessageBox.information(None, _("Labels imported"), _("Your labels were imported from")+" '%s'" % str(labelsFile)) + self.show_message(_("Your labels were imported from") + " '%s'" % str(labelsFile)) except (IOError, os.error) as reason: self.show_critical(_("Electrum was unable to import your labels.") + "\n" + str(reason)) @@ -2388,7 +2375,7 @@ class ElectrumWindow(QMainWindow, PrintError): if fileName: with open(fileName, 'w+') as f: json.dump(labels, f) - QMessageBox.information(None, _("Labels exported"), _("Your labels where exported to")+" '%s'" % str(fileName)) + self.show_message(_("Your labels where exported to") + " '%s'" % str(fileName)) except (IOError, os.error), reason: self.show_critical(_("Electrum was unable to export your labels.") + "\n" + str(reason)) @@ -2417,7 +2404,7 @@ class ElectrumWindow(QMainWindow, PrintError): export_error_label = _("Electrum was unable to produce a transaction export.") self.show_critical(export_error_label + "\n" + str(reason), title=_("Unable to export history")) return - QMessageBox.information(self,_("History exported"), _("Your wallet history has been successfully exported.")) + self.show_message(_("Your wallet history has been successfully exported.")) def do_export_history(self, wallet, fileName, is_csv): @@ -2530,7 +2517,7 @@ class ElectrumWindow(QMainWindow, PrintError): else: addrlist.append(addr) if addrlist: - QMessageBox.information(self, _('Information'), _("The following addresses were added") + ':\n' + '\n'.join(addrlist)) + self.show_message(_("The following addresses were added") + ':\n' + '\n'.join(addrlist)) if badkeys: self.show_critical(_("The following inputs could not be imported") + ':\n'+ '\n'.join(badkeys)) self.address_list.update() diff --git a/gui/qt/util.py b/gui/qt/util.py index de43ef0c2..3fa63681b 100644 --- a/gui/qt/util.py +++ b/gui/qt/util.py @@ -192,6 +192,20 @@ class CancelButton(QPushButton): QPushButton.__init__(self, label or _("Cancel")) self.clicked.connect(dialog.reject) +class MessageBoxMixin: + def show_warning(self, msg, parent=None, title=None): + WindowModalDialog.warning(parent or self, title or _('Warning'), msg) + + def show_error(self, msg, parent=None): + 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) + + def show_message(self, msg, parent=None, title=None): + WindowModalDialog.information(self, title or _('Information'), msg) + class WindowModalDialog(QDialog): '''Handy wrapper; window modal dialogs are better for our multi-window daemon model as other wallet windows can still be accessed.''' @@ -209,6 +223,10 @@ class WindowModalDialog(QDialog): def warning(*args, **kwargs): return WindowModalDialog.msg_box(QMessageBox.Warning, *args, **kwargs) + @staticmethod + def information(*args, **kwargs): + return WindowModalDialog.msg_box(QMessageBox.Information, *args, **kwargs) + @staticmethod def msg_box(icon, parent, title, text, buttons=QMessageBox.Ok, defaultButton=QMessageBox.NoButton): diff --git a/plugins/ledger/qt.py b/plugins/ledger/qt.py index ec46c116f..d05d22dfd 100644 --- a/plugins/ledger/qt.py +++ b/plugins/ledger/qt.py @@ -2,7 +2,6 @@ from PyQt4.Qt import QApplication, QMessageBox, QDialog, QInputDialog, QLineEdit import PyQt4.QtCore as QtCore import threading -from electrum_gui.qt.password_dialog import make_password_dialog, run_password_dialog from electrum.plugins import BasePlugin, hook from ledger import LedgerPlugin diff --git a/plugins/trezor/qt.py b/plugins/trezor/qt.py index 2d62a4c7e..0926b331b 100644 --- a/plugins/trezor/qt.py +++ b/plugins/trezor/qt.py @@ -194,7 +194,3 @@ class Plugin(TrezorPlugin): layout.addWidget(current_label_label,3,0) layout.addWidget(change_label_button,3,1) d.exec_() - - - -