Re: Beginner question re dynamic menus

Terry Maloney <[email protected]> Sat, 29 Mar 2008 11:58:32 -0400
Newsgroups gmane.comp.python.pythoncard
Message-ID <[email protected]>
Thanks very much Neil ... exactly what I was looking for, and it's  
working perfectly in my test app as well.


On Mar 28, 2008, at 7:10 AM, Neil Hughes wrote:
> 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.
>
> -- 
> Neil Hughes


-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace