[wxPython-users] Re: Custom validator
Paul Koning
pkoning at equallogic.com
Tue Jan 2 09:06:02 PST 2007
>>>>> "Robin" == Robin Dunn <robin at alldunn.com> writes:
Robin> Basil Shubin wrote:
>> Hi,
>>
>> Phil Mayes ÐÉÛÅÔ:
>>> Try: FLOAT = r'\d+\.\d+$'
>> Not exactly what it should be. The problem is that I want check
>> all input char and 'allow' only digits, but all digits should fit
>> the regex pattern. For checking where is pressed key correspond
>> the digits, is to bind on wx.EVT_CHAR and than check if key is
>> digit (it's showed in wxPython validator example). But I don't
>> know how I can check the entire inputed string, so it fits regex
>> pattern.
Robin> Normally something like that would be done in the Validate
Robin> method, but that is not called for every character, only when
Robin> the dialog is completed. You don't want to do it in the
Robin> EVT_CHAR handler since the new char has not been inserted into
Robin> textctrl yet. But you could use wx.CallAfter from there to
Robin> cause a method to be called after the character has been
Robin> inserted, and from there you can get the value of the control
Robin> and check it however you like.
Neat.
I found the behavior of validators surprising and unhelpful -- it
seems like unfriendly UI design to allow a user to enter bad data and
then complain afterwards.
For example, I have a text control where a user is expected to enter a
number. The rational behavior is to ignore non-numeric keystrokes,
and I foolishly expected a validator to be able to do that. No such
luck. But now I know how to get that effect. Thanks!
paul
More information about the wxpython-users
mailing list