How I can add validator before OK clicking in widget which subclass of wx.TextEntryDialog

I’m not sure you can. The TextEntryDialog is a light wrapper around an OS level dialog (I think), which doesn’t offer much in customization. You should just recreate the dialog by creating your own subclass of wx.Dialog.

  • Mike
···

On Thursday, July 26, 2012 10:23:53 AM UTC-5, Daniel Finder wrote:

i’ve the following code:

class MyTextEntryDialog(wx.TextEntryDialog):

def __init__(self, parent):
    wx.TextEntryDialog.__init__(self, parent, message = "My Question",
                                caption = "Please enter value",  defaultValue = "default",
                                style = wx.OK|wx.CANCEL|wx.CENTRE, pos = wx.DefaultPosition)

def OnOK(self, event):
    print "OnOK"

validation

#…
self.EndModal(wx.ID_OK)

def GetValue(self):
    print "GetValue: ", wx.TextEntryDialog.GetValue(self)
    return wx.TextEntryDialog.GetValue(self)

class MyFrame(wx.Frame):
“”“”“”
def init(self):
wx.Frame.init(self, None)
panel = wx.Panel(self)
button = wx.Button(panel, label=“Push Me”)
self.Bind(wx.EVT_BUTTON, self.OnPush, button)
self.sizer = wx.FlexGridSizer(cols=2, rows=3, hgap=3, vgap=3)
self.sizer.AddWindow(button)
panel.SetSizer(self.sizer)

def OnPush(self, event):
    dlg = MyTextEntryDialog(None)
    if dlg.ShowModal() == wx.ID_OK:
        response = dlg.GetValue()
        print response

How i can bind OnON method with clicking on OK button in this dialog? I want to add validation in OnOK method and in case when input text is wrong - show error dialog (new dialog) and not close (!!!) this dialog

In this case it is a generic dialog.

Take a look at the window list you get from self.GetChildren() to find the widgets you want access too. In the case of the button it is probably using the stock ID so you can also use self.FindWindowById to get it.

···

On 7/26/12 9:10 AM, Mike Driscoll wrote:

On Thursday, July 26, 2012 10:23:53 AM UTC-5, Daniel Finder wrote:

    i've the following code:

    class MyTextEntryDialog(wx.TextEntryDialog):

         def __init__(self, parent):
             wx.TextEntryDialog.__init__(self, parent, message = "My
    Question",
           caption = "Please enter value", defaultValue = "default",
           style = wx.OK|wx.CANCEL|wx.CENTRE, pos = wx.DefaultPosition)

         def OnOK(self, event):
             print "OnOK"
    # validation
    #...
             self.EndModal(wx.ID_OK)

         def GetValue(self):
             print "GetValue: ", wx.TextEntryDialog.GetValue(self)
             return wx.TextEntryDialog.GetValue(self)

    How i can bind OnON method with clicking on OK button in this
    dialog? I want to add validation in OnOK method and in case when
    input text is wrong - show error dialog (new dialog) and not close
    (!!!) this dialog

I'm not sure you can. The TextEntryDialog is a light wrapper around an
OS level dialog (I think), which doesn't offer much in customization.

--
Robin Dunn
Software Craftsman

Really? Oops. Don’t mind me.

  • Mike
···

On Thursday, July 26, 2012 11:20:33 AM UTC-5, Robin Dunn wrote:

On 7/26/12 9:10 AM, Mike Driscoll wrote:

On Thursday, July 26, 2012 10:23:53 AM UTC-5, Daniel Finder wrote:

i've the following code:
class MyTextEntryDialog(wx.TextEntryDialog):
     def __init__(self, parent):
         wx.TextEntryDialog.__init__(self, parent, message = "My
Question",
       caption = "Please enter value",  defaultValue = "default",
       style = wx.OK|wx.CANCEL|wx.CENTRE, pos = wx.DefaultPosition)
     def OnOK(self, event):
         print "OnOK"
# validation
#...
         self.EndModal(wx.ID_OK)
     def GetValue(self):
         print "GetValue: ", wx.TextEntryDialog.GetValue(self)
         return wx.TextEntryDialog.GetValue(self)
How i can bind OnON method with clicking on OK button in this
dialog? I want to add validation in OnOK method and in case when
input text is wrong - show error dialog (new dialog) and not close
(!!!) this dialog

I’m not sure you can. The TextEntryDialog is a light wrapper around an

OS level dialog (I think), which doesn’t offer much in customization.

In this case it is a generic dialog.

Take a look at the window list you get from self.GetChildren() to find
the widgets you want access too. In the case of the button it is
probably using the stock ID so you can also use self.FindWindowById to
get it.


Robin Dunn

Software Craftsman

http://wxPython.org