]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/samples/wxPIA_book/Chapter-10/popupmenu.py
3 class MyFrame(wx
.Frame
):
5 wx
.Frame
.__init
__(self
, None, -1,
7 self
.panel
= p
= wx
.Panel(self
)
9 exit
= menu
.Append(-1, "Exit")
10 self
.Bind(wx
.EVT_MENU
, self
.OnExit
, exit
)
12 menuBar
= wx
.MenuBar()
13 menuBar
.Append(menu
, "Menu")
14 self
.SetMenuBar(menuBar
)
17 "Right-click on the panel to show a popup menu",
20 self
.popupmenu
= wx
.Menu()
21 for text
in "one two three four five".split():
22 item
= self
.popupmenu
.Append(-1, text
)
23 self
.Bind(wx
.EVT_MENU
, self
.OnPopupItemSelected
, item
)
24 p
.Bind(wx
.EVT_CONTEXT_MENU
, self
.OnShowPopup
)
27 def OnShowPopup(self
, event
):
28 pos
= event
.GetPosition()
29 pos
= self
.panel
.ScreenToClient(pos
)
30 self
.panel
.PopupMenu(self
.popupmenu
, pos
)
33 def OnPopupItemSelected(self
, event
):
34 item
= self
.popupmenu
.FindItemById(event
.GetId())
36 wx
.MessageBox("You selected item '%s'" % text
)
39 def OnExit(self
, event
):
43 if __name__
== "__main__":
44 app
= wx
.PySimpleApp()