From: Heimburger, R. P <rph...@ba...> - 2004-09-24 12:24:22
|
=20 Thanks! =20 ________________________________ From: Kevin Altis [mailto:al...@se...]=20 Sent: Thursday, September 23, 2004 4:21 PM To: Heimburger, Ralph P Cc: pyt...@li... Subject: Re: [Pythoncard-users] Capturing RETURN key and translating to TAB =20 On Sep 23, 2004, at 11:59 AM, Heimburger, Ralph P wrote:=20 =20 I have a requirement to capture the RETURN key and treat it like a TAB so that both TAB and RETURN will perform the same function. I have a "global" on_keyPress(self, event) defined but need help in figuring out the syntax of the event to fire:=20 =20 def on_keypress(self, event):=20 =20 if event.keyCode =3D=3D wx.WXK_RETURN:=20 =20 event.target.MouseUpEvent=20 =20 # other things I've tried that don't work=20 =20 #self.components.keys(wx.WXK_TAB)=20 =20 #event.m_keyCode =3D wx.WXK_TAB=20 =20 =20 The wxPython 2.5.2.x MigrationGuide.html document has an example using wx.NavigationKeyEvent, which is new with wxPython 2.5.2. Adapting that to cause the return key to behave the same as the tab key using PythonCard event attribute names gives us this example:=20 =20 def on_keyDown(self, event):=20 # wx.WXK_RETURN is 13=20 if event.keyCode =3D=3D wx.WXK_RETURN:=20 if event.shiftDown:=20 flags =3D wx.NavigationKeyEvent.IsBackward=20 else:=20 flags =3D wx.NavigationKeyEvent.IsForward=20 if event.controlDown:=20 flags |=3D wx.NavigationKeyEvent.WinChange=20 event.target.Navigate(flags)=20 else:=20 event.skip()=20 =20 Remember that if you use an on_keyDown event handler, all components that receive key events that don't have their own keyDown handlers will end up using that event handler. If you just want it to handle TextField components you might want to add a test for the class or class name and call event.skip() if necessary. Here's one possibility:=20 =20 if event.target.__class__.__name__ =3D=3D 'TextField':=20 ...=20 =20 ka |