mirror of
https://github.com/LBRYFoundation/LBRY-Vault.git
synced 2025-08-28 16:01:30 +00:00
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
This commit is contained in:
parent
407e3514cc
commit
f6dfcccf8c
5 changed files with 71 additions and 46 deletions
|
@ -53,7 +53,7 @@ from electrum.logging import Logger
|
||||||
from .installwizard import InstallWizard, WalletAlreadyOpenInMemory
|
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 .main_window import ElectrumWindow
|
||||||
from .network_dialog import NetworkDialog
|
from .network_dialog import NetworkDialog
|
||||||
from .stylesheet_patcher import patch_qt_stylesheet
|
from .stylesheet_patcher import patch_qt_stylesheet
|
||||||
|
@ -227,8 +227,10 @@ class ElectrumGui(Logger):
|
||||||
wallet = self.daemon.load_wallet(path, None)
|
wallet = self.daemon.load_wallet(path, None)
|
||||||
except BaseException as e:
|
except BaseException as e:
|
||||||
self.logger.exception('')
|
self.logger.exception('')
|
||||||
QMessageBox.warning(None, _('Error'),
|
custom_message_box(icon=QMessageBox.Warning,
|
||||||
_('Cannot load wallet') + ' (1):\n' + str(e))
|
parent=None,
|
||||||
|
title=_('Error'),
|
||||||
|
text=_('Cannot load wallet') + ' (1):\n' + str(e))
|
||||||
# if app is starting, still let wizard to appear
|
# if app is starting, still let wizard to appear
|
||||||
if not app_is_starting:
|
if not app_is_starting:
|
||||||
return
|
return
|
||||||
|
@ -237,8 +239,10 @@ class ElectrumGui(Logger):
|
||||||
wallet = self._start_wizard_to_select_or_create_wallet(path)
|
wallet = self._start_wizard_to_select_or_create_wallet(path)
|
||||||
except (WalletFileException, BitcoinException) as e:
|
except (WalletFileException, BitcoinException) as e:
|
||||||
self.logger.exception('')
|
self.logger.exception('')
|
||||||
QMessageBox.warning(None, _('Error'),
|
custom_message_box(icon=QMessageBox.Warning,
|
||||||
_('Cannot load wallet') + ' (2):\n' + str(e))
|
parent=None,
|
||||||
|
title=_('Error'),
|
||||||
|
text=_('Cannot load wallet') + ' (2):\n' + str(e))
|
||||||
if not wallet:
|
if not wallet:
|
||||||
return
|
return
|
||||||
# create or raise window
|
# create or raise window
|
||||||
|
@ -250,8 +254,10 @@ class ElectrumGui(Logger):
|
||||||
window = self._create_window_for_wallet(wallet)
|
window = self._create_window_for_wallet(wallet)
|
||||||
except BaseException as e:
|
except BaseException as e:
|
||||||
self.logger.exception('')
|
self.logger.exception('')
|
||||||
QMessageBox.warning(None, _('Error'),
|
custom_message_box(icon=QMessageBox.Warning,
|
||||||
_('Cannot create window for wallet') + ':\n' + str(e))
|
parent=None,
|
||||||
|
title=_('Error'),
|
||||||
|
text=_('Cannot create window for wallet') + ':\n' + str(e))
|
||||||
if app_is_starting:
|
if app_is_starting:
|
||||||
wallet_dir = os.path.dirname(path)
|
wallet_dir = os.path.dirname(path)
|
||||||
path = os.path.join(wallet_dir, get_new_wallet_name(wallet_dir))
|
path = os.path.join(wallet_dir, get_new_wallet_name(wallet_dir))
|
||||||
|
|
|
@ -618,8 +618,8 @@ class HistoryList(MyTreeView, AcceptFileDragDrop):
|
||||||
if len(to_delete) > 1:
|
if len(to_delete) > 1:
|
||||||
question = (_("Are you sure you want to remove this transaction and {} child transactions?")
|
question = (_("Are you sure you want to remove this transaction and {} child transactions?")
|
||||||
.format(len(to_delete) - 1))
|
.format(len(to_delete) - 1))
|
||||||
answer = QMessageBox.question(self.parent, _("Please confirm"), question, QMessageBox.Yes, QMessageBox.No)
|
if not self.parent.question(msg=question,
|
||||||
if answer == QMessageBox.No:
|
title=_("Please confirm")):
|
||||||
return
|
return
|
||||||
for tx in to_delete:
|
for tx in to_delete:
|
||||||
self.wallet.remove_transaction(tx)
|
self.wallet.remove_transaction(tx)
|
||||||
|
|
|
@ -263,25 +263,24 @@ class InstallWizard(QDialog, MessageBoxMixin, BaseWizard):
|
||||||
self.temp_storage.decrypt(password)
|
self.temp_storage.decrypt(password)
|
||||||
break
|
break
|
||||||
except InvalidPassword as e:
|
except InvalidPassword as e:
|
||||||
QMessageBox.information(None, _('Error'), str(e))
|
self.show_message(title=_('Error'), msg=str(e))
|
||||||
continue
|
continue
|
||||||
except BaseException as e:
|
except BaseException as e:
|
||||||
self.logger.exception('')
|
self.logger.exception('')
|
||||||
QMessageBox.information(None, _('Error'), str(e))
|
self.show_message(title=_('Error'), msg=str(e))
|
||||||
raise UserCancelled()
|
raise UserCancelled()
|
||||||
elif self.temp_storage.is_encrypted_with_hw_device():
|
elif self.temp_storage.is_encrypted_with_hw_device():
|
||||||
try:
|
try:
|
||||||
self.run('choose_hw_device', HWD_SETUP_DECRYPT_WALLET, storage=self.temp_storage)
|
self.run('choose_hw_device', HWD_SETUP_DECRYPT_WALLET, storage=self.temp_storage)
|
||||||
except InvalidPassword as e:
|
except InvalidPassword as e:
|
||||||
QMessageBox.information(
|
self.show_message(title=_('Error'),
|
||||||
None, _('Error'),
|
msg=_('Failed to decrypt using this hardware device.') + '\n' +
|
||||||
_('Failed to decrypt using this hardware device.') + '\n' +
|
_('If you use a passphrase, make sure it is correct.'))
|
||||||
_('If you use a passphrase, make sure it is correct.'))
|
|
||||||
self.reset_stack()
|
self.reset_stack()
|
||||||
return self.select_storage(path, get_wallet_from_daemon)
|
return self.select_storage(path, get_wallet_from_daemon)
|
||||||
except BaseException as e:
|
except BaseException as e:
|
||||||
self.logger.exception('')
|
self.logger.exception('')
|
||||||
QMessageBox.information(None, _('Error'), str(e))
|
self.show_message(title=_('Error'), msg=str(e))
|
||||||
raise UserCancelled()
|
raise UserCancelled()
|
||||||
if self.temp_storage.is_past_initial_decryption():
|
if self.temp_storage.is_past_initial_decryption():
|
||||||
break
|
break
|
||||||
|
@ -290,7 +289,7 @@ class InstallWizard(QDialog, MessageBoxMixin, BaseWizard):
|
||||||
else:
|
else:
|
||||||
raise Exception('Unexpected encryption version')
|
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):
|
def run_upgrades(self, storage):
|
||||||
path = storage.path
|
path = storage.path
|
||||||
|
|
|
@ -239,13 +239,10 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger):
|
||||||
|
|
||||||
# If the option hasn't been set yet
|
# If the option hasn't been set yet
|
||||||
if config.get('check_updates') is None:
|
if config.get('check_updates') is None:
|
||||||
choice = QMessageBox.question(self,
|
choice = self.question(title="Electrum - " + _("Enable update check"),
|
||||||
"Electrum - " + _("Enable update check"),
|
msg=_("For security reasons we advise that you always use the latest version of Electrum.") + " " +
|
||||||
_("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?"))
|
||||||
_("Would you like to be notified when there is a newer version of Electrum available?"),
|
config.set_key('check_updates', bool(choice), save=True)
|
||||||
QMessageBox.Yes,
|
|
||||||
QMessageBox.No)
|
|
||||||
config.set_key('check_updates', choice == QMessageBox.Yes, save=True)
|
|
||||||
|
|
||||||
if config.get('check_updates', False):
|
if config.get('check_updates', False):
|
||||||
# The references to both the thread and the window need to be stored somewhere
|
# 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' +
|
_("You can disable this setting in '{}'.").format(_('Preferences')) + '\n' +
|
||||||
_('Also, dust is not kept as change, but added to the fee.') + '\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.'))
|
_('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 = QPushButton(read_QIcon('info.png'), '')
|
||||||
self.feerounding_icon.setFixedWidth(20)
|
self.feerounding_icon.setFixedWidth(20)
|
||||||
|
|
|
@ -103,7 +103,10 @@ class HelpLabel(QLabel):
|
||||||
self.font = QFont()
|
self.font = QFont()
|
||||||
|
|
||||||
def mouseReleaseEvent(self, x):
|
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):
|
def enterEvent(self, event):
|
||||||
self.font.setUnderline(True)
|
self.font.setUnderline(True)
|
||||||
|
@ -127,7 +130,10 @@ class HelpButton(QPushButton):
|
||||||
self.clicked.connect(self.onclick)
|
self.clicked.connect(self.onclick)
|
||||||
|
|
||||||
def onclick(self):
|
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):
|
class InfoButton(QPushButton):
|
||||||
|
@ -139,7 +145,10 @@ class InfoButton(QPushButton):
|
||||||
self.clicked.connect(self.onclick)
|
self.clicked.connect(self.onclick)
|
||||||
|
|
||||||
def onclick(self):
|
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):
|
class Buttons(QHBoxLayout):
|
||||||
|
@ -217,26 +226,40 @@ class MessageBoxMixin(object):
|
||||||
return self.msg_box(QMessageBox.Information, parent,
|
return self.msg_box(QMessageBox.Information, parent,
|
||||||
title or _('Information'), msg, **kwargs)
|
title or _('Information'), msg, **kwargs)
|
||||||
|
|
||||||
def msg_box(self, icon, parent, title, text, buttons=QMessageBox.Ok,
|
def msg_box(self, icon, parent, title, text, *, buttons=QMessageBox.Ok,
|
||||||
defaultButton=QMessageBox.NoButton, *, rich_text=False,
|
defaultButton=QMessageBox.NoButton, rich_text=False,
|
||||||
checkbox=None):
|
checkbox=None):
|
||||||
parent = parent or self.top_level_window()
|
parent = parent or self.top_level_window()
|
||||||
if type(icon) is QPixmap:
|
return custom_message_box(icon=icon,
|
||||||
d = QMessageBox(QMessageBox.Information, title, str(text), buttons, parent)
|
parent=parent,
|
||||||
d.setIconPixmap(icon)
|
title=title,
|
||||||
else:
|
text=text,
|
||||||
d = QMessageBox(icon, title, str(text), buttons, parent)
|
buttons=buttons,
|
||||||
d.setWindowModality(Qt.WindowModal)
|
defaultButton=defaultButton,
|
||||||
d.setDefaultButton(defaultButton)
|
rich_text=rich_text,
|
||||||
if rich_text:
|
checkbox=checkbox)
|
||||||
d.setTextInteractionFlags(Qt.TextSelectableByMouse| Qt.LinksAccessibleByMouse)
|
|
||||||
d.setTextFormat(Qt.RichText)
|
|
||||||
else:
|
def custom_message_box(*, icon, parent, title, text, buttons=QMessageBox.Ok,
|
||||||
d.setTextInteractionFlags(Qt.TextSelectableByMouse)
|
defaultButton=QMessageBox.NoButton, rich_text=False,
|
||||||
d.setTextFormat(Qt.PlainText)
|
checkbox=None):
|
||||||
if checkbox is not None:
|
if type(icon) is QPixmap:
|
||||||
d.setCheckBox(checkbox)
|
d = QMessageBox(QMessageBox.Information, title, str(text), buttons, parent)
|
||||||
return d.exec_()
|
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):
|
class WindowModalDialog(QDialog, MessageBoxMixin):
|
||||||
'''Handy wrapper; window modal dialogs are better for our multi-window
|
'''Handy wrapper; window modal dialogs are better for our multi-window
|
||||||
|
|
Loading…
Add table
Reference in a new issue