[wxPython-users] Cannot close a dialog on Linux with
wx.WS_EX_VALIDATE_RECURSIVELY
Tai Tran Tan
tttai at tma.com.vn
Wed Feb 27 17:18:07 PST 2008
Hi Robin,
[Robin]: How are you setting the style? Are you doing anything that would
clear the default wx.CLOSE_BOX style?
I did not set any style to my testing dialog.
The attachment including in this email is the source code for my testing
dialog. Actually, it is the validator example dialog that I take from your
eBook "wxPython in Action". The only thing that I've changed to this dialog
is adding the wx.WS_EX_VALIDATE_RECURSIVELY style through the function
SetExtraStyle(wx.WS_EX_VALIDATE_RECURSIVELY). This change makes the dialog
cannot be closed on Red Hat Linux with the (X) button. Please note that I
don't have this problem on Windows XP.
Best regards,
Tai Tran
-----Original Message-----
From: Robin Dunn [mailto:robin at alldunn.com]
Sent: Wednesday, February 27, 2008 9:37 AM
To: wxPython-users at lists.wxwidgets.org
Subject: Re: [wxPython-users] Cannot close a dialog on Linux with
wx.WS_EX_VALIDATE_RECURSIVELY
Tai Tran Tan wrote:
> Hi Robin,
>
> [Robin]: Do any of the widgets in the dialog have a validator that is
> failing?
>
> My dialog has only one direct child, a notebook, and all the controls are
> the children of tabs in this notebook. Some controls use validators to
> validate and transfer data to/from.
>
> If I set wx.WS_EX_VALIDATE_RECURSIVELY to the dialog, no validators fail,
> everything works OK except I cannot close the dialog with the (X) button
on
> Linux. I have to close the dialog by the Cancel button.
>
> It seems that every time I set wx.WS_EX_VALIDATE_RECURSIVELY to the
dialog,
> I cannot close it on Linux regardless of whether this dialog has children
> controls with validators or not.
How are you setting the style? Are you doing anything that would clear
the default wx.CLOSE_BOX style?
--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!
---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe at lists.wxwidgets.org
For additional commands, e-mail: wxPython-users-help at lists.wxwidgets.org
-------------- next part --------------
import wx
about_txt = """\
The validator used in this example will ensure that the text
controls are not empty when you press the Ok button, and
will not let you leave if any of the Validations fail."""
class NotEmptyValidator(wx.PyValidator):
def __init__(self):
wx.PyValidator.__init__(self)
def Clone(self):
"""
Note that every validator must implement the Clone() method.
"""
return NotEmptyValidator()
def Validate(self, win):
textCtrl = self.GetWindow()
text = textCtrl.GetValue()
if len(text) == 0:
wx.MessageBox("This field must contain some text!", "Error")
textCtrl.SetBackgroundColour("pink")
textCtrl.SetFocus()
textCtrl.Refresh()
return False
else:
textCtrl.SetBackgroundColour(
wx.SystemSettings_GetColour(wx.SYS_COLOUR_WINDOW))
textCtrl.Refresh()
return True
def TransferToWindow(self):
return True
def TransferFromWindow(self):
return True
class MyDialog(wx.Dialog):
def __init__(self):
wx.Dialog.__init__(self, None, -1, "Validators: validating")
self.SetExtraStyle(wx.WS_EX_VALIDATE_RECURSIVELY)
# Create the text controls
about = wx.StaticText(self, -1, about_txt)
name_l = wx.StaticText(self, -1, "Name:")
email_l = wx.StaticText(self, -1, "Email:")
phone_l = wx.StaticText(self, -1, "Phone:")
name_t = wx.TextCtrl(self, validator=NotEmptyValidator())
email_t = wx.TextCtrl(self, validator=NotEmptyValidator())
phone_t = wx.TextCtrl(self, validator=NotEmptyValidator())
# Use standard button IDs
okay = wx.Button(self, wx.ID_OK)
okay.SetDefault()
self.cancel = wx.Button(self, wx.ID_CANCEL)
# Layout with sizers
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(about, 0, wx.ALL, 5)
sizer.Add(wx.StaticLine(self), 0, wx.EXPAND|wx.ALL, 5)
fgs = wx.FlexGridSizer(3, 2, 5, 5)
fgs.Add(name_l, 0, wx.ALIGN_RIGHT)
fgs.Add(name_t, 0, wx.EXPAND)
fgs.Add(email_l, 0, wx.ALIGN_RIGHT)
fgs.Add(email_t, 0, wx.EXPAND)
fgs.Add(phone_l, 0, wx.ALIGN_RIGHT)
fgs.Add(phone_t, 0, wx.EXPAND)
fgs.AddGrowableCol(1)
sizer.Add(fgs, 0, wx.EXPAND|wx.ALL, 5)
btns = wx.StdDialogButtonSizer()
btns.AddButton(okay)
btns.AddButton(self.cancel)
btns.Realize()
sizer.Add(btns, 0, wx.EXPAND|wx.ALL, 5)
self.SetSizer(sizer)
sizer.Fit(self)
self.Fit()
app = wx.PySimpleApp()
dlg = MyDialog()
dlg.ShowModal()
dlg.Destroy()
app.MainLoop()
More information about the wxpython-users
mailing list