I'm trying to understand how to put an accelerator on a menu, yet rely
on the default behavior of that keystroke in text controls.
For example, I want to create an Edit menu on the menubar, with an
item labelled "Cut". I want that to have "Ctrl+X" appear as an
accelerator on the menu item. However, as soon as I do that, the
default cut behavior in my text controls is lost because the text
control never sees the keystroke.
What's the standard way to deal with this problem? Do I have to create
an event binding that figures out which widget has focus and then call
wx.PostEvent() to send an appropriate key event to that window? That
sounds so kludgy it makes me think I'm missing something fundamental.
What am I missing?
For the sake of discussion, here's the code I'm starting with. What I
am hoping to figure out is how to get the built-in cut functionality
to work with as little extra code as possible. I'm using wxPython
2.8.9.1 and python 2.5.
#--- code begins here
import wx
ID_CUT = wx.NewId()
class MyFrame(wx.Frame):
def __init__(self, parent, ID, title):
wx.Frame.__init__(self, parent, ID, title,
wx.DefaultPosition)
editMenu = wx.Menu()
editMenu.AppendItem(wx.MenuItem(editMenu, ID_CUT,
"Cu&t\tCtrl+X"))
menuBar = wx.MenuBar()
menuBar.Append(editMenu, "&Edit")
self.SetMenuBar(menuBar)
tc = wx.TextCtrl(self, style=wx.TE_MULTILINE)
class MyApp(wx.App):
def OnInit(self):
frame = MyFrame(None, -1, "Example")
frame.Show(True)
self.SetTopWindow(frame)
return True
app = MyApp(0)
app.MainLoop()
# -- code ends here