Browse Source

MessageBoxMixin-related cleanup

283
Neil Booth 9 years ago
parent
commit
0ecf2565ce
  1. 6
      gui/qt/__init__.py
  2. 20
      gui/qt/installwizard.py
  3. 54
      gui/qt/util.py

6
gui/qt/__init__.py

@ -64,7 +64,7 @@ class OpenFileEventFilter(QObject):
class ElectrumGui: class ElectrumGui(MessageBoxMixin):
def __init__(self, config, network, plugins): def __init__(self, config, network, plugins):
set_language(config.get('language')) set_language(config.get('language'))
@ -134,7 +134,7 @@ class ElectrumGui:
try: try:
storage = WalletStorage(filename) storage = WalletStorage(filename)
except Exception as e: except Exception as e:
WindowModalDialog.warning(None, _('Error'), str(e)) self.show_error(str(e))
return return
if not storage.file_exists: if not storage.file_exists:
recent = self.config.get('recently_open', []) recent = self.config.get('recently_open', [])
@ -147,7 +147,7 @@ class ElectrumGui:
wallet = Wallet(storage) wallet = Wallet(storage)
except BaseException as e: except BaseException as e:
traceback.print_exc(file=sys.stdout) traceback.print_exc(file=sys.stdout)
WindowModalDialog.warning(None, _('Warning'), str(e)) self.show_warning(str(e))
return return
action = wallet.get_action() action = wallet.get_action()
# run wizard # run wizard

20
gui/qt/installwizard.py

@ -384,22 +384,6 @@ class InstallWizard(WindowModalDialog, MessageBoxMixin):
wallet_type = '%dof%d'%(m,n) wallet_type = '%dof%d'%(m,n)
return wallet_type 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): def show_seed(self, seed, sid):
vbox = seed_dialog.show_seed_box_msg(seed, sid) vbox = seed_dialog.show_seed_box_msg(seed, sid)
vbox.addLayout(Buttons(CancelButton(self), OkButton(self, _("Next")))) vbox.addLayout(Buttons(CancelButton(self), OkButton(self, _("Next"))))
@ -418,8 +402,8 @@ class InstallWizard(WindowModalDialog, MessageBoxMixin):
path = self.storage.path path = self.storage.path
msg = _("The file '%s' contains an incompletely created wallet.\n" msg = _("The file '%s' contains an incompletely created wallet.\n"
"Do you want to complete its creation now?") % path "Do you want to complete its creation now?") % path
if not question(msg): if not self.question(msg):
if question(_("Do you want to delete '%s'?") % path): if self.question(_("Do you want to delete '%s'?") % path):
os.remove(path) os.remove(path)
self.show_warning(_('The file was removed')) self.show_warning(_('The file was removed'))
return return

54
gui/qt/util.py

@ -195,24 +195,35 @@ class CancelButton(QPushButton):
class MessageBoxMixin: class MessageBoxMixin:
def question(self, msg, parent=None, title=None): def question(self, msg, parent=None, title=None):
Yes, No = QMessageBox.Yes, QMessageBox.No Yes, No = QMessageBox.Yes, QMessageBox.No
return WindowModalDialog.question(parent or self, title, msg, return self.msg_box(QMessageBox.Question, parent or self, title or '',
buttons=Yes|No, msg, buttons=Yes|No, defaultButton=No) == Yes
defaultButton=No) == Yes
def show_warning(self, msg, parent=None, title=None): def show_warning(self, msg, parent=None, title=None):
return WindowModalDialog.warning(parent or self, return self.msg_box(QMessageBox.Warning, parent or self,
title or _('Warning'), msg) title or _('Warning'), msg)
def show_error(self, msg, parent=None): 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): def show_critical(self, msg, parent=None, title=None):
return WindowModalDialog.critical(parent or self, return self.msg_box(QMessageBox.Critical, parent or self,
title or _('Critical Error'), msg) title or _('Critical Error'), msg)
def show_message(self, msg, parent=None, title=None): def show_message(self, msg, parent=None, title=None):
return WindowModalDialog.information(self, title or _('Information'), return self.msg_box(QMessageBox.Information, parent or self,
msg) 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): class WindowModalDialog(QDialog):
'''Handy wrapper; window modal dialogs are better for our multi-window '''Handy wrapper; window modal dialogs are better for our multi-window
@ -223,30 +234,6 @@ class WindowModalDialog(QDialog):
if title: if title:
self.setWindowTitle(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): def line_dialog(parent, title, label, ok_label, default=None):
dialog = WindowModalDialog(parent, title) dialog = WindowModalDialog(parent, title)
dialog.setMinimumWidth(500) dialog.setMinimumWidth(500)
@ -276,9 +263,6 @@ def text_dialog(parent, title, label, ok_label, default=None):
if dialog.exec_(): if dialog.exec_():
return unicode(txt.toPlainText()) 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): def address_field(addresses):
hbox = QHBoxLayout() hbox = QHBoxLayout()
address_e = QLineEdit() address_e = QLineEdit()

Loading…
Cancel
Save