/ Published in: Python
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
import wx import string class HostValidator(wx.PyValidator): def __init__(self, pyVar=None): wx.PyValidator.__init__(self) self.Bind(wx.EVT_CHAR, self.OnChar) def Clone(self): """ Standard cloner. Note that every validator must implement the Clone() method. """ return HostValidator() def Validate(self, win): tc = self.GetWindow() # tc == TextCtrl val = tc.GetValue() for x in val: if x not in string.digits and x not in ".:": return False return True 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 string.digits: event.Skip() return if chr(key) in ".:": 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