Fix a bunch more modality issues for message boxes
This commit is contained in:
parent
0a3a0f12cc
commit
57d4b27696
|
@ -284,14 +284,17 @@ class ElectrumWindow(QMainWindow, PrintError):
|
||||||
except:
|
except:
|
||||||
self.setGeometry(100, 100, 840, 400)
|
self.setGeometry(100, 100, 840, 400)
|
||||||
self.show()
|
self.show()
|
||||||
|
self.warn_if_watching_only()
|
||||||
|
run_hook('load_wallet', wallet, self)
|
||||||
|
|
||||||
|
def warn_if_watching_only(self):
|
||||||
if self.wallet.is_watching_only():
|
if self.wallet.is_watching_only():
|
||||||
msg = ' '.join([
|
msg = ' '.join([
|
||||||
_("This wallet is watching-only."),
|
_("This wallet is watching-only."),
|
||||||
_("This means you will not be able to spend Bitcoins with it."),
|
_("This means you will not be able to spend Bitcoins with it."),
|
||||||
_("Make sure you own the seed phrase or the private keys, before you request Bitcoins to be sent to this wallet.")
|
_("Make sure you own the seed phrase or the private keys, before you request Bitcoins to be sent to this wallet.")
|
||||||
])
|
])
|
||||||
QMessageBox.warning(self, _('Information'), msg, _('OK'))
|
self.show_warning(msg, title=_('Information'))
|
||||||
run_hook('load_wallet', wallet, self)
|
|
||||||
|
|
||||||
def import_old_contacts(self):
|
def import_old_contacts(self):
|
||||||
# backward compatibility: import contacts
|
# backward compatibility: import contacts
|
||||||
|
@ -766,7 +769,7 @@ class ElectrumWindow(QMainWindow, PrintError):
|
||||||
try:
|
try:
|
||||||
self.wallet.sign_payment_request(addr, alias, alias_addr, password)
|
self.wallet.sign_payment_request(addr, alias, alias_addr, password)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
QMessageBox.warning(self, _('Error'), str(e), _('OK'))
|
self.show_error(str(e))
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
return
|
return
|
||||||
|
@ -779,7 +782,7 @@ class ElectrumWindow(QMainWindow, PrintError):
|
||||||
amount = self.receive_amount_e.get_amount()
|
amount = self.receive_amount_e.get_amount()
|
||||||
message = unicode(self.receive_message_e.text())
|
message = unicode(self.receive_message_e.text())
|
||||||
if not message and not amount:
|
if not message and not amount:
|
||||||
QMessageBox.warning(self, _('Error'), _('No message or amount'), _('OK'))
|
self.show_error(_('No message or amount'))
|
||||||
return False
|
return False
|
||||||
i = self.expires_combo.currentIndex()
|
i = self.expires_combo.currentIndex()
|
||||||
expiration = map(lambda x: x[1], expiration_values)[i]
|
expiration = map(lambda x: x[1], expiration_values)[i]
|
||||||
|
@ -1150,7 +1153,7 @@ class ElectrumWindow(QMainWindow, PrintError):
|
||||||
self.wallet.check_password(password)
|
self.wallet.check_password(password)
|
||||||
break
|
break
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
QMessageBox.warning(parent, _('Error'), str(e), _('OK'))
|
self.show_error(str(e), parent=parent)
|
||||||
continue
|
continue
|
||||||
else:
|
else:
|
||||||
password = None
|
password = None
|
||||||
|
@ -1161,7 +1164,7 @@ class ElectrumWindow(QMainWindow, PrintError):
|
||||||
|
|
||||||
def read_send_tab(self):
|
def read_send_tab(self):
|
||||||
if self.payment_request and self.payment_request.has_expired():
|
if self.payment_request and self.payment_request.has_expired():
|
||||||
QMessageBox.warning(self, _('Error'), _('Payment request has expired'), _('OK'))
|
self.show_error(_('Payment request has expired'))
|
||||||
return
|
return
|
||||||
label = unicode( self.message_e.text() )
|
label = unicode( self.message_e.text() )
|
||||||
|
|
||||||
|
@ -1182,23 +1185,23 @@ class ElectrumWindow(QMainWindow, PrintError):
|
||||||
return
|
return
|
||||||
|
|
||||||
if not outputs:
|
if not outputs:
|
||||||
QMessageBox.warning(self, _('Error'), _('No outputs'), _('OK'))
|
self.show_error(_('No outputs'))
|
||||||
return
|
return
|
||||||
|
|
||||||
for _type, addr, amount in outputs:
|
for _type, addr, amount in outputs:
|
||||||
if addr is None:
|
if addr is None:
|
||||||
QMessageBox.warning(self, _('Error'), _('Bitcoin Address is None'), _('OK'))
|
self.show_error(_('Bitcoin Address is None'))
|
||||||
return
|
return
|
||||||
if _type == 'address' and not bitcoin.is_address(addr):
|
if _type == 'address' and not bitcoin.is_address(addr):
|
||||||
QMessageBox.warning(self, _('Error'), _('Invalid Bitcoin Address'), _('OK'))
|
self.show_error(_('Invalid Bitcoin Address'))
|
||||||
return
|
return
|
||||||
if amount is None:
|
if amount is None:
|
||||||
QMessageBox.warning(self, _('Error'), _('Invalid Amount'), _('OK'))
|
self.show_error(_('Invalid Amount'))
|
||||||
return
|
return
|
||||||
|
|
||||||
fee = self.fee_e.get_amount()
|
fee = self.fee_e.get_amount()
|
||||||
if fee is None:
|
if fee is None:
|
||||||
QMessageBox.warning(self, _('Error'), _('Invalid Fee'), _('OK'))
|
self.show_error(_('Invalid Fee'))
|
||||||
return
|
return
|
||||||
|
|
||||||
coins = self.get_coins()
|
coins = self.get_coins()
|
||||||
|
@ -1224,7 +1227,7 @@ class ElectrumWindow(QMainWindow, PrintError):
|
||||||
return
|
return
|
||||||
|
|
||||||
if tx.get_fee() < MIN_RELAY_TX_FEE and tx.requires_fee(self.wallet):
|
if tx.get_fee() < MIN_RELAY_TX_FEE and tx.requires_fee(self.wallet):
|
||||||
QMessageBox.warning(self, _('Error'), _("This transaction requires a higher fee, or it will not be propagated by the network."), _('OK'))
|
self.show_error(_("This transaction requires a higher fee, or it will not be propagated by the network"))
|
||||||
return
|
return
|
||||||
|
|
||||||
if self.show_before_broadcast():
|
if self.show_before_broadcast():
|
||||||
|
@ -1321,7 +1324,7 @@ class ElectrumWindow(QMainWindow, PrintError):
|
||||||
self.invoices_list.update()
|
self.invoices_list.update()
|
||||||
self.do_clear()
|
self.do_clear()
|
||||||
else:
|
else:
|
||||||
QMessageBox.warning(parent, _('Error'), msg, _('OK'))
|
self.show_error(msg, parent=parent)
|
||||||
self.send_button.setDisabled(False)
|
self.send_button.setDisabled(False)
|
||||||
|
|
||||||
if parent == None:
|
if parent == None:
|
||||||
|
@ -1380,7 +1383,7 @@ class ElectrumWindow(QMainWindow, PrintError):
|
||||||
try:
|
try:
|
||||||
out = util.parse_URI(unicode(URI), self.on_pr)
|
out = util.parse_URI(unicode(URI), self.on_pr)
|
||||||
except BaseException as e:
|
except BaseException as e:
|
||||||
QMessageBox.warning(self, _('Error'), _('Invalid bitcoin URI:') + '\n' + str(e), _('OK'))
|
self.show_error(_('Invalid bitcoin URI:') + '\n' + str(e))
|
||||||
return
|
return
|
||||||
self.tabs.setCurrentIndex(1)
|
self.tabs.setCurrentIndex(1)
|
||||||
r = out.get('r')
|
r = out.get('r')
|
||||||
|
@ -1590,7 +1593,7 @@ class ElectrumWindow(QMainWindow, PrintError):
|
||||||
|
|
||||||
def set_contact(self, label, address):
|
def set_contact(self, label, address):
|
||||||
if not is_valid(address):
|
if not is_valid(address):
|
||||||
QMessageBox.warning(self, _('Error'), _('Invalid Address'), _('OK'))
|
self.show_error(_('Invalid Address'))
|
||||||
self.contacts_list.update() # Displays original unchanged value
|
self.contacts_list.update() # Displays original unchanged value
|
||||||
return False
|
return False
|
||||||
self.contacts[label] = ('address', address)
|
self.contacts[label] = ('address', address)
|
||||||
|
@ -1976,7 +1979,7 @@ class ElectrumWindow(QMainWindow, PrintError):
|
||||||
try:
|
try:
|
||||||
mnemonic = self.wallet.get_mnemonic(password)
|
mnemonic = self.wallet.get_mnemonic(password)
|
||||||
except BaseException as e:
|
except BaseException as e:
|
||||||
QMessageBox.warning(self, _('Error'), str(e), _('OK'))
|
self.show_error(str(e))
|
||||||
return
|
return
|
||||||
from seed_dialog import SeedDialog
|
from seed_dialog import SeedDialog
|
||||||
d = SeedDialog(self, mnemonic, self.wallet.has_imported_keys())
|
d = SeedDialog(self, mnemonic, self.wallet.has_imported_keys())
|
||||||
|
@ -2160,8 +2163,11 @@ class ElectrumWindow(QMainWindow, PrintError):
|
||||||
def show_message(self, msg):
|
def show_message(self, msg):
|
||||||
QMessageBox.information(self, _('Message'), msg, _('OK'))
|
QMessageBox.information(self, _('Message'), msg, _('OK'))
|
||||||
|
|
||||||
def show_warning(self, msg):
|
def show_warning(self, msg, parent=None, title=None):
|
||||||
QMessageBox.warning(self, _('Warning'), msg, _('OK'))
|
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 password_dialog(self, msg=None, parent=None):
|
def password_dialog(self, msg=None, parent=None):
|
||||||
if parent == None:
|
if parent == None:
|
||||||
|
@ -2219,8 +2225,8 @@ class ElectrumWindow(QMainWindow, PrintError):
|
||||||
from electrum import qrscanner
|
from electrum import qrscanner
|
||||||
try:
|
try:
|
||||||
data = qrscanner.scan_qr(self.config)
|
data = qrscanner.scan_qr(self.config)
|
||||||
except BaseException, e:
|
except BaseException as e:
|
||||||
QMessageBox.warning(self, _('Error'), _(e), _('OK'))
|
self.show_error(str(e))
|
||||||
return
|
return
|
||||||
if not data:
|
if not data:
|
||||||
return
|
return
|
||||||
|
@ -2286,7 +2292,7 @@ class ElectrumWindow(QMainWindow, PrintError):
|
||||||
try:
|
try:
|
||||||
self.wallet.check_password(password)
|
self.wallet.check_password(password)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
QMessageBox.warning(self, _('Error'), str(e), _('OK'))
|
self.show_error(str(e))
|
||||||
return
|
return
|
||||||
|
|
||||||
d = WindowModalDialog(self, _('Private keys'))
|
d = WindowModalDialog(self, _('Private keys'))
|
||||||
|
@ -2494,15 +2500,12 @@ class ElectrumWindow(QMainWindow, PrintError):
|
||||||
if not d.exec_():
|
if not d.exec_():
|
||||||
return
|
return
|
||||||
|
|
||||||
if self.wallet.is_watching_only():
|
|
||||||
if not self.question(_("Warning: this wallet is watching only. You will be UNABLE to spend the swept funds directly. Continue only if you have access to the private keys in another way.\n\nAre you SURE you want to sweep?")):
|
|
||||||
return
|
|
||||||
|
|
||||||
fee = self.wallet.fee_per_kb(self.config)
|
fee = self.wallet.fee_per_kb(self.config)
|
||||||
tx = Transaction.sweep(get_pk(), self.network, get_address(), fee)
|
tx = Transaction.sweep(get_pk(), self.network, get_address(), fee)
|
||||||
if not tx:
|
if not tx:
|
||||||
self.show_message(_('No inputs found. (Note that inputs need to be confirmed)'))
|
self.show_message(_('No inputs found. (Note that inputs need to be confirmed)'))
|
||||||
return
|
return
|
||||||
|
self.warn_if_watching_only()
|
||||||
self.show_transaction(tx)
|
self.show_transaction(tx)
|
||||||
|
|
||||||
|
|
||||||
|
@ -2809,13 +2812,11 @@ class ElectrumWindow(QMainWindow, PrintError):
|
||||||
|
|
||||||
run_hook('close_settings_dialog')
|
run_hook('close_settings_dialog')
|
||||||
if self.need_restart:
|
if self.need_restart:
|
||||||
QMessageBox.warning(self, _('Success'), _('Please restart Electrum to activate the new GUI settings'), _('OK'))
|
self.show_warning(_('Please restart Electrum to activate the new GUI settings'), title=_('Success'))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def run_network_dialog(self):
|
def run_network_dialog(self):
|
||||||
if not self.network:
|
if not self.network:
|
||||||
QMessageBox.warning(self, _('Offline'), _('You are using Electrum in offline mode.\nRestart Electrum if you want to get connected.'), _('OK'))
|
self.show_warning(_('You are using Electrum in offline mode; restart Electrum if you want to get connected'), title=_('Offline'))
|
||||||
return
|
return
|
||||||
NetworkDialog(self.wallet.network, self.config, self).do_exec()
|
NetworkDialog(self.wallet.network, self.config, self).do_exec()
|
||||||
|
|
||||||
|
|
|
@ -201,6 +201,18 @@ class WindowModalDialog(QDialog):
|
||||||
if title:
|
if title:
|
||||||
self.setWindowTitle(title)
|
self.setWindowTitle(title)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def warning(*args, **kwargs):
|
||||||
|
return WindowModalDialog.msg_box(QMessageBox.Warning, *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)
|
||||||
|
|
Loading…
Reference in New Issue