Sorted things out with validation of NewChanDialog
This commit is contained in:
parent
512bb41a03
commit
59049f8e8b
|
@ -1,4 +1,4 @@
|
||||||
from qtpy import QtGui, QtWidgets
|
from qtpy import QtGui
|
||||||
from Queue import Empty
|
from Queue import Empty
|
||||||
|
|
||||||
from addresses import decodeAddress, addBMIfNotPresent
|
from addresses import decodeAddress, addBMIfNotPresent
|
||||||
|
@ -13,17 +13,16 @@ from debug import logger
|
||||||
class AddressPassPhraseValidatorMixin(object):
|
class AddressPassPhraseValidatorMixin(object):
|
||||||
def setParams(
|
def setParams(
|
||||||
self, passPhraseObject=None, addressObject=None,
|
self, passPhraseObject=None, addressObject=None,
|
||||||
feedBackObject=None, buttonBox=None, addressMandatory=True
|
feedBackObject=None, button=None, addressMandatory=True
|
||||||
):
|
):
|
||||||
self.addressObject = addressObject
|
self.addressObject = addressObject
|
||||||
self.passPhraseObject = passPhraseObject
|
self.passPhraseObject = passPhraseObject
|
||||||
self.feedBackObject = feedBackObject
|
self.feedBackObject = feedBackObject
|
||||||
self.buttonBox = buttonBox
|
|
||||||
self.addressMandatory = addressMandatory
|
self.addressMandatory = addressMandatory
|
||||||
self.isValid = False
|
self.isValid = False
|
||||||
# save default text
|
# save default text
|
||||||
self.okButton = self.buttonBox.button(QtWidgets.QDialogButtonBox.Ok)
|
self.okButton = button
|
||||||
self.okButtonLabel = self.okButton.text()
|
self.okButtonLabel = button.text()
|
||||||
|
|
||||||
def setError(self, string):
|
def setError(self, string):
|
||||||
if string is not None and self.feedBackObject is not None:
|
if string is not None and self.feedBackObject is not None:
|
||||||
|
@ -33,7 +32,7 @@ class AddressPassPhraseValidatorMixin(object):
|
||||||
self.feedBackObject.setStyleSheet("QLabel { color : red; }")
|
self.feedBackObject.setStyleSheet("QLabel { color : red; }")
|
||||||
self.feedBackObject.setText(string)
|
self.feedBackObject.setText(string)
|
||||||
self.isValid = False
|
self.isValid = False
|
||||||
if self.buttonBox:
|
if self.okButton:
|
||||||
self.okButton.setEnabled(False)
|
self.okButton.setEnabled(False)
|
||||||
if string is not None and self.feedBackObject is not None:
|
if string is not None and self.feedBackObject is not None:
|
||||||
self.okButton.setText(
|
self.okButton.setText(
|
||||||
|
@ -50,7 +49,7 @@ class AddressPassPhraseValidatorMixin(object):
|
||||||
self.feedBackObject.setStyleSheet("QLabel { }")
|
self.feedBackObject.setStyleSheet("QLabel { }")
|
||||||
self.feedBackObject.setText(string)
|
self.feedBackObject.setText(string)
|
||||||
self.isValid = True
|
self.isValid = True
|
||||||
if self.buttonBox:
|
if self.okButton:
|
||||||
self.okButton.setEnabled(True)
|
self.okButton.setEnabled(True)
|
||||||
self.okButton.setText(self.okButtonLabel)
|
self.okButton.setText(self.okButtonLabel)
|
||||||
|
|
||||||
|
@ -80,7 +79,7 @@ class AddressPassPhraseValidatorMixin(object):
|
||||||
"AddressValidator",
|
"AddressValidator",
|
||||||
"Address already present as one of your identities."
|
"Address already present as one of your identities."
|
||||||
))
|
))
|
||||||
return (QtGui.QValidator.Intermediate, 0)
|
return
|
||||||
if addressGeneratorReturnValue[0] == \
|
if addressGeneratorReturnValue[0] == \
|
||||||
'chan name does not match address':
|
'chan name does not match address':
|
||||||
self.setError(
|
self.setError(
|
||||||
|
@ -89,7 +88,7 @@ class AddressPassPhraseValidatorMixin(object):
|
||||||
"Although the Bitmessage address you entered was"
|
"Although the Bitmessage address you entered was"
|
||||||
" valid, it doesn\'t match the chan name."
|
" valid, it doesn\'t match the chan name."
|
||||||
))
|
))
|
||||||
return (QtGui.QValidator.Intermediate, 0)
|
return
|
||||||
self.setOK(
|
self.setOK(
|
||||||
_translate(
|
_translate(
|
||||||
"MainWindow", "Passphrase and address appear to be valid."))
|
"MainWindow", "Passphrase and address appear to be valid."))
|
||||||
|
@ -120,7 +119,7 @@ class AddressPassPhraseValidatorMixin(object):
|
||||||
"Chan name/passphrase needed."
|
"Chan name/passphrase needed."
|
||||||
" You didn't enter a chan name."
|
" You didn't enter a chan name."
|
||||||
))
|
))
|
||||||
return (QtGui.QValidator.Intermediate, pos)
|
return (QtGui.QValidator.Intermediate, s, pos)
|
||||||
|
|
||||||
if self.addressMandatory or address is not None:
|
if self.addressMandatory or address is not None:
|
||||||
# check if address already exists:
|
# check if address already exists:
|
||||||
|
@ -130,7 +129,7 @@ class AddressPassPhraseValidatorMixin(object):
|
||||||
"AddressValidator",
|
"AddressValidator",
|
||||||
"Address already present as one of your identities."
|
"Address already present as one of your identities."
|
||||||
))
|
))
|
||||||
return (QtGui.QValidator.Intermediate, pos)
|
return (QtGui.QValidator.Intermediate, s, pos)
|
||||||
|
|
||||||
# version too high
|
# version too high
|
||||||
if decodeAddress(address)[0] == 'versiontoohigh':
|
if decodeAddress(address)[0] == 'versiontoohigh':
|
||||||
|
@ -142,7 +141,7 @@ class AddressPassPhraseValidatorMixin(object):
|
||||||
" for us to handle. Perhaps you need to upgrade"
|
" for us to handle. Perhaps you need to upgrade"
|
||||||
" Bitmessage."
|
" Bitmessage."
|
||||||
))
|
))
|
||||||
return (QtGui.QValidator.Intermediate, pos)
|
return (QtGui.QValidator.Intermediate, s, pos)
|
||||||
|
|
||||||
# invalid
|
# invalid
|
||||||
if decodeAddress(address)[0] != 'success':
|
if decodeAddress(address)[0] != 'success':
|
||||||
|
@ -151,7 +150,7 @@ class AddressPassPhraseValidatorMixin(object):
|
||||||
"AddressValidator",
|
"AddressValidator",
|
||||||
"The Bitmessage address is not valid."
|
"The Bitmessage address is not valid."
|
||||||
))
|
))
|
||||||
return (QtGui.QValidator.Intermediate, pos)
|
return (QtGui.QValidator.Intermediate, s, pos)
|
||||||
|
|
||||||
# this just disables the OK button without changing the feedback text
|
# this just disables the OK button without changing the feedback text
|
||||||
# but only if triggered by textEdited, not by clicking the Ok button
|
# but only if triggered by textEdited, not by clicking the Ok button
|
||||||
|
@ -171,13 +170,13 @@ class AddressPassPhraseValidatorMixin(object):
|
||||||
))
|
))
|
||||||
|
|
||||||
if self.okButton.hasFocus():
|
if self.okButton.hasFocus():
|
||||||
return (self.returnValid(), pos)
|
return (self.returnValid(), s, pos)
|
||||||
else:
|
else:
|
||||||
return (QtGui.QValidator.Intermediate, pos)
|
return (QtGui.QValidator.Intermediate, s, pos)
|
||||||
|
|
||||||
def checkData(self):
|
def checkData(self):
|
||||||
try:
|
try:
|
||||||
return self.validate("", 0)
|
return self.validate(u"", 0)
|
||||||
except Exception:
|
except Exception:
|
||||||
logger.warning("Exception in validate():", exc_info=True)
|
logger.warning("Exception in validate():", exc_info=True)
|
||||||
|
|
||||||
|
@ -185,11 +184,11 @@ class AddressPassPhraseValidatorMixin(object):
|
||||||
class AddressValidator(QtGui.QValidator, AddressPassPhraseValidatorMixin):
|
class AddressValidator(QtGui.QValidator, AddressPassPhraseValidatorMixin):
|
||||||
def __init__(
|
def __init__(
|
||||||
self, parent=None, passPhraseObject=None, feedBackObject=None,
|
self, parent=None, passPhraseObject=None, feedBackObject=None,
|
||||||
buttonBox=None, addressMandatory=True
|
button=None, addressMandatory=True
|
||||||
):
|
):
|
||||||
super(AddressValidator, self).__init__(parent)
|
super(AddressValidator, self).__init__(parent)
|
||||||
self.setParams(
|
self.setParams(
|
||||||
passPhraseObject, parent, feedBackObject, buttonBox,
|
passPhraseObject, parent, feedBackObject, button,
|
||||||
addressMandatory
|
addressMandatory
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -197,10 +196,10 @@ class AddressValidator(QtGui.QValidator, AddressPassPhraseValidatorMixin):
|
||||||
class PassPhraseValidator(QtGui.QValidator, AddressPassPhraseValidatorMixin):
|
class PassPhraseValidator(QtGui.QValidator, AddressPassPhraseValidatorMixin):
|
||||||
def __init__(
|
def __init__(
|
||||||
self, parent=None, addressObject=None, feedBackObject=None,
|
self, parent=None, addressObject=None, feedBackObject=None,
|
||||||
buttonBox=None, addressMandatory=False
|
button=None, addressMandatory=False
|
||||||
):
|
):
|
||||||
super(PassPhraseValidator, self).__init__(parent)
|
super(PassPhraseValidator, self).__init__(parent)
|
||||||
self.setParams(
|
self.setParams(
|
||||||
parent, addressObject, feedBackObject, buttonBox,
|
parent, addressObject, feedBackObject, button,
|
||||||
addressMandatory
|
addressMandatory
|
||||||
)
|
)
|
||||||
|
|
|
@ -9,27 +9,19 @@ from tr import _translate
|
||||||
from utils import str_chan
|
from utils import str_chan
|
||||||
import widgets
|
import widgets
|
||||||
|
|
||||||
from debug import logger
|
|
||||||
|
|
||||||
|
|
||||||
class NewChanDialog(QtWidgets.QDialog, RetranslateMixin):
|
class NewChanDialog(QtWidgets.QDialog, RetranslateMixin):
|
||||||
def __init__(self, parent=None):
|
def __init__(self, parent=None):
|
||||||
super(NewChanDialog, self).__init__(parent)
|
super(NewChanDialog, self).__init__(parent)
|
||||||
widgets.load('newchandialog.ui', self)
|
widgets.load('newchandialog.ui', self)
|
||||||
self.parent = parent
|
self.parent = parent
|
||||||
validator = AddressValidator(
|
self.chanAddress.setValidator(AddressValidator(
|
||||||
self.chanAddress, self.chanPassPhrase,
|
self.chanAddress, self.chanPassPhrase,
|
||||||
self.validatorFeedback, self.buttonBox, False)
|
self.validatorFeedback,
|
||||||
try:
|
self.buttonBox.button(QtWidgets.QDialogButtonBox.Ok), False))
|
||||||
validator.checkData()
|
|
||||||
except:
|
|
||||||
logger.warning("NewChanDialog.__init__", exc_info=True)
|
|
||||||
# logger.warning("NewChanDialog.__init__, validator.checkData()")
|
|
||||||
|
|
||||||
self.chanAddress.setValidator(validator)
|
|
||||||
self.chanPassPhrase.setValidator(PassPhraseValidator(
|
self.chanPassPhrase.setValidator(PassPhraseValidator(
|
||||||
self.chanPassPhrase, self.chanAddress, self.validatorFeedback,
|
self.chanPassPhrase, self.chanAddress, self.validatorFeedback,
|
||||||
self.buttonBox, False))
|
self.buttonBox.button(QtWidgets.QDialogButtonBox.Ok), False))
|
||||||
|
|
||||||
self.timer = QtCore.QTimer()
|
self.timer = QtCore.QTimer()
|
||||||
self.timer.timeout.connect(self.delayedUpdateStatus)
|
self.timer.timeout.connect(self.delayedUpdateStatus)
|
||||||
|
@ -48,13 +40,13 @@ class NewChanDialog(QtWidgets.QDialog, RetranslateMixin):
|
||||||
addressGeneratorQueue.put((
|
addressGeneratorQueue.put((
|
||||||
'createChan', 4, 1,
|
'createChan', 4, 1,
|
||||||
str_chan + ' ' + str(self.chanPassPhrase.text()),
|
str_chan + ' ' + str(self.chanPassPhrase.text()),
|
||||||
self.chanPassPhrase.text(), True
|
self.chanPassPhrase.text().encode('utf-8'), True
|
||||||
))
|
))
|
||||||
else:
|
else:
|
||||||
addressGeneratorQueue.put((
|
addressGeneratorQueue.put((
|
||||||
'joinChan', addBMIfNotPresent(self.chanAddress.text()),
|
'joinChan', addBMIfNotPresent(self.chanAddress.text()),
|
||||||
str_chan + ' ' + str(self.chanPassPhrase.text()),
|
str_chan + ' ' + str(self.chanPassPhrase.text()),
|
||||||
self.chanPassPhrase.text(), True
|
self.chanPassPhrase.text().encode('utf-8'), True
|
||||||
))
|
))
|
||||||
addressGeneratorReturnValue = apiAddressGeneratorReturnQueue.get(True)
|
addressGeneratorReturnValue = apiAddressGeneratorReturnQueue.get(True)
|
||||||
if (len(addressGeneratorReturnValue) > 0
|
if (len(addressGeneratorReturnValue) > 0
|
||||||
|
|
Reference in New Issue
Block a user