electrum

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

commit 0ecf2565ce484ab0d79cf902f417a3fb6307f6d1
parent 8bcd13242309d5888c92c7a03db60a42f6573446
Author: Neil Booth <kyuupichan@gmail.com>
Date:   Wed, 23 Dec 2015 20:05:09 +0900

MessageBoxMixin-related cleanup

Diffstat:
Mgui/qt/__init__.py | 6+++---
Mgui/qt/installwizard.py | 20++------------------
Mgui/qt/util.py | 58+++++++++++++++++++++-------------------------------------
3 files changed, 26 insertions(+), 58 deletions(-)

diff --git a/gui/qt/__init__.py b/gui/qt/__init__.py @@ -64,7 +64,7 @@ class OpenFileEventFilter(QObject): -class ElectrumGui: +class ElectrumGui(MessageBoxMixin): def __init__(self, config, network, plugins): set_language(config.get('language')) @@ -134,7 +134,7 @@ class ElectrumGui: try: storage = WalletStorage(filename) except Exception as e: - WindowModalDialog.warning(None, _('Error'), str(e)) + self.show_error(str(e)) return if not storage.file_exists: recent = self.config.get('recently_open', []) @@ -147,7 +147,7 @@ class ElectrumGui: wallet = Wallet(storage) except BaseException as e: traceback.print_exc(file=sys.stdout) - WindowModalDialog.warning(None, _('Warning'), str(e)) + self.show_warning(str(e)) return action = wallet.get_action() # run wizard diff --git a/gui/qt/installwizard.py b/gui/qt/installwizard.py @@ -384,22 +384,6 @@ class InstallWizard(WindowModalDialog, MessageBoxMixin): wallet_type = '%dof%d'%(m,n) return wallet_type - def question(self, msg, yes_label=_('OK'), no_label=_('Cancel'), icon=None): - vbox = QVBoxLayout() - self.set_layout(vbox) - if icon: - logo = QLabel() - logo.setPixmap(icon) - vbox.addWidget(logo) - label = QLabel(msg) - label.setWordWrap(True) - vbox.addWidget(label) - vbox.addStretch(1) - vbox.addLayout(Buttons(CancelButton(self, no_label), OkButton(self, yes_label))) - if not self.exec_(): - return None - return True - def show_seed(self, seed, sid): vbox = seed_dialog.show_seed_box_msg(seed, sid) vbox.addLayout(Buttons(CancelButton(self), OkButton(self, _("Next")))) @@ -418,8 +402,8 @@ class InstallWizard(WindowModalDialog, MessageBoxMixin): path = self.storage.path msg = _("The file '%s' contains an incompletely created wallet.\n" "Do you want to complete its creation now?") % path - if not question(msg): - if question(_("Do you want to delete '%s'?") % path): + if not self.question(msg): + if self.question(_("Do you want to delete '%s'?") % path): os.remove(path) self.show_warning(_('The file was removed')) return diff --git a/gui/qt/util.py b/gui/qt/util.py @@ -195,24 +195,35 @@ class CancelButton(QPushButton): 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 + return self.msg_box(QMessageBox.Question, parent or self, title or '', + msg, buttons=Yes|No, defaultButton=No) == Yes def show_warning(self, msg, parent=None, title=None): - return WindowModalDialog.warning(parent or self, - title or _('Warning'), msg) + return self.msg_box(QMessageBox.Warning, parent or self, + title or _('Warning'), msg) def show_error(self, msg, parent=None): - return self.show_warning(msg, parent=parent, title=_('Error')) + return self.msg_box(QMessageBox.Warning, parent or self, + _('Error'), msg) def show_critical(self, msg, parent=None, title=None): - return WindowModalDialog.critical(parent or self, - title or _('Critical Error'), msg) + return self.msg_box(QMessageBox.Critical, parent or self, + title or _('Critical Error'), msg) def show_message(self, msg, parent=None, title=None): - return WindowModalDialog.information(self, title or _('Information'), - msg) + return self.msg_box(QMessageBox.Information, parent or self, + title or _('Information'), msg) + + @staticmethod + def msg_box(icon, parent, title, text, buttons=QMessageBox.Ok, + defaultButton=QMessageBox.NoButton): + # handle e.g. ElectrumGui + if not isinstance(parent, QWidget): + parent = None + d = QMessageBox(icon, title, text, buttons, parent) + d.setWindowModality(Qt.WindowModal) + d.setDefaultButton(defaultButton) + return d.exec_() class WindowModalDialog(QDialog): '''Handy wrapper; window modal dialogs are better for our multi-window @@ -223,30 +234,6 @@ 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) - - @staticmethod - 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): - d = QMessageBox(icon, title, text, buttons, parent) - d.setWindowModality(Qt.WindowModal) - d.setDefaultButton(defaultButton) - return d.exec_() - def line_dialog(parent, title, label, ok_label, default=None): dialog = WindowModalDialog(parent, title) dialog.setMinimumWidth(500) @@ -276,9 +263,6 @@ def text_dialog(parent, title, label, ok_label, default=None): if dialog.exec_(): return unicode(txt.toPlainText()) -def question(msg): - return QMessageBox.question(None, _('Message'), msg, QMessageBox.Yes | QMessageBox.No, QMessageBox.No) == QMessageBox.Yes - def address_field(addresses): hbox = QHBoxLayout() address_e = QLineEdit()