Opened 5 years ago

Closed 5 years ago

Last modified 5 years ago

#14970 closed defect (fixed)

SearchCtrl HasFocus() doesn't report correct status

Reported by: fhjull00 Owned by:
Priority: normal Milestone:
Component: wxPython Version: 2.9.4
Keywords: SearchCtrl, HasFocus Cc:
Blocked By: Blocking:
Patch: no


SearchCtrl control doesn't seem to return HasFocus() correctly - when cursor is inside SearchCtrl TextCtrl, then

print searchCtrl.HasFocus()
>>> False

The workaround is to get list of children and query focus for them:

for searchFieldChild in searchCtrl.GetChildren():
   print searchFieldChild, searchFieldChild.HasFocus()

>>> <wx._controls.TextCtrl; proxy of <Swig Object of type 'wxTextCtrl *' at 0x40ae5e8> > True
>>> <wx._core.Control; proxy of <Swig Object of type 'wxControl *' at 0x3f9b7b0> > False
>>> <wx._core.Control; proxy of <Swig Object of type 'wxControl *' at 0x3f9c3b8> > False

Is this desired or should TextCtrl portion of SearchCtrl return the same HasFocus() value as SearchCtrl itself?

I am using wxPython on Windows 7 x64 with Python 2.7 (x32).

Change History (2)

comment:1 Changed 5 years ago by VZ

  • Resolution set to fixed
  • Status changed from new to closed

(In [73401]) Fix wxSearchCtrl::HasFocus() in the generic version.

Override GetMainWindowOfCompositeControl() in the windows composing the
generic wxSearchCtrl to ensure that HasFocus() correctly returns true for the
entire control when any of them has focus.

Add a trivial unit test to check that this really works and facilitate adding
more tests for this class later.

Closes #14970.

comment:2 Changed 5 years ago by fhjull00

Thank you!

Note: See TracTickets for help on using tickets.