hi,
macosx-10.4.11, python 2.6, wxpython-2.8.9.1-mac-unicode
i have a little dialog that contains a control derived from TextCtrl
that provides a SET_FOCUS handler for selecting all text when receiving
focus, a KILL_FOCUS handler that reformats the contents of the field
when focus is lost, and a validator for keystrokes. the dialog also
contains a StdDialogButtonSizer containing ok and cancel buttons.
anyway, the control works fine and the cancel button works fine but
the ok button does nothing. if i add an EVT_BUTTON handler, it shows
that the ok button is being triggered but the dialog doesn't close
and ShowModal doesn't return.
if i replace the validator with DefaultValidator, the ok button
works again (but of course it then also allows invalid characters).
the enter/return key is being accepted (Skip()) by the validator.
the code (almost) for the validator is below.
any idea what i'm doing wrong?
cheers,
raf
class KeyVetoValidator(PyValidator):
'''A control validator that will veto characters not in a specific string of
valid characters.'''
def __init__(self, valid):
'''Initialise this validator. Valid is the string of valid characters.'''
PyValidator.__init__(self)
self.Bind(EVT_CHAR, self._KeyVetoValidator_OnChar)
self.valid = valid
def TransferToWindow(self):
'''Needed to suppress error dialogue box.'''
return true
def TransferFromWindow(self):
'''Needed to suppress error dialogue box.'''
return true
def Clone(self):
'''Return a copy of this validator.'''
return KeyVetoValidator(self.valid)
def _KeyVetoValidator_OnChar(self, event):
'''Handler for the EVT_CHAR event. Veto invalid characters.'''
key = event.GetKeyCode()
if key < WXK_SPACE or key == WXK_DELETE or key > 255 or chr(key) in self.valid:
event.Skip()
class DateValidator(KeyVetoValidator):
'''A key-vetoing validator that only accepts digits, space, dash and slash.'''
def __init__(self, valid=''):
DigitValidator.__init__(self, string.digits + ' -/')