[wxPython-users] Focus swallowing sideshow

Kevin Ollivier kevino at tulane.edu
Thu Aug 31 17:37:24 PDT 2006


Hi Donn,

The problem doesn't occur on OS X with Py 2.4, wxPy 2.6.3.3. ESC key  
always closes the dialog, regardless of which button you click or  
don't click.

regards,

Kevin

On Aug 31, 2006, at 4:42 PM, Donn Ingle wrote:

> Kubuntu 6.06
> WxPython 2.6 - from the wxPython downloads apt-sources
>
> Hi,
> I'm up late. Was about to post a bug on SF when I though I should  
> make a
> shorter sample app. I came up with the listing below.
>
> The problem is that when a button is clicked and in the handler one  
> set the
> enabled (False) on it, the detection of key presses seems to stop.  
> (I want
> ESC key to always close the app.)
> I used a self.Bind(wx.EVT_KEY_UP, self.OnKeyUp) kind of event and  
> then Robin
> told me about these accelerator tables, but both suffer the same fate.
>
> When I add a SetFocus() to *another* button the ESC key comes back  
> to life.
>
> I don't know what this means in the scheme of things, but it's a  
> fix for my
> app right now.
>
> Should I still post a bug? Perhaps someone on Windows/Mac could try  
> this:
> Change remark on the line, to toggle the effect:
> self.butOk.SetFocus () #If I do this, it works again
>
>
> Code:
> #!/usr/bin/env python2.4
>
> import wx
> import 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
>
>         #Try re/unmarking this next line:
>         #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
>
> #PREV=wx.ID_BACKWARD
> ID_ESC = wx.NewId ()
>
> if __name__ == "__main__":
>     app = App(0)
>     app.MainLoop()
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: wxPython-users-unsubscribe at lists.wxwidgets.org
> For additional commands, e-mail: wxPython-users- 
> help at lists.wxwidgets.org
>





More information about the wxpython-users mailing list