[wxPython] wxWindow::SetFocus

SetFocus() doesn't seem to work in some cases. For example:

[wxTextCtrl] [wxButton]
When the button is clicked, some text is fetched and placed into the
text control. I then want the focus to go to the next text control after
that, but calling its SetFocus() method doesn't do anything at all.
...

The handler:

def OnAddCountry(self, event):
   import EgCORBA, Table
   dlg = Table.EgTableSelectDialog(self, -1, "Select country", "countries")
   country = dlg.ShowModal()
   dlg.Destroy()

   country_obj = EgCORBA.get_country()
   self.txt_country.SetValue("%d - %s" % (country, country_obj.get_name

(country)))

   self.txt_postal_code.SetFocus()

this one does work:

def OnAddCountry(self, event):
   self.txt_postal_code.SetFocus()

I'm just speculating here, but sometimes even can be helpful.

Focus is a transitory thing. If you try to change the focus to a control
when the highest-level parent window containing that control is not the
uppermost window, the SetFocus call can be lost. In your first handler, the
SetFocus call is happening at a time of transition. You have a modal dialog
that is just coming down. Thus, the "uppermost window" totem is changing
from the dialog back to your main window. If your main window hasn't
completely regained "uppermost" status by the time of the SetFocus, you'd be
in trouble.

You might try moving the SetFocus call to just BEFORE the dialog call as an
experiment.

···

On Thu, 6 Jun 2002 12:05:59 +0200, aderuwe@aqs-carcontrol.be (Alexander Deruwe) wrote:

--
- Tim Roberts, timr@probo.com
  Providenza & Boekelheide, Inc.