Here is how implemented a Recent File List.
# create the menu items and other variables:
self.recentfilelist = []
self.lastrecentID = RECENTFILE_BASE ##RECENTFILE_BASE = 81
self.menuF = wxMenu()
...#other File menu items added here
self.menuRecentFiles = wxMenu()
self.menuF.AppendMenu(ID_FILE_RECENTFILE, 'Recent Files',
self.menuRecentFiles, '')
...
self.mainmenu.Append(self.menuF, '&File')
...
Method to add files to the menu; called when user opens a file via the File
menu, or when they drop a file via drag-and drop. 'parmaccess' object
referenced below is an XML parser that reads from and writes to an
application configuration file. Here it is used to determine how many files
are allowed to be listed in the menu, since that is a configurable option in
this application (wxPython-based IDE tailored to another Python app).
Selecting an item from the recent file menu results in the file being opened
or, if it is already open, being selected as the active document.
def AddToRecentFiles(self, path, add = 1):
"""Add the file specified in path to the Recent File list and update
menu contents."""
if path == None or path == '':
return
if add: #add path to the menu
count = self.parmaccess.ReadParmInt(SECTION_RECENT,
RECENT_COUNT)
if count == None:
count = 1
if len(self.recentfilelist) > 0:
if len(self.recentfilelist) >= count: #Will we go over the
limit? If so, delete one
fid =
self.menuRecentFiles.FindItem(self.recentfilelist[0])
self.menuRecentFiles.DestroyId(fid)
del self.recentfilelist[0]#remove first item from list
if path not in self.recentfilelist:
self.recentfilelist.append(path)
self.lastrecentID += 1
menuItem = wxMenuItem(self.menuRecentFiles,
self.lastrecentID, path)
#issue #2: wxMenuItem 'feature' - slashes are wrong
direction on Linux
self.menuRecentFiles.AppendItem(menuItem)
EVT_MENU(self, self.lastrecentID, self.OnFileRecentFile)
... (other unused code followed)
Here is the code that gets called from the EVT_MENU macro above...
def OnFileRecentFile(self, event):
evtid = event.GetId()
path = self.menuRecentFiles.GetLabel(evtid)
#slashes are wrong direction under Linux, and menus cannot be
created with them going
#in the correct direction, so check them here and change if
necessary
if path != '' and path != None:
if sys.platform.find('linux') > -1: #issue #2
path = path.replace('\\', '/')
if not self.scriptnbk.DocAlreadyOpen(path, 1):
self.OpenDoc(path)
Hope this helps.
Ron Clarke
···
-----Original Message-----
From: A [mailto:printers@sendme.cz]
Sent: Tuesday, September 25, 2001 12:34 AM
To: wxpython-users@lists.wxwindows.org
Subject: [wxPython] MRU
Hi,
Does anyone know how to add (implement) ,with wxPython,
a list of Most-Recently-Used files that appears on the File menu?
Can you please give an example?
Thank you for help.
Ladislav
_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwindows.org
http://lists.wxwindows.org/mailman/listinfo/wxpython-users