[wxPython] Problem with wxGTK wxDialog SetFocus

wxPython 2.3.3.1
python 2.2.1
platform bsdi 4.3

I'm having trouble with SetFocus calls for my wxDialog's children. The
child control in this case self.text never seems to get the focus. The
dialog works as I would expect on NT. Is their a bug or am I missing
something?

Thanks in advance,

Steve

This example is modified from the demo's wxDialog.py.

from wxPython.wx import *

···

#---------------------------------------------------------------------------
class MyDialog(wxDialog):
    def __init__(self, parent, id, title, pos, size):
         wxDialog.__init__(self, parent, id, title, pos, size)
         self.ok = wxButton(self, wxID_OK, " OK ", wxPoint(75, 120),
wxDefaultSize).SetDefault()
         self.cancel = wxButton(self, wxID_CANCEL, " Cancel ",
wxPoint(200, 120), wxDefaultSize)
         self.text = wxTextCtrl(self, -1, "This is a wxDialog",
wxPoint(20, 20))
         self.text.SetFocus()

def runTest(frame, nb, log):
    win = MyDialog(frame, -1, "This is a wxDialog", wxDefaultPosition,
wxSize(350, 200))

    val = win.ShowModal()
    if val == wxID_OK:
        log.WriteText("You pressed OK\n")
    else:
        log.WriteText("You pressed Cancel\n")

#---------------------------------------------------------------------------

I'm having trouble with SetFocus calls for my wxDialog's children. The
child control in this case self.text never seems to get the focus. The
dialog works as I would expect on NT. Is their a bug or am I missing
something?

The dialog is not shown when you call SetFocus, so it can't change the focus
to the text ctrl. The fact that it works on Windows is just a happy
accident.

You can use an idle handler (or the new wxCallAfter in 2.3.3) to set the
focus after the dialog is shown.

···

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