More modality fixes and cleanups

This commit is contained in:
Neil Booth 2015-12-23 18:31:36 +09:00
parent 37b474716b
commit 9484b6371f
6 changed files with 37 additions and 38 deletions

View File

@ -48,7 +48,7 @@ from electrum import Imported_Wallet, paymentrequest
from amountedit import BTCAmountEdit, MyLineEdit, BTCkBEdit from amountedit import BTCAmountEdit, MyLineEdit, BTCkBEdit
from network_dialog import NetworkDialog from network_dialog import NetworkDialog
from qrcodewidget import QRCodeWidget, QRDialog from qrcodewidget import QRCodeWidget, QRDialog
from qrtextedit import ScanQRTextEdit, ShowQRTextEdit from qrtextedit import ShowQRTextEdit
from transaction_dialog import show_transaction from transaction_dialog import show_transaction
from installwizard import InstallWizard from installwizard import InstallWizard
@ -1568,6 +1568,13 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, PrintError):
def paytomany(self): def paytomany(self):
self.tabs.setCurrentIndex(1) self.tabs.setCurrentIndex(1)
self.payto_e.paytomany() self.payto_e.paytomany()
msg = '\n'.join([
_('Enter a list of outputs in the \'Pay to\' field.'),
_('One output per line.'),
_('Format: address, amount'),
_('You may load a CSV file using the file icon.')
])
self.show_warning(msg, title=_('Pay to many'))
def payto_contacts(self, labels): def payto_contacts(self, labels):
paytos = [self.get_contact_payto(label) for label in labels] paytos = [self.get_contact_payto(label) for label in labels]
@ -2185,10 +2192,6 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, PrintError):
layout.addLayout(hbox, 4, 1) layout.addLayout(hbox, 4, 1)
d.exec_() d.exec_()
def question(self, msg):
return QMessageBox.question(self, _('Message'), msg, QMessageBox.Yes | QMessageBox.No, QMessageBox.No) == QMessageBox.Yes
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
@ -2236,7 +2239,7 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, 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 as e: except e:
self.show_error(str(e)) self.show_error(str(e))
return return
if not data: if not data:
@ -2526,10 +2529,10 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, PrintError):
@protected @protected
def do_import_privkey(self, password): def do_import_privkey(self, password):
if not self.wallet.has_imported_keys(): if not self.wallet.has_imported_keys():
r = QMessageBox.question(None, _('Warning'), '<b>'+_('Warning') +':\n</b><br/>'+ _('Imported keys are not recoverable from seed.') + ' ' \ if not self.question('<b>'+_('Warning') +':\n</b><br/>'+ _('Imported keys are not recoverable from seed.') + ' ' \
+ _('If you ever need to restore your wallet from its seed, these keys will be lost.') + '<p>' \ + _('If you ever need to restore your wallet from its seed, these keys will be lost.') + '<p>' \
+ _('Are you sure you understand what you are doing?'), 3, 4) + _('Are you sure you understand what you are doing?'), title=_('Warning')):
if r == 4: return return
text = text_dialog(self, _('Import private keys'), _("Enter private keys")+':', _("Import")) text = text_dialog(self, _('Import private keys'), _("Enter private keys")+':', _("Import"))
if not text: return if not text: return

View File

@ -160,16 +160,8 @@ class PayToEdit(ScanQRTextEdit):
return len(self.lines()) > 1 return len(self.lines()) > 1
def paytomany(self): def paytomany(self):
from electrum.i18n import _
self.setText("\n\n\n") self.setText("\n\n\n")
self.update_size() self.update_size()
msg = '\n'.join([
_('Enter a list of outputs in the \'Pay to\' field.'),
_('One output per line.'),
_('Format: address, amount.'),
_('You may load a CSV file using the file icon.')
])
QMessageBox.warning(self, _('Pay to many'), msg, _('OK'))
def update_size(self): def update_size(self):
docHeight = self.document().size().height() docHeight = self.document().size().height()

View File

@ -3,7 +3,7 @@ from electrum.plugins import run_hook
from PyQt4.QtGui import * from PyQt4.QtGui import *
from PyQt4.QtCore import * from PyQt4.QtCore import *
from util import ButtonsTextEdit from util import ButtonsTextEdit, MessageBoxMixin
class ShowQRTextEdit(ButtonsTextEdit): class ShowQRTextEdit(ButtonsTextEdit):
@ -29,7 +29,7 @@ class ShowQRTextEdit(ButtonsTextEdit):
m.exec_(e.globalPos()) m.exec_(e.globalPos())
class ScanQRTextEdit(ButtonsTextEdit): class ScanQRTextEdit(ButtonsTextEdit, MessageBoxMixin):
def __init__(self, text=""): def __init__(self, text=""):
ButtonsTextEdit.__init__(self, text) ButtonsTextEdit.__init__(self, text)
@ -50,8 +50,8 @@ class ScanQRTextEdit(ButtonsTextEdit):
from electrum import qrscanner, get_config from electrum import qrscanner, get_config
try: try:
data = qrscanner.scan_qr(get_config()) data = qrscanner.scan_qr(get_config())
except BaseException, e: except BaseException as e:
QMessageBox.warning(self, _('Error'), _(e), _('OK')) self.show_error(str(e))
return "" return ""
if type(data) != str: if type(data) != str:
return return

View File

@ -38,7 +38,7 @@ def show_transaction(tx, parent, desc=None, prompt_if_unsaved=False):
dialogs.append(d) dialogs.append(d)
d.show() d.show()
class TxDialog(QDialog): class TxDialog(QDialog, MessageBoxMixin):
def __init__(self, tx, parent, desc, prompt_if_unsaved): def __init__(self, tx, parent, desc, prompt_if_unsaved):
'''Transactions in the wallet will show their description. '''Transactions in the wallet will show their description.
@ -122,10 +122,7 @@ class TxDialog(QDialog):
def closeEvent(self, event): def closeEvent(self, event):
if (self.prompt_if_unsaved and not self.saved and not self.broadcast if (self.prompt_if_unsaved and not self.saved and not self.broadcast
and QMessageBox.question( and not self.question(_('This transaction is not saved. Close anyway?'), title=_("Warning"))):
self, _('Warning'),
_('This transaction is not saved. Close anyway?'),
QMessageBox.Yes | QMessageBox.No) == QMessageBox.No):
event.ignore() event.ignore()
else: else:
event.accept() event.accept()
@ -291,8 +288,3 @@ class TxDialog(QDialog):
cursor.insertText(format_amount(v), ext) cursor.insertText(format_amount(v), ext)
cursor.insertBlock() cursor.insertBlock()
vbox.addWidget(o_text) vbox.addWidget(o_text)
def show_message(self, msg):
QMessageBox.information(self, _('Message'), msg, _('OK'))

View File

@ -193,18 +193,26 @@ class CancelButton(QPushButton):
self.clicked.connect(dialog.reject) self.clicked.connect(dialog.reject)
class MessageBoxMixin: class MessageBoxMixin:
def question(self, msg, parent=None, title=None):
Yes, No = QMessageBox.Yes, QMessageBox.No
return WindowModalDialog.question(parent or self, title, msg,
buttons=Yes|No,
defaultButton=No) == Yes
def show_warning(self, msg, parent=None, title=None): def show_warning(self, msg, parent=None, title=None):
WindowModalDialog.warning(parent or self, title or _('Warning'), msg) return WindowModalDialog.warning(parent or self,
title or _('Warning'), msg)
def show_error(self, msg, parent=None): def show_error(self, msg, parent=None):
self.show_warning(msg, parent=parent, title=_('Error')) return self.show_warning(msg, parent=parent, title=_('Error'))
def show_critical(self, msg, parent=None, title=None): def show_critical(self, msg, parent=None, title=None):
WindowModalDialog.critical(parent or self, return WindowModalDialog.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):
WindowModalDialog.information(self, title or _('Information'), msg) return 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
@ -215,6 +223,10 @@ 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 @staticmethod
def critical(*args, **kwargs): def critical(*args, **kwargs):
return WindowModalDialog.msg_box(QMessageBox.Critical, *args, **kwargs) return WindowModalDialog.msg_box(QMessageBox.Critical, *args, **kwargs)

View File

@ -12,7 +12,7 @@ proc = None
def scan_qr(config): def scan_qr(config):
global proc global proc
if not zbar: if not zbar:
raise BaseException("\n".join([_("Cannot start QR scanner."),_("The zbar package is not available."),_("On Linux, try 'sudo pip install zbar'")])) raise RuntimeError("\n".join([_("Cannot start QR scanner."),_("The zbar package is not available."),_("On Linux, try 'sudo pip install zbar'")]))
if proc is None: if proc is None:
device = config.get("video_device", "default") device = config.get("video_device", "default")
if device == 'default': if device == 'default':