[wxpython-users] Subclassing TextEntryDialog
Rickey, Kyle W
Kyle.Rickey at bakerhughes.com
Thu Apr 3 07:40:20 PDT 2008
I'm trying to create a dialog that has some basic validation. I've got
it somewhat working except the SetValue method does not work. Below is
an example. Note I can get the desired text in the TextCtrl by passing
it as an argument in the __init__ method. Is this a bug or am I missing
something?
import wx
class SetEmailAddressDialog(wx.TextEntryDialog):
def __init__(self, parent, prompt, title):
wx.TextEntryDialog.__init__(self, parent, prompt, title)
children = self.GetChildren()
for child in children:
if str(child.__class__) == "<class
'wx._controls.TextCtrl'>":
self.text = child
break
self.text.Bind(wx.EVT_TEXT, self.ValidateEmail)
self.ok_button = self.FindWindowById(wx.ID_OK)
def ValidateEmail(self, event):
text = self.text.GetValue()
if text != "" and text != "@something.com":#Valid email
address
self.ok_button.Enable(True)
else:
self.ok_button.Enable(False)
def GetValue(self):
return self.text.GetValue()
def SetValue(self, value):
print value
self.text.SetValue(value)
app = wx.App(0)
dlg = SetEmailAddressDialog(None, "Set your email address", "Do it")
dlg.SetValue("this doesn't show up in the dialog")
dlg.ShowModal()
app.MainLoop()
-Kyle Rickey
More information about the wxpython-users
mailing list