Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > How do I insert a menu item in an existing menu.

Reply
Thread Tools

How do I insert a menu item in an existing menu.

 
 
BlueFlash
Guest
Posts: n/a
 
      08-26-2009
Idea: Use of a RecentFileList, update element 0 with new file opened.

Appending a menu is easy
menu.Append(-1, "Menu Name")

when I try to insert a new menu item
menu.Insert(-1, position, "Menu Name")

does not work.

full code:
def addnew(self, position, path):
path = path.strip()
try:
self.filelist.index(path) # index() throws ValueError
if path does not exist.
except:
# ValueError, path is not in list, so add it:
if position >= len(self.filelist):
self.filelist.append(path)
item = self.menu.Append(-1, path) #this does return a
menu item
self.window.Bind(wx.EVT_MENU, self.event, item)
else:
self.filelist.insert(position, path)
item = self.menu.InsertItem(-1, position, path) # does
Not return a menu item. throws some exception.
print item
#self.window.Bind(wx.EVT_MENU, self.event, item)


How do I remove a menu item from a menu? The RecentUsedList is eg: 4
element long. When opening a new file, this should be added at the
top, and the 4th element must be dropped.
 
Reply With Quote
 
 
 
 
MRAB
Guest
Posts: n/a
 
      08-26-2009
BlueFlash wrote:
> Idea: Use of a RecentFileList, update element 0 with new file opened.
>
> Appending a menu is easy
> menu.Append(-1, "Menu Name")
>
> when I try to insert a new menu item
> menu.Insert(-1, position, "Menu Name")
>
> does not work.
>


The following comments are the result of a brief search of the web, so
I'm not sure whether they're correct, but they might be worth a try.

> full code:
> def addnew(self, position, path):
> path = path.strip()
> try:
> self.filelist.index(path) # index() throws ValueError
> if path does not exist.
> except:
> # ValueError, path is not in list, so add it:
> if position >= len(self.filelist):
> self.filelist.append(path)
> item = self.menu.Append(-1, path) #this does return a
> menu item
> self.window.Bind(wx.EVT_MENU, self.event, item)
> else:
> self.filelist.insert(position, path)
> item = self.menu.InsertItem(-1, position, path) # does
> Not return a menu item. throws some exception.


I think it should be:

item = self.menu.InsertItem(position, -1, path)

> print item
> #self.window.Bind(wx.EVT_MENU, self.event, item)
>
>
> How do I remove a menu item from a menu? The RecentUsedList is eg: 4
> element long. When opening a new file, this should be added at the
> top, and the 4th element must be dropped.


I think you need the 'Remove' method.
 
Reply With Quote
 
 
 
 
John Ladasky
Guest
Posts: n/a
 
      08-26-2009
You might want to direct your wxPython questions to the dedicated
wxPython newsgroup. It's Google-only, and thus not part of the Usenet
hierarchy. But it's the most on-topic newsgroup you will find.

http://groups.google.com/group/wxpython-users

I attempted to crosspost this article to wx-python users, but that
doesn't work for non-Usenet groups... Good luck!
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
ASP.Net 2.0 Insert new item, then display this new item in Edit mo Ann ASP .Net Web Controls 0 03-28-2007 01:11 AM
How do I set selected Menu item in a asp:menu control? goran.strand@gmail.com ASP .Net 0 12-22-2006 08:05 AM
"Shutdown" menu item disapper from START menu......... vik Computer Support 5 08-09-2006 03:14 PM
How to do bitmap icon in front of menu-items in Java? what is the class for menu-item in Java? gino Java 12 09-01-2004 04:14 PM



Advertisments