[wxPython-users] Custom validator
Werner F. Bruhin
werner.bruhin at free.fr
Sun Dec 31 01:03:11 PST 2006
Hi Basil,
Why not use the wx.lib.masked controls, they do this and more.
Werner
Basil Shubin wrote:
> Hi friends!
>
> I want use custom validators in my app to check where input data
> correct or disallow it. With following example is not possible to
> check if input is correct or not, it just allow all input, even I
> explicitly point to use only float input???
>
> import wx
> import re
>
> NUMBER = r'\d+$'
> FLOAT = r'\d+(\.\d{1,2})?$'
>
>
> class Validator(wx.PyValidator):
>
> def __init__(self, regex=None):
> wx.PyValidator.__init__(self)
> self.regex = regex
> if self.regex:
> self.re = re.compile(regex)
>
> def Clone(self):
> return Validator(self.regex)
>
> def Validate(self, win):
> if not self.regex:
> return True
> window = self.GetWindow()
> text = window.GetValue().strip()
> if self.re.match(text):
> return True
> else:
> return False
>
> def TransferToWindow(self):
> return true
>
> def TransferFromWindow(self):
> return true
>
> Other way is to use OnChar method, but how I can check where inputed
> char fit appropriate regex, i.e is it float?
>
> Thanks!
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: wxPython-users-unsubscribe at lists.wxwidgets.org
> For additional commands, e-mail: wxPython-users-help at lists.wxwidgets.org
>
>
>
>
More information about the wxpython-users
mailing list