- menu = wxMenu()
- tPopupID1 = 0
- tPopupID2 = 1
- tPopupID3 = 2
- tPopupID4 = 3
- tPopupID5 = 5
- #menu.Append(tPopupID1, "One")
- item = wxMenuItem(menu, tPopupID1,"One")
- item.SetBitmap(images.getSmilesBitmap())
- menu.AppendItem(item)
- menu.Append(tPopupID2, "Two")
- menu.Append(tPopupID3, "Three")
- menu.Append(tPopupID4, "DeleteAllItems")
- menu.Append(tPopupID5, "GetItem")
- EVT_MENU(self, tPopupID1, self.OnPopupOne)
- EVT_MENU(self, tPopupID2, self.OnPopupTwo)
- EVT_MENU(self, tPopupID3, self.OnPopupThree)
- EVT_MENU(self, tPopupID4, self.OnPopupFour)
- EVT_MENU(self, tPopupID5, self.OnPopupFive)
- self.PopupMenu(menu, wxPoint(self.x, self.y))
+
+ # only do this part the first time so the events are only bound once
+ if not hasattr(self, "popupID1"):
+ self.popupID1 = wx.NewId()
+ self.popupID2 = wx.NewId()
+ self.popupID3 = wx.NewId()
+ self.popupID4 = wx.NewId()
+ self.popupID5 = wx.NewId()
+ self.popupID6 = wx.NewId()
+
+ self.Bind(wx.EVT_MENU, self.OnPopupOne, id=self.popupID1)
+ self.Bind(wx.EVT_MENU, self.OnPopupTwo, id=self.popupID2)
+ self.Bind(wx.EVT_MENU, self.OnPopupThree, id=self.popupID3)
+ self.Bind(wx.EVT_MENU, self.OnPopupFour, id=self.popupID4)
+ self.Bind(wx.EVT_MENU, self.OnPopupFive, id=self.popupID5)
+ self.Bind(wx.EVT_MENU, self.OnPopupSix, id=self.popupID6)
+
+ # make a menu
+ menu = wx.Menu()
+ # add some items
+ menu.Append(self.popupID1, "FindItem tests")
+ menu.Append(self.popupID2, "Iterate Selected")
+ menu.Append(self.popupID3, "ClearAll and repopulate")
+ menu.Append(self.popupID4, "DeleteAllItems")
+ menu.Append(self.popupID5, "GetItem")
+ menu.Append(self.popupID6, "Edit")
+
+ # Popup the menu. If an item is selected then its handler
+ # will be called before PopupMenu returns.
+ self.PopupMenu(menu, (self.x, self.y))