Validating a wxTextCtrl on a wxPanel

I’m trying to have a validate a certain wxTextCtrl on a wxPanel but it
doesn’t seem to be getting called when I enter data into the field or
on the EVT_BUTTON event.

All the examples I’ve seen using Validators have had the parent frame
be a wxDialog. Is there something specific about using a
Validator on a wxPanel that I am missing?

Thanks,

Kevin

Relevant code:

class HostNameValidator(wxPyValidator):

def __init__(self):
    wxPyValidator.__init__(self)

def Clone(self):
    return HostNameValidator()

def Validate(self, win):
    tc = self.GetWindow()
    val = tc.GetValue()
   
    print "Validating!"

    return False

class LoginPanel(wxPanel):

def __init__(self, parent):
    wxPanel.__init__(self, parent, -1)

    ...

    self.host  =

wxTextCtrl(self, ID_HOST, size=(125, -1), validator =
HostNameValidator() )

Hi Kevin,

Kevin Conaway wrote:

I'm trying to have a validate a certain wxTextCtrl on a wxPanel but it doesn't seem to be getting called when I enter data into the field or on the EVT_BUTTON event.

All the examples I've seen using Validators have had the parent frame be a wxDialog. Is there something specific about using a Validator on a wxPanel that I am missing?

you need to call LoginPanel.InitDialog() before showing it see doc:

When a wxDialog::Show is called (for a modeless dialog) or wxDialog::ShowModal is called (for a modal dialog), the function wxWindow::InitDialog is automatically called. This in turn sends an initialisation event to the dialog. The default handler for the wxEVT_INIT_DIALOG event is defined in the wxWindow class to simply call the function wxWindow::TransferDataToWindow. This function finds all the validators in the window's children and calls the TransferToWindow function for each. Thus, data is transferred from C++ variables to the dialog just as the dialog is being shown.

If you are using a window or panel instead of a dialog, you will need to call wxWindow::InitDialog explicitly before showing the window.

See you
Werner

···

Thanks,

Kevin

Relevant code:

class HostNameValidator(wxPyValidator):

    def __init__(self):
        wxPyValidator.__init__(self)

    def Clone(self):
        return HostNameValidator()
       def Validate(self, win):
        tc = self.GetWindow()
        val = tc.GetValue()
               print "Validating!"

        return False

class LoginPanel(wxPanel):

    def __init__(self, parent):
        wxPanel.__init__(self, parent, -1)

        ...

        self.host = wxTextCtrl(self, ID_HOST, size=(125, -1), validator = HostNameValidator() )

Werner F. Bruhin wrote:

Hi Kevin,

Kevin Conaway wrote:

I'm trying to have a validate a certain wxTextCtrl on a wxPanel but it doesn't seem to be getting called when I enter data into the field or on the EVT_BUTTON event.

All the examples I've seen using Validators have had the parent frame be a wxDialog. Is there something specific about using a Validator on a wxPanel that I am missing?

you need to call LoginPanel.InitDialog() before showing it see doc:

But for doing actual validation instead of data transfer then you'll want to call the Validate method of the panel.

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!