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
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)
wxTextEntry dialog already has its own GetValue and SetValue, my guess is that it is calling it's SetValue before it goes into its modal event loop, and since you never set the internal value (in the dialog, not the textctrl) then it overwrote what you put in the textctrl with an empty string.
Try just removing your GetValue/SetValue methods so the default ones will be used instead.
···
--
Robin Dunn
Software Craftsman http://wxPython.org Java give you jitters? Relax with wxPython!
Thanks Robin, I forgot about the isinstance method. Upon removing my
(S/G)etValue methods it works as expected. Thanks for you explanation.
For anyone who is interested, below is the code.
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 isinstance(child, wx.TextCtrl):
self.text = child
break
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)
From:
wxpython-users-bounces+kyle.rickey=bakerhughes.com@lists.wxwidgets.org
[mailto:wxpython-users-bounces+kyle.rickey=bakerhughes.com@lists.wxwidge
ts.org] On Behalf Of Robin Dunn
···
-----Original Message-----
Sent: Thursday, April 03, 2008 5:43 PM
To: wxpython-users@lists.wxwidgets.org
Subject: Re: [wxpython-users] Subclassing TextEntryDialog
Rickey, Kyle W wrote:
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
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)
wxTextEntry dialog already has its own GetValue and SetValue, my guess
is that it is calling it's SetValue before it goes into its modal event
loop, and since you never set the internal value (in the dialog, not the
textctrl) then it overwrote what you put in the textctrl with an empty
string.
Try just removing your GetValue/SetValue methods so the default ones
will be used instead.
--
Robin Dunn
Software Craftsman http://wxPython.org Java give you jitters? Relax with wxPython!