I am using wxFileHistory in a file menu, but I would also like to use a
separate wxFileHistory instance for another menu dealing with scripts run
from within the app that are not associated with the files the user edits,
which is what the first file history is used for.
Setting up the menus seems to work fine, something like:
self.fileHistory = wx.wxFileHistory()
fileMenu = self.GetMenuBar().GetMenu(0)
self.fileHistory.UseMenu(fileMenu)
self.scriptFileHistory = wx.wxFileHistory()
scriptFileMenu = self.GetMenuBar().GetMenu(4)
self.scriptFileHistory.UseMenu(scriptFileMenu)
The problem appears to be that I need to use the special file history menu
ids to catch the events as a menu item is selected. This normally looks
like:
wx.EVT_MENU_RANGE(self, wx.wxID_FILE1, wx.wxID_FILE9,
self.OnFileHistory)
which is processed as
def OnFileHistory(self, event):
fileNum = event.GetId() - wx.wxID_FILE1
path = self.fileHistory.GetHistoryFile(fileNum)
...
The EVT_MENU_RANGE binding above will cause selections from either
fileHistory or scriptFileHistory to go to the OnFileHistory method. However,
there doesn't appear to be a way to figure out the menu that the menu item
was selected from based on the wxEVT_COMMAND_MENU_RANGE event.
Since the ids will be the same in both menus, wxMenu::FindItemById won't
work. Menu (command) events don't have a string set, so I can't use
GetString either, which rule out a hack of sticking a tab or some other
character sequence on the beginning or end of the path before calling
AddFileToHistory.
So, is there a workaround?
ka