commit f6dfcccf8c056db0fe1ad52a2676a474deb349a1
parent 407e3514cc705caf25d807c5933b1b638d1e832f
Author: SomberNight <somber.night@protonmail.com>
Date: Mon, 13 May 2019 23:59:29 +0200
qt: factor out util.MessageBoxMixin.msg_box into function and use it
so these dialogs also get our custom default settings applied,
e.g. their text is selectable by mouse
Diffstat:
5 files changed, 71 insertions(+), 46 deletions(-)
diff --git a/electrum/gui/qt/__init__.py b/electrum/gui/qt/__init__.py
@@ -53,7 +53,7 @@ from electrum.logging import Logger
from .installwizard import InstallWizard, WalletAlreadyOpenInMemory
-from .util import get_default_language, read_QIcon, ColorScheme
+from .util import get_default_language, read_QIcon, ColorScheme, custom_message_box
from .main_window import ElectrumWindow
from .network_dialog import NetworkDialog
from .stylesheet_patcher import patch_qt_stylesheet
@@ -227,8 +227,10 @@ class ElectrumGui(Logger):
wallet = self.daemon.load_wallet(path, None)
except BaseException as e:
self.logger.exception('')
- QMessageBox.warning(None, _('Error'),
- _('Cannot load wallet') + ' (1):\n' + str(e))
+ custom_message_box(icon=QMessageBox.Warning,
+ parent=None,
+ title=_('Error'),
+ text=_('Cannot load wallet') + ' (1):\n' + str(e))
# if app is starting, still let wizard to appear
if not app_is_starting:
return
@@ -237,8 +239,10 @@ class ElectrumGui(Logger):
wallet = self._start_wizard_to_select_or_create_wallet(path)
except (WalletFileException, BitcoinException) as e:
self.logger.exception('')
- QMessageBox.warning(None, _('Error'),
- _('Cannot load wallet') + ' (2):\n' + str(e))
+ custom_message_box(icon=QMessageBox.Warning,
+ parent=None,
+ title=_('Error'),
+ text=_('Cannot load wallet') + ' (2):\n' + str(e))
if not wallet:
return
# create or raise window
@@ -250,8 +254,10 @@ class ElectrumGui(Logger):
window = self._create_window_for_wallet(wallet)
except BaseException as e:
self.logger.exception('')
- QMessageBox.warning(None, _('Error'),
- _('Cannot create window for wallet') + ':\n' + str(e))
+ custom_message_box(icon=QMessageBox.Warning,
+ parent=None,
+ title=_('Error'),
+ text=_('Cannot create window for wallet') + ':\n' + str(e))
if app_is_starting:
wallet_dir = os.path.dirname(path)
path = os.path.join(wallet_dir, get_new_wallet_name(wallet_dir))
diff --git a/electrum/gui/qt/history_list.py b/electrum/gui/qt/history_list.py
@@ -618,8 +618,8 @@ class HistoryList(MyTreeView, AcceptFileDragDrop):
if len(to_delete) > 1:
question = (_("Are you sure you want to remove this transaction and {} child transactions?")
.format(len(to_delete) - 1))
- answer = QMessageBox.question(self.parent, _("Please confirm"), question, QMessageBox.Yes, QMessageBox.No)
- if answer == QMessageBox.No:
+ if not self.parent.question(msg=question,
+ title=_("Please confirm")):
return
for tx in to_delete:
self.wallet.remove_transaction(tx)
diff --git a/electrum/gui/qt/installwizard.py b/electrum/gui/qt/installwizard.py
@@ -263,25 +263,24 @@ class InstallWizard(QDialog, MessageBoxMixin, BaseWizard):
self.temp_storage.decrypt(password)
break
except InvalidPassword as e:
- QMessageBox.information(None, _('Error'), str(e))
+ self.show_message(title=_('Error'), msg=str(e))
continue
except BaseException as e:
self.logger.exception('')
- QMessageBox.information(None, _('Error'), str(e))
+ self.show_message(title=_('Error'), msg=str(e))
raise UserCancelled()
elif self.temp_storage.is_encrypted_with_hw_device():
try:
self.run('choose_hw_device', HWD_SETUP_DECRYPT_WALLET, storage=self.temp_storage)
except InvalidPassword as e:
- QMessageBox.information(
- None, _('Error'),
- _('Failed to decrypt using this hardware device.') + '\n' +
- _('If you use a passphrase, make sure it is correct.'))
+ self.show_message(title=_('Error'),
+ msg=_('Failed to decrypt using this hardware device.') + '\n' +
+ _('If you use a passphrase, make sure it is correct.'))
self.reset_stack()
return self.select_storage(path, get_wallet_from_daemon)
except BaseException as e:
self.logger.exception('')
- QMessageBox.information(None, _('Error'), str(e))
+ self.show_message(title=_('Error'), msg=str(e))
raise UserCancelled()
if self.temp_storage.is_past_initial_decryption():
break
@@ -290,7 +289,7 @@ class InstallWizard(QDialog, MessageBoxMixin, BaseWizard):
else:
raise Exception('Unexpected encryption version')
- return self.temp_storage.path, (self.temp_storage if self.temp_storage.file_exists() else None)
+ return self.temp_storage.path, (self.temp_storage if self.temp_storage.file_exists() else None) #
def run_upgrades(self, storage):
path = storage.path
diff --git a/electrum/gui/qt/main_window.py b/electrum/gui/qt/main_window.py
@@ -239,13 +239,10 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger):
# If the option hasn't been set yet
if config.get('check_updates') is None:
- choice = QMessageBox.question(self,
- "Electrum - " + _("Enable update check"),
- _("For security reasons we advise that you always use the latest version of Electrum.") + " " +
- _("Would you like to be notified when there is a newer version of Electrum available?"),
- QMessageBox.Yes,
- QMessageBox.No)
- config.set_key('check_updates', choice == QMessageBox.Yes, save=True)
+ choice = self.question(title="Electrum - " + _("Enable update check"),
+ msg=_("For security reasons we advise that you always use the latest version of Electrum.") + " " +
+ _("Would you like to be notified when there is a newer version of Electrum available?"))
+ config.set_key('check_updates', bool(choice), save=True)
if config.get('check_updates', False):
# The references to both the thread and the window need to be stored somewhere
@@ -1282,7 +1279,7 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger):
_("You can disable this setting in '{}'.").format(_('Preferences')) + '\n' +
_('Also, dust is not kept as change, but added to the fee.') + '\n' +
_('Also, when batching RBF transactions, BIP 125 imposes a lower bound on the fee.'))
- QMessageBox.information(self, 'Fee rounding', text)
+ self.show_message(title=_('Fee rounding'), msg=text)
self.feerounding_icon = QPushButton(read_QIcon('info.png'), '')
self.feerounding_icon.setFixedWidth(20)
diff --git a/electrum/gui/qt/util.py b/electrum/gui/qt/util.py
@@ -103,7 +103,10 @@ class HelpLabel(QLabel):
self.font = QFont()
def mouseReleaseEvent(self, x):
- QMessageBox.information(self, 'Help', self.help_text)
+ custom_message_box(icon=QMessageBox.Information,
+ parent=self,
+ title=_('Help'),
+ text=self.help_text)
def enterEvent(self, event):
self.font.setUnderline(True)
@@ -127,7 +130,10 @@ class HelpButton(QPushButton):
self.clicked.connect(self.onclick)
def onclick(self):
- QMessageBox.information(self, 'Help', self.help_text)
+ custom_message_box(icon=QMessageBox.Information,
+ parent=self,
+ title=_('Help'),
+ text=self.help_text)
class InfoButton(QPushButton):
@@ -139,7 +145,10 @@ class InfoButton(QPushButton):
self.clicked.connect(self.onclick)
def onclick(self):
- QMessageBox.information(self, 'Info', self.help_text)
+ custom_message_box(icon=QMessageBox.Information,
+ parent=self,
+ title=_('Info'),
+ text=self.help_text)
class Buttons(QHBoxLayout):
@@ -217,26 +226,40 @@ class MessageBoxMixin(object):
return self.msg_box(QMessageBox.Information, parent,
title or _('Information'), msg, **kwargs)
- def msg_box(self, icon, parent, title, text, buttons=QMessageBox.Ok,
- defaultButton=QMessageBox.NoButton, *, rich_text=False,
+ def msg_box(self, icon, parent, title, text, *, buttons=QMessageBox.Ok,
+ defaultButton=QMessageBox.NoButton, rich_text=False,
checkbox=None):
parent = parent or self.top_level_window()
- if type(icon) is QPixmap:
- d = QMessageBox(QMessageBox.Information, title, str(text), buttons, parent)
- d.setIconPixmap(icon)
- else:
- d = QMessageBox(icon, title, str(text), buttons, parent)
- d.setWindowModality(Qt.WindowModal)
- d.setDefaultButton(defaultButton)
- if rich_text:
- d.setTextInteractionFlags(Qt.TextSelectableByMouse| Qt.LinksAccessibleByMouse)
- d.setTextFormat(Qt.RichText)
- else:
- d.setTextInteractionFlags(Qt.TextSelectableByMouse)
- d.setTextFormat(Qt.PlainText)
- if checkbox is not None:
- d.setCheckBox(checkbox)
- return d.exec_()
+ return custom_message_box(icon=icon,
+ parent=parent,
+ title=title,
+ text=text,
+ buttons=buttons,
+ defaultButton=defaultButton,
+ rich_text=rich_text,
+ checkbox=checkbox)
+
+
+def custom_message_box(*, icon, parent, title, text, buttons=QMessageBox.Ok,
+ defaultButton=QMessageBox.NoButton, rich_text=False,
+ checkbox=None):
+ if type(icon) is QPixmap:
+ d = QMessageBox(QMessageBox.Information, title, str(text), buttons, parent)
+ d.setIconPixmap(icon)
+ else:
+ d = QMessageBox(icon, title, str(text), buttons, parent)
+ d.setWindowModality(Qt.WindowModal)
+ d.setDefaultButton(defaultButton)
+ if rich_text:
+ d.setTextInteractionFlags(Qt.TextSelectableByMouse | Qt.LinksAccessibleByMouse)
+ d.setTextFormat(Qt.RichText)
+ else:
+ d.setTextInteractionFlags(Qt.TextSelectableByMouse)
+ d.setTextFormat(Qt.PlainText)
+ if checkbox is not None:
+ d.setCheckBox(checkbox)
+ return d.exec_()
+
class WindowModalDialog(QDialog, MessageBoxMixin):
'''Handy wrapper; window modal dialogs are better for our multi-window