Hi,
There's a problem with wxToolBar on MSW: it gains the keyboard focus when
you click it. It's something that's been found and fixed before, wasn't
there in 2.3.1, but is back in 2.3.2beta (tested in b4 and now b5).
You can see it in the wxToolBar demo - click in the combobox then click a
toolbar button. In 2.3.1 the focus will remain in the combobox, but in
2.3.2b5 it will go to the toolbar itself (as you can see if you hit the
left/right arrow keys - the focus moves from button to button).
Here's a not-quite-perfect workaround for apps with multiple focussable
windows that returns the focus to the right window 99% of the time, and a
default window the other 1%. (If your app only has one focussable window,
just returning the focus to that in OnSetFocus would be better!)
class MyToolBar( wxToolBar ):
'''A wxToolBar that doesn't accept the focus (as can happen in some
versions of wxWindows).'''
def __init__( self, parent, defaultFocusWindow, id, style ):
wxToolBar.__init__( self, parent, id, style=style )
self.oldFocus = None
self.defaultFocusWindow = defaultFocusWindow
EVT_ENTER_WINDOW( self, self.OnEnterWindow )
EVT_LEAVE_WINDOW( self, self.OnLeaveWindow )
EVT_SET_FOCUS( self, self.OnSetFocus )
def OnEnterWindow( self, event ):
self.oldFocus = wxWindow_FindFocus()
def OnLeaveWindow( self, event ):
self.oldFocus = None
def OnSetFocus( self, event ):
if self.oldFocus:
self.oldFocus.SetFocus()
else:
self.defaultFocusWindow.SetFocus()
···
--
Richie Hindle
richie@entrian.com