From: Kevin A. <al...@se...> - 2004-09-23 20:21:33
|
On Sep 23, 2004, at 11:59 AM, Heimburger, Ralph P wrote: > I have a requirement to capture the RETURN key and treat it like a TAB=20= > so that both TAB and RETURN will perform the same function.=A0=A0 I = have a=20 > =93global=94 on_keyPress(self, event) defined but need help in = figuring=20 > out the syntax of the event to fire: > > def on_keypress(self, event): > > =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 if event.keyCode =3D=3D wx.WXK_RETURN: > > =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 = event.target.MouseUpEvent > > =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 =A0=A0=A0=A0 # other things I=92ve = tried that don=92t work > > =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 = #self.components.keys(wx.WXK_TAB) > > =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 #event.m_keyCode =3D = wx.WXK_TAB > > thanks > > Ralph Heimburger > > Babcock & Wilcox Enterprise Systems > > 330-860-1858 > The wxPython 2.5.2.x MigrationGuide.html document has an example using=20= wx.NavigationKeyEvent, which is new with wxPython 2.5.2. Adapting that=20= to cause the return key to behave the same as the tab key using=20 PythonCard event attribute names gives us this example: def on_keyDown(self, event): # wx.WXK_RETURN is 13 if event.keyCode =3D=3D wx.WXK_RETURN: if event.shiftDown: flags =3D wx.NavigationKeyEvent.IsBackward else: flags =3D wx.NavigationKeyEvent.IsForward if event.controlDown: flags |=3D wx.NavigationKeyEvent.WinChange event.target.Navigate(flags) else: event.skip() Remember that if you use an on_keyDown event handler, all components=20 that receive key events that don't have their own keyDown handlers will=20= end up using that event handler. If you just want it to handle=20 TextField components you might want to add a test for the class or=20 class name and call event.skip() if necessary. Here's one possibility: if event.target.__class__.__name__ =3D=3D 'TextField': ... ka= |