URI: 
       tMove message box logic to a mixin - electrum - Electrum Bitcoin wallet
  HTML git clone https://git.parazyd.org/electrum
   DIR Log
   DIR Files
   DIR Refs
   DIR Submodules
       ---
   DIR commit 15e9991e2afdbe4bf1fd8d5fbd7a20fba91c489c
   DIR parent 72fdf0cd216c39cc59927bb0f63066432bcd4426
  HTML Author: Neil Booth <kyuupichan@gmail.com>
       Date:   Wed, 23 Dec 2015 15:10:15 +0900
       
       Move message box logic to a mixin
       
       Diffstat:
         M gui/qt/installwizard.py             |      13 ++++++-------
         M gui/qt/main_window.py               |      31 +++++++++----------------------
         M gui/qt/util.py                      |      18 ++++++++++++++++++
         M plugins/ledger/qt.py                |       1 -
         M plugins/trezor/qt.py                |       4 ----
       
       5 files changed, 33 insertions(+), 34 deletions(-)
       ---
   DIR diff --git a/gui/qt/installwizard.py b/gui/qt/installwizard.py
       t@@ -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')
       t@@ -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
       t@@ -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()
       t@@ -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
        
       t@@ -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
       t@@ -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
        
   DIR diff --git a/gui/qt/main_window.py b/gui/qt/main_window.py
       t@@ -102,7 +102,7 @@ expiration_values = [
        
        
        
       -class ElectrumWindow(QMainWindow, PrintError):
       +class ElectrumWindow(QMainWindow, MessageBoxMixin, PrintError):
        
            def __init__(self, gui_object, wallet):
                QMainWindow.__init__(self)
       t@@ -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"))
        
       t@@ -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():
       t@@ -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:
       t@@ -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:
       t@@ -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
       t@@ -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))
        
       t@@ -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))
        
       t@@ -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):
       t@@ -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()
   DIR diff --git a/gui/qt/util.py b/gui/qt/util.py
       t@@ -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.'''
       t@@ -210,6 +224,10 @@ class WindowModalDialog(QDialog):
                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):
                d = QMessageBox(icon, title, text, buttons, parent)
   DIR diff --git a/plugins/ledger/qt.py b/plugins/ledger/qt.py
       t@@ -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
   DIR diff --git a/plugins/trezor/qt.py b/plugins/trezor/qt.py
       t@@ -194,7 +194,3 @@ class Plugin(TrezorPlugin):
                layout.addWidget(current_label_label,3,0)
                layout.addWidget(change_label_button,3,1)
                d.exec_()
       -
       -
       -
       -