From: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX - 2008-03-28 11:11:01
|
On 27/03/2008 20:23, Terry Maloney wrote: > > I've figured out how to add menu items easily enough using PythonCard's > menu.py module's appendMenuItem method. But the > corresponding deleteMenuItem is only a stub. I can almost get the > underlying wx._core's.Menu's DeleteItem or RemoveItem to work, but not > quite ... I can't seem to get the parameters right, and wxPython is > still rather daunting at this point. > > Any pointers to a faq, or a few lines of code if it's trivial, would be > greatly appreciated. I managed to get something to work, but it's a bit messy and tied to my very simple test application, so for a 'proper' application it might not help much. 1. menu.py - since the function doesn't appear to do anything, change from def deleteMenuItem( self, aName ) : pass to def deleteMenuItem( self, aMenuItem ) : self.items.remove(aMenuItem) self.DeleteItem(aMenuItem) 2. I then needed some sample code, so I took minimal.py, which has a menu with one item and after a bit of experimenting got to this: ----------------------------- #!/usr/bin/python """ __version__ = "$Revision: 1.10 $" __date__ = "$Date: 2004/04/24 22:13:31 $" """ from PythonCard import model class Minimal(model.Background): def on_textUpdate(self, event): currentMenu = self.menuBar.menus[0] items = currentMenu.getMenuItems() if(len(items)): print "Ha! I've deleted your menu item" itemToDelete = items[0] currentMenu.deleteMenuItem(itemToDelete) if __name__ == '__main__': app = model.Application(Minimal) app.MainLoop() ----------------------------- What should happen is that as soon as you start typing into the text area, the exit menu item disappears. -- XXXXXXXXXXX |