]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/tests/test_popupMenuChecks.py
9 class TestPanelBase(wx
.Panel
):
10 def __init__(self
, parent
):
11 wx
.Panel
.__init
__(self
, parent
, style
=wx
.BORDER_SUNKEN
)
14 self
.Bind(wx
.EVT_CONTEXT_MENU
, self
.OnContextMenu
)
15 self
.Bind(wx
.EVT_MENU
, self
.OnItem1
, id=ID_ITEM1
)
16 self
.Bind(wx
.EVT_MENU
, self
.OnItem2
, id=ID_ITEM2
)
17 wx
.StaticText(self
, -1, self
.__doc
__.strip(), (0,0))
19 def OnItem1(self
, evt
):
21 self
.item1
= not self
.item1
23 def OnItem2(self
, evt
):
25 self
.item2
= not self
.item2
28 class TestPanel1(TestPanelBase
):
30 Pre-create and reuse the menu
32 def __init__(self
, parent
):
33 TestPanelBase
.__init
__(self
, parent
)
35 self
.menu
.Append(ID_ITEM1
, "Item 1", kind
=wx
.ITEM_CHECK
)
36 self
.menu
.Append(ID_ITEM2
, "Item 2", kind
=wx
.ITEM_CHECK
)
37 self
.menu
.Check(ID_ITEM1
, self
.item1
)
38 self
.menu
.Check(ID_ITEM2
, self
.item2
)
40 def OnContextMenu(self
, evt
):
41 self
.PopupMenu(self
.menu
)
44 class TestPanel2(TestPanelBase
):
46 This one recreates the menu and sets the checks each time
48 def __init__(self
, parent
):
49 TestPanelBase
.__init
__(self
, parent
)
51 def OnContextMenu(self
, evt
):
53 menu
.Append(ID_ITEM1
, "Item 1", kind
=wx
.ITEM_CHECK
)
54 menu
.Append(ID_ITEM2
, "Item 2", kind
=wx
.ITEM_CHECK
)
55 menu
.Check(ID_ITEM1
, self
.item1
)
56 menu
.Check(ID_ITEM2
, self
.item2
)
61 class TestPanel3(TestPanelBase
):
63 Use an EVT_UPDATE_UI handler to set the checks
65 def __init__(self
, parent
):
66 TestPanelBase
.__init
__(self
, parent
)
67 self
.Bind(wx
.EVT_UPDATE_UI
, self
.OnUpdateUI_Item1
, id=ID_ITEM1
)
68 self
.Bind(wx
.EVT_UPDATE_UI
, self
.OnUpdateUI_Item2
, id=ID_ITEM2
)
70 def OnContextMenu(self
, evt
):
72 menu
.Append(ID_ITEM1
, "Item 1", kind
=wx
.ITEM_CHECK
)
73 menu
.Append(ID_ITEM2
, "Item 2", kind
=wx
.ITEM_CHECK
)
77 def OnUpdateUI_Item1(self
, evt
):
78 print "OnUpdateUI_Item1"
81 def OnUpdateUI_Item2(self
, evt
):
82 print "OnUpdateUI_Item2"
87 frm
= wx
.Frame(None, title
="Right-click on a panel...")
88 pnl1
= TestPanel1(frm
)
89 pnl2
= TestPanel2(frm
)
90 pnl3
= TestPanel3(frm
)
91 sizer
= wx
.BoxSizer(wx
.VERTICAL
)
93 sizer
.Add(pnl1
, 1, wx
.EXPAND
)
94 sizer
.Add(pnl2
, 1, wx
.EXPAND
)
95 sizer
.Add(pnl3
, 1, wx
.EXPAND
)