[ wxwindows-Bugs-1550332 ] wxPython button swallows keyboard events

SourceForge.net noreply at sourceforge.net
Thu Aug 31 23:35:10 PDT 2006


Bugs item #1550332, was opened at 2006-09-01 08:35
Message generated for change (Tracker Item Submitted) made by Item Submitter
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=109863&aid=1550332&group_id=9863

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: wxGTK specific
Group: None
Status: Open
Resolution: None
Priority: 5
Submitted By: Donn (donningle)
Assigned to: Nobody/Anonymous (nobody)
Summary: wxPython button swallows keyboard events

Initial Comment:
Robin Dunn suggested I submit this bug.

Platform:
Kubuntu 6.06 with wxPython 2.6 (unicode) installed from
the apt sources on the wxPython homepage.

Another person (on the list) has checked this on Mac
OSX (Py 2.4, wxPy 2.6.3.3) and the problem is not
evident - Esc key works no matter what button is clicked.

Problem:
If when in a handler of a mouse EVT_LEFT_UP event, one
sets that button to enable(False), keyboard events seem
to be 'swallowed' by that button.
If I set the focus onto *another* button (not another
panel), then things work again.
The desired effect was to have Esc key close the app
from anywhere.

Sample code:
Please toggle the remark in the handler to see the
effect of setFocus on another button.

#!/usr/bin/env python2.4
## Problem apparent on Kubuntu 6.06, wxPython 2.6 (unicode)

import wx, os, sys

class MainFrame(wx.Frame):
    def __init__(self,parent,title):
        wx.Frame.__init__(self,parent,-1,title)
        self.buttonsPanel = wx.Panel(self)
        self.butSink = wx.Button(self.buttonsPanel,
label="Click me to sink ESC key")
        self.butOk = wx.Button(self.buttonsPanel,
label="You can click me and still ESC", pos=(0,50))
        #Use acceleratortable to trap Esc key
        self.accel =
wx.AcceleratorTable([(wx.ACCEL_NORMAL, wx.WXK_ESCAPE,
ID_ESC)])
        self.SetAcceleratorTable(self.accel)
        self.Bind(wx.EVT_MENU, self.OnCloseWindow,
id=ID_ESC)
        #The events
        self.Bind(wx.EVT_CLOSE,self.OnCloseWindow)
        self.butSink.Bind(wx.EVT_LEFT_UP,self.NavClick)
        #Focus on the panel
        self.buttonsPanel.SetFocus()

    def NavClick(self,event):
        self.butSink.Enable(False) #Kills the ESC key event
        #self.buttonsPanel.SetFocus() #This has no effect

        ##Toggle the remark below to toggle the effect
        ##
        ##self.butOk.SetFocus () #If I do this, it
works again

    def OnCloseWindow(self, event):
        self.Destroy()

class App(wx.App):
    def OnInit(self):
        frame = MainFrame(None, "click sink")
        self.SetTopWindow(frame)
        frame.Show(True)
        return True

ID_ESC = wx.NewId ()

if __name__ == "__main__":
    app = App(0)
    app.MainLoop()

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=109863&aid=1550332&group_id=9863




More information about the wx-dev mailing list