Hi friends!
I have trying understand this *damn* PyValidator and don't know how I can check text while input, so only float number will be accepted... Why there Validator method that do not do anything?
Inside OnChar method I can only check if inputed *char* is valid, but don't know how to validate entire string.
Suppose float value should correspond some pattern, i.e. only two digints after dot. How to implement float validator based on PyValidator class?
Thanks!
------------------------------------------------------------------------
# -*- coding: utf-8 -*-
import wx
import re
class floatValidator(wx.PyValidator):
def __init__(self, pyVar=None):
wx.PyValidator.__init__(self)
self.numList = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '.']
self.Bind(wx.EVT_CHAR, self.OnChar)
def Clone(self):
return floatValidator()
def Validate(self, win):
pass
def OnChar(self, event): key = event.GetKeyCode()
if key < wx.WXK_SPACE or key == wx.WXK_DELETE or key > 255:
event.Skip()
return
if chr(key) in self.numList:
event.Skip()
return
if not wx.Validator_IsSilent():
wx.Bell()
# Returning without calling even.Skip eats the event before it
# gets to the text control
return
------------------------------------------------------------------------
---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwidgets.org
For additional commands, e-mail: wxPython-users-help@lists.wxwidgets.org