I meant to write up a post on this within a week of reading about it, but then things got busy and I forgot. Anyway, there’s a new widget in the wxPython toolkit called the ShortcutEditor. You can read about it on the wxPython mailing list. You’ll probably have to update the agw lib folder on your local drive unless you run from SVN a lot. It may be included in the latest Phoenix builds too, but I’m not sure. If you want to check it out, do the following on the command line (assuming you have svn installed)
svn checkout http://svn.wxwidgets.org/svn/wx/wxPython/3rdParty/AGW/agw/
That will create an “agw” folder in whatever your current directory is. You’ll want to copy that over the top of the one that’s in your wxPython installation. On my machine, it was in the following location: C:\Python27\Lib\site-packages\wx-2.9.3-msw\wx\lib There’s a simple demo application included in the source code. I’m reproducing it here so you can see try running it too:
import wx import wx.lib.agw.shortcuteditor as SE class MyFrame(wx.Frame): def __init__(self, parent): wx.Frame.__init__(self, parent, -1, "ShortcutEditor Demo") bar = wx.MenuBar() menu = wx.Menu() menu.Append(101, "&Mercury", "This the text in the Statusbar") menu.Append(102, "&Venus", "") menu.Append(103, "&Earth", "You may select Earth too") menu.AppendSeparator() menu.Append(104, "&Close", "Close this frame") bar.Append(menu, 'File') self.SetMenuBar(bar) dlg = SE.ShortcutEditor(self) dlg.FromMenuBar(self) if dlg.ShowModal() == wx.ID_OK: # Changes accepted, send back the new shortcuts to the TLW wx.MenuBar dlg.ToMenuBar(self) dlg.Destroy() # our normal wxApp-derived class, as usual app = wx.App(0) frame = MyFrame(None) app.SetTopWindow(frame) frame.Show() app.MainLoop()
If you run the code above, you should see something like this on your screen:
Then you can start changing short cut keys. I thought it was really cool. According to the file’s internal documentation, it can change menu shortcut keys and AcceleratorTables. You should give it a try sometime. I think this will be a pretty helpful utility to add to my own scripts.