Sometimes, an individual page or control on a page needs a way to give some additional options on which actions are available to be performed. The use of a context (or right-click) menu is often used to fill this role. In this recipe, we will look at how to create, show, and manage a context menu.
Here's how you can display a context menu:
In order to help manage the creation and destruction of a
Menu
object, we will make a small helper class that will be responsible for theMenu
object, as follows:class ContextMenuMgr(object): def __init__(self, parent): super(ContextMenuMgr, self).__init__() assert isinstance(parent, wx.Window) assert hasattr(parent, 'GetPopupMenu'), \ "parent must implement GetPopupMenu" self.window = parent self.window.Bind(wx.EVT_CONTEXT_MENU, self.OnContextMenu)
This helper class will have the following method, which is bound to the preceding...