[wxPython] wxWindow::SetFocus

Hewwo everyone,

[Linux 2.4.19pre7 running Debian unstable, wxGTK 2.2.9, libwxgtk2.2-python 2.2.9.2]

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.

If, in this button handler, I only call the SetFocus() method for the
next control it works correctly.

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()

Any ideas? More info needed?
Thanks in advance,

···

--
Alexander Deruwe
AQS-CarControl

[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()

IIRC, there is some code executed after a dialog is closed that resets the
focus back to where it was before the dialog was shown. On wxGTK this
probably happens in idle time, which means that it will happen after your
SetFocus. You might be able to get around it by putting a call to wxYield
before your SetFocus. If that doesn't do it then you will have to do the
same trick that wxGTK is doing and change the focus in an EVT_IDLE handler.

···

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

Hewwo everyone,

[Linux 2.4.19pre7 running Debian unstable, wxGTK 2.2.9, libwxgtk2.2-python 2.2.9.2]

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.

If, in this button handler, I only call the SetFocus() method for the
next control it works correctly.

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()

Any ideas? More info needed?
Thanks in advance,

Consider using a flag, and check/SetFocus in an OnIdle handler.

--
Alexander Deruwe
AQS-CarControl

Cheers,
  Hans-Peter

P.S.: Looking for python projects. Rent me...

···

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