Recursive validation - what's wrong here

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()

``

Mystery solved.

All works replacing this line:

wx.Frame.init(self, parent, -1, title=title, style = wx.DEFAULT_FRAME_STYLE|wx.WS_EX_VALIDATE_RECURSIVELY)

``

with these lines:

wx.Frame.init(self, parent, -1, title=title)
self.SetExtraStyle(wx.WS_EX_VALIDATE_RECURSIVELY)

``

I hadn’t realized that there was a second way to apply styles (or that I was supposed to attach my code rather than include in the body :-p)

–charlie

···

On Wednesday, September 3, 2014 1:04:07 AM UTC-7, Charles J. Daniels wrote:

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()

``

You found your answer already, but might anyhow the followings links
might be helpful.
On the wiki just search for validator - Validator Overview — wxPython Phoenix 4.2.3a1 documentation
Note that the above is the Phoenix documentation, if you use classic
there are some API changes but I find the documentation still very
helpful.
I would also suggest to place your controls onto a wx.Panel within
your frame to get consistent behaviour on the different platforms.
Werner

···

Hi Charles,

  On 9/3/2014 20:13, Charles J. Daniels wrote:

Mystery solved.

All works replacing this line:

wx.Frame.init(self,
parent, -1, title=title, style
= wx.DEFAULT_FRAME_STYLE|wx.WS_EX_VALIDATE_RECURSIVELY)

``

with these lines:

wx.Frame.init(self, parent, -1, title=title)

          self.SetExtraStyle(wx.WS_EX_VALIDATE_RECURSIVELY)

``

      I hadn't realized that there was a second way to apply

styles (or that I was supposed to attach my code rather than
include in the body :-p)

http://wiki.wxpython.org