In the demo application listed below, when the user presses <Enter>
the OnEnter() method is called, printing a message to the console.
When the user presses <Tab>, focus is passed to the next text
control. When the user presses <Tab> again, focus is passed to the
slider, then to the button, then back to the first text control.
But NOW when the user presses <Enter> the OnEnter() method is NO
LONGER called. This is because the button is now set as the default
button for <Return> for the panel.
Is there a way to remove a given control (especially the button,
and probably the slider) from the tab-order, so that the button
never becomes the "default" for <Return>?
Also, is there a way to force one text control to pass the focus to
the next text control in the tab order? Is there a command that can
be placed in the OnEnter() method?
···
#################################################################
from wxPython.wx import *
class MyTextCtrl(wxTextCtrl):
def __init__(self, parent):
wxTextCtrl.__init__(self, parent, -1)
EVT_TEXT_ENTER(self, self.GetId(), self.OnEnter)
def OnEnter(self, event):
print 'enter key pressed'
# put code here to tab on to next text control
class TopWin(wxFrame):
def __init__(self, parent=None, id=-1, title='Focus Demo'):
wxFrame.__init__(self, parent, id, title)
panel = wxPanel(self, -1)
t1 = MyTextCtrl(panel)
t2 = MyTextCtrl(panel)
s1 = wxSlider(panel, -1, 0, 0, 1000)
b1 = wxButton(panel, 10, 'Press Me')
EVT_BUTTON(self, 10, self.OnPress)
box1 = wxBoxSizer(wxVERTICAL)
box1.Add(t1, 1, wxEXPAND)
box1.Add(t2, 1, wxEXPAND)
box1.Add(s1, 1, wxEXPAND)
box1.Add(b1, 1, wxEXPAND)
panel.SetSizer(box1)
panel.Layout()
panel.SetAutoLayout(true)
box1.Fit(self)
box1.SetSizeHints(self)
def OnPress(self, event):
print 'Button Pressed'
class App(wxApp):
def OnInit(self):
top = TopWin()
top.Show(true)
self.SetTopWindow(top)
return true
if __name__ == '__main__':
app = App(0)
app.MainLoop()
#################################################################
=====
Donnal Walter
Arkansas Children's Hospital
__________________________________________________
Do You Yahoo!?
Send FREE video emails in Yahoo! Mail!
http://promo.yahoo.com/videomail/