Below is my non-working case. All the controls with the custom validators applied that are children of the main frame work, but when I bury a control inside one of them, it doesn’t recurse. Am I missing something? I’m on Windows. Each validated control is supposed to pop up a message, but the buried one doesn’t. Also, I can’t seem to get the one on the main window to work either, but not as important.
import wx
class TextObjectValidator(wx.PyValidator):
def init(self, label):
wx.PyValidator.init(self)
self.label = label
def Clone(self):
return TextObjectValidator(self.label)
def Validate(self, win):
return True
def TransferToWindow(self):
return True
def TransferFromWindow(self):
wx.MessageBox(self.label, “”)
return True
class MainWindow(wx.Frame):
def init(self, parent, title):
wx.Frame.init(self, parent, -1, title=title, style = wx.DEFAULT_FRAME_STYLE|wx.WS_EX_VALIDATE_RECURSIVELY)
#doesn’t work
self.SetValidator(TextObjectValidator(“MainWindown”))
#this one works
self.txt = wx.TextCtrl(self, -1, "test", validator = TextObjectValidator("txt"))
self.tabs = wx.Listbook(self, -1, style = wx.WS_EX_VALIDATE_RECURSIVELY)
#this one works
self.tabs.SetValidator(TextObjectValidator("tabs"))
#this one works
newPanel = wx.Panel(self, -1, style = wx.WS_EX_VALIDATE_RECURSIVELY)
newPanel.SetValidator(TextObjectValidator("newPanel"))
#doesn't work
wx.TextCtrl(newPanel, -1, "test2", validator = TextObjectValidator("txt2"))
self.tabs.AddPage(newPanel, "newPanel")
self.executeButton = wx.Button(self, -1, "Execute")
self.Bind(wx.EVT_BUTTON, self.OnExecute, self.executeButton)
self.sizer = wx.BoxSizer(wx.VERTICAL)
self.sizer.Add(self.txt, 1, wx.EXPAND)
self.sizer.Add(self.tabs, 1, wx.EXPAND)
self.sizer.Add(self.executeButton, 1, wx.EXPAND)
self.SetSizer(self.sizer)
self.Maximize(True)
self.Show()
def OnExecute(self, event):
if self.TransferDataFromWindow():
wx.MessageBox("all transfered", "OK")
else:
wx.MessageBox("something didn't tranfer", "ERROR")
def main():
app = wx.App(False)
TopWnd = MainWindow(None, “Recursive Validator Test”)
TopWnd.Show(True)
app.MainLoop()
if name == ‘main’:
main()
``