Move message box logic to a mixin
This commit is contained in:
parent
72fdf0cd21
commit
15e9991e2a
|
@ -62,7 +62,7 @@ class CosignWidget(QWidget):
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class InstallWizard(WindowModalDialog):
|
class InstallWizard(WindowModalDialog, MessageBoxMixin):
|
||||||
|
|
||||||
def __init__(self, app, config, network, storage):
|
def __init__(self, app, config, network, storage):
|
||||||
title = 'Electrum' + ' - ' + _('Install Wizard')
|
title = 'Electrum' + ' - ' + _('Install Wizard')
|
||||||
|
@ -157,7 +157,7 @@ class InstallWizard(WindowModalDialog):
|
||||||
if not r:
|
if not r:
|
||||||
return
|
return
|
||||||
if prepare_seed(r) != prepare_seed(seed):
|
if prepare_seed(r) != prepare_seed(seed):
|
||||||
QMessageBox.warning(None, _('Error'), _('Incorrect seed'), _('OK'))
|
self.show_error(_('Incorrect seed'))
|
||||||
return False
|
return False
|
||||||
else:
|
else:
|
||||||
return True
|
return True
|
||||||
|
@ -421,8 +421,7 @@ class InstallWizard(WindowModalDialog):
|
||||||
if not question(msg):
|
if not question(msg):
|
||||||
if question(_("Do you want to delete '%s'?") % path):
|
if question(_("Do you want to delete '%s'?") % path):
|
||||||
os.remove(path)
|
os.remove(path)
|
||||||
QMessageBox.information(self, _('Warning'),
|
self.show_warning(_('The file was removed'))
|
||||||
_('The file was removed'), _('OK'))
|
|
||||||
return
|
return
|
||||||
return
|
return
|
||||||
self.show()
|
self.show()
|
||||||
|
@ -434,7 +433,7 @@ class InstallWizard(WindowModalDialog):
|
||||||
wallet = self.run_wallet_type(action, wallet_type)
|
wallet = self.run_wallet_type(action, wallet_type)
|
||||||
except BaseException as e:
|
except BaseException as e:
|
||||||
traceback.print_exc(file=sys.stdout)
|
traceback.print_exc(file=sys.stdout)
|
||||||
QMessageBox.information(None, _('Error'), str(e), _('OK'))
|
self.show_error(str(e))
|
||||||
return
|
return
|
||||||
return wallet
|
return wallet
|
||||||
|
|
||||||
|
@ -527,7 +526,7 @@ class InstallWizard(WindowModalDialog):
|
||||||
if self.config.get('server') is None:
|
if self.config.get('server') is None:
|
||||||
self.network_dialog()
|
self.network_dialog()
|
||||||
else:
|
else:
|
||||||
QMessageBox.information(None, _('Warning'), _('You are offline'), _('OK'))
|
self.show_warning(_('You are offline'))
|
||||||
|
|
||||||
|
|
||||||
# start wallet threads
|
# start wallet threads
|
||||||
|
@ -539,7 +538,7 @@ class InstallWizard(WindowModalDialog):
|
||||||
msg = _("Recovery successful") if wallet.is_found() else _("No transactions found for this seed")
|
msg = _("Recovery successful") if wallet.is_found() else _("No transactions found for this seed")
|
||||||
else:
|
else:
|
||||||
msg = _("This wallet was restored offline. It may contain more addresses than displayed.")
|
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
|
return wallet
|
||||||
|
|
||||||
|
|
|
@ -102,7 +102,7 @@ expiration_values = [
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class ElectrumWindow(QMainWindow, PrintError):
|
class ElectrumWindow(QMainWindow, MessageBoxMixin, PrintError):
|
||||||
|
|
||||||
def __init__(self, gui_object, wallet):
|
def __init__(self, gui_object, wallet):
|
||||||
QMainWindow.__init__(self)
|
QMainWindow.__init__(self)
|
||||||
|
@ -338,7 +338,7 @@ class ElectrumWindow(QMainWindow, PrintError):
|
||||||
if new_path != path:
|
if new_path != path:
|
||||||
try:
|
try:
|
||||||
shutil.copy2(path, new_path)
|
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:
|
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"))
|
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."),
|
_("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.")
|
_("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):
|
def notify_transactions(self):
|
||||||
if not self.network or not self.network.is_connected():
|
if not self.network or not self.network.is_connected():
|
||||||
|
@ -1318,7 +1318,7 @@ class ElectrumWindow(QMainWindow, PrintError):
|
||||||
if status:
|
if status:
|
||||||
if tx_desc is not None and tx.is_complete():
|
if tx_desc is not None and tx.is_complete():
|
||||||
self.wallet.set_label(tx.hash(), tx_desc)
|
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.invoices_list.update()
|
||||||
self.do_clear()
|
self.do_clear()
|
||||||
else:
|
else:
|
||||||
|
@ -1971,7 +1971,7 @@ class ElectrumWindow(QMainWindow, PrintError):
|
||||||
@protected
|
@protected
|
||||||
def show_seed_dialog(self, password):
|
def show_seed_dialog(self, password):
|
||||||
if not self.wallet.has_seed():
|
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
|
return
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -2158,19 +2158,6 @@ class ElectrumWindow(QMainWindow, PrintError):
|
||||||
def question(self, msg):
|
def question(self, msg):
|
||||||
return QMessageBox.question(self, _('Message'), msg, QMessageBox.Yes | QMessageBox.No, QMessageBox.No) == QMessageBox.Yes
|
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):
|
def password_dialog(self, msg=None, parent=None):
|
||||||
if parent == None:
|
if parent == None:
|
||||||
parent = self
|
parent = self
|
||||||
|
@ -2376,7 +2363,7 @@ class ElectrumWindow(QMainWindow, PrintError):
|
||||||
f.close()
|
f.close()
|
||||||
for key, value in json.loads(data).items():
|
for key, value in json.loads(data).items():
|
||||||
self.wallet.set_label(key, value)
|
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:
|
except (IOError, os.error) as reason:
|
||||||
self.show_critical(_("Electrum was unable to import your labels.") + "\n" + str(reason))
|
self.show_critical(_("Electrum was unable to import your labels.") + "\n" + str(reason))
|
||||||
|
|
||||||
|
@ -2388,7 +2375,7 @@ class ElectrumWindow(QMainWindow, PrintError):
|
||||||
if fileName:
|
if fileName:
|
||||||
with open(fileName, 'w+') as f:
|
with open(fileName, 'w+') as f:
|
||||||
json.dump(labels, 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:
|
except (IOError, os.error), reason:
|
||||||
self.show_critical(_("Electrum was unable to export your labels.") + "\n" + str(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.")
|
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"))
|
self.show_critical(export_error_label + "\n" + str(reason), title=_("Unable to export history"))
|
||||||
return
|
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):
|
def do_export_history(self, wallet, fileName, is_csv):
|
||||||
|
@ -2530,7 +2517,7 @@ class ElectrumWindow(QMainWindow, PrintError):
|
||||||
else:
|
else:
|
||||||
addrlist.append(addr)
|
addrlist.append(addr)
|
||||||
if addrlist:
|
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:
|
if badkeys:
|
||||||
self.show_critical(_("The following inputs could not be imported") + ':\n'+ '\n'.join(badkeys))
|
self.show_critical(_("The following inputs could not be imported") + ':\n'+ '\n'.join(badkeys))
|
||||||
self.address_list.update()
|
self.address_list.update()
|
||||||
|
|
|
@ -192,6 +192,20 @@ class CancelButton(QPushButton):
|
||||||
QPushButton.__init__(self, label or _("Cancel"))
|
QPushButton.__init__(self, label or _("Cancel"))
|
||||||
self.clicked.connect(dialog.reject)
|
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):
|
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
|
||||||
daemon model as other wallet windows can still be accessed.'''
|
daemon model as other wallet windows can still be accessed.'''
|
||||||
|
@ -209,6 +223,10 @@ class WindowModalDialog(QDialog):
|
||||||
def warning(*args, **kwargs):
|
def warning(*args, **kwargs):
|
||||||
return WindowModalDialog.msg_box(QMessageBox.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
|
@staticmethod
|
||||||
def msg_box(icon, parent, title, text, buttons=QMessageBox.Ok,
|
def msg_box(icon, parent, title, text, buttons=QMessageBox.Ok,
|
||||||
defaultButton=QMessageBox.NoButton):
|
defaultButton=QMessageBox.NoButton):
|
||||||
|
|
|
@ -2,7 +2,6 @@ from PyQt4.Qt import QApplication, QMessageBox, QDialog, QInputDialog, QLineEdit
|
||||||
import PyQt4.QtCore as QtCore
|
import PyQt4.QtCore as QtCore
|
||||||
import threading
|
import threading
|
||||||
|
|
||||||
from electrum_gui.qt.password_dialog import make_password_dialog, run_password_dialog
|
|
||||||
from electrum.plugins import BasePlugin, hook
|
from electrum.plugins import BasePlugin, hook
|
||||||
|
|
||||||
from ledger import LedgerPlugin
|
from ledger import LedgerPlugin
|
||||||
|
|
|
@ -194,7 +194,3 @@ class Plugin(TrezorPlugin):
|
||||||
layout.addWidget(current_label_label,3,0)
|
layout.addWidget(current_label_label,3,0)
|
||||||
layout.addWidget(change_label_button,3,1)
|
layout.addWidget(change_label_button,3,1)
|
||||||
d.exec_()
|
d.exec_()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue