I really don't grok accelerators and menus, and could use some help.
Their use seems totally unintuitive to me.
What I want is an standard Edit menu with Cut, Copy, and Paste. I then
have two TextCtrl widgets that I want to bind to these menu items. I
can't seem to make it work. Can someone tell me what I'm doing wrong?
Here's what I've got so far. It's just a condensed version of a bigger
program where different widgets may have different implementations of
OnCopy, OnCut, OnPaste. When I run this code on RHEL, wxPython
2.8.9.1, python 2.5, pressing control-c in either of the text controls
doesn't seem to do anything.
import wx
import wx.aui as aui
class CustomTextCtrl(wx.TextCtrl):
def __init__(self, parent, id, text):
wx.TextCtrl.__init__(self, parent, id, text,
style=wx.TE_MULTILINE, size=(200,100))
self.Bind(wx.EVT_MENU, self.OnCut, id=wx.ID_CUT)
self.Bind(wx.EVT_MENU, self.OnCopy, id=wx.ID_PASTE)
self.Bind(wx.EVT_MENU, self.OnPaste, id=wx.ID_PASTE)
def OnCopy(self, event): print id, "OnCopy..."
def OnCut(self, event): print id, "OnCut..."
def OnPaste(self, event): print id, "OnPaste..."
class TabPanel(wx.Panel):
def __init__(self, parent):
wx.Panel.__init__(self, parent=parent, id=wx.ID_ANY)
sizer = wx.BoxSizer(wx.VERTICAL)
one = CustomTextCtrl(self, wx.ID_ANY, "hello, world\n")
two = CustomTextCtrl(self, wx.ID_ANY, "Lorem Ipsum\n")
sizer = wx.BoxSizer(wx.HORIZONTAL)
sizer.Add(one, 1, wx.EXPAND|wx.ALL, 5)
sizer.Add(two, 1, wx.EXPAND|wx.ALL, 5)
self.SetSizer(sizer)
class MyFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, wx.ID_ANY,
"AGW AUI Notebook Tutorial",
size=(500,200))
self._mgr = aui.AuiManager()
self._mgr.SetManagedWindow(self)
notebook = aui.AuiNotebook(self)
panel = TabPanel(notebook)
notebook.AddPage(panel, "Whatever", False)
self._mgr.AddPane(notebook)
self._mgr.Update()
editMenu = wx.Menu()
editMenu.Append(wx.ID_CUT)
editMenu.Append(wx.ID_COPY)
editMenu.Append(wx.ID_PASTE)
mb = wx.MenuBar()
mb.Append(editMenu, "&Edit")
self.SetMenuBar(mb)
if __name__ == "__main__":
app = wx.PySimpleApp()
frame = MyFrame()
frame.Show()
app.MainLoop()