[wxPython-users] button disable swallows focus

Robin Dunn robin at alldunn.com
Wed Aug 30 12:19:08 PDT 2006


Donn Ingle wrote:
> Kubuntu 6.06
> wxPython 2.6
> 
> Hello,
> I could post code, but it's a little hard to make a short demo of the
> problem. Lemme try it this way first. 
> 
> In a nutshell:
> I have several panels on a frame.
> I have a button on the bottom panel.
> I have the frame with:
> self.Bind(wx.EVT_KEY_UP, self.OnKeyUp)
> I want escape key to quit app at any stage, no matter the focus.
> When the button is pressed I go one page forward (not described here).
> Pressing escape key works as expected.
> When there is no next page, the button is disabled (in OnKeyUp) by:
> self.buttNext.Enable(False)
> Now, pressing escape does nothing; it's as if the disabled button has
> swallowed the focus and I cannot get it back on the frame. 
> I have tried self.Setfocus() (on the frame) after the OnKeyUp code is all
> done. No go.

Frames can't have the focus, it has to be in one of the child windows. 
The best way to have a app-global key handler like this is to use 
accelerators.  If your frame has a menubar then one of the menu items 
can have "\tESC" as part of the label, and then the EVT_MENU handler for 
that menu item will be called whenever the ESC key is pressed.  If you 
don't have a menubar then you can so the same thing by creating a 
wx.AcceleratorTable and assigning it to the frame.


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





More information about the wxpython-users mailing list