I'm trying to update a menu to show a list of open documents like gedit's document menu. I get a segfault while the menu is updating that I can't reproduce by writing a simplified program, so I'm trying to debug what I've got. The program looks like this:
# self is the menu bar
# using the ID of a static item in the menu (ID_CLOSE_ALL)
frame.Bind(wx.EVT_UPDATE_UI, self.onUpdateDocList, id=wx.ID_CLOSE_ALL)
def onUpdateDocList(self, evt):
menu = self.documents_menu
# clear documents from the menu
# I've tried many different approaches that work,
# but none avoid a segfault.
item = menu.FindItemByPosition(6)
while item:
menu.Delete(item.Id)
item = menu.FindItemByPosition(6)
# add documents
for title in self.frame.doc_titles:
menu.Append(-1, title)
# WITH PRINT STATEMENTS, THE SEGFAULT SEEMS TO OCCUR HERE
I've not used core files and gdb before, but based on some other threads I gave it a shot, produced a core file and fed it into gdb. This is what I got:
Program terminated with signal 11, Segmentation fault.
[New process 11658]
[New process 11923]
[New process 11915] #0 0xb71bb62d in wxMenuBase::UpdateUI ()
from /usr/lib/libwx_gtk2u_core-2.8.so.0
(gdb) q
My program runs multiple processes, so I guess that's what the "New process" entries are. The other processes don't run any wx code. They just run database queries and send the results back to the main process, which does all the GUI stuff.
Is there something more I can do to debug this? Maybe there's a better approach than using EVT_UPDATE_UI. Trying to update the menu as documents are opened/closed/altered would be a mess. That's why I'm trying to update the menu when it's selected.
Does it make a difference if you bind to wx.EVT_MENU_OPEN instead of
wx.EVT_UPDATE_UI?
Cheers, Frank
···
2010/2/18 Randall Smith <randall@tnr.cc>:
Using wxpython 2.8.9.1-0ubuntu6
I'm trying to update a menu to show a list of open documents like gedit's
document menu. I get a segfault while the menu is updating that I can't
reproduce by writing a simplified program, so I'm trying to debug what I've
got. The program looks like this:
# self is the menu bar
# using the ID of a static item in the menu (ID_CLOSE_ALL)
frame.Bind(wx.EVT_UPDATE_UI, self.onUpdateDocList, id=wx.ID_CLOSE_ALL)
Also see wx.FileHistory in the demo for a completely different way to do it.
···
On 2/18/10 12:06 PM, Frank Niessink wrote:
2010/2/18 Randall Smith<randall@tnr.cc>:
Using wxpython 2.8.9.1-0ubuntu6
I'm trying to update a menu to show a list of open documents like gedit's
document menu. I get a segfault while the menu is updating that I can't
reproduce by writing a simplified program, so I'm trying to debug what I've
got. The program looks like this:
# self is the menu bar
# using the ID of a static item in the menu (ID_CLOSE_ALL)
frame.Bind(wx.EVT_UPDATE_UI, self.onUpdateDocList, id=wx.ID_CLOSE_ALL)
Does it make a difference if you bind to wx.EVT_MENU_OPEN instead of
wx.EVT_UPDATE_UI?
Using wxpython 2.8.9.1-0ubuntu6
I'm trying to update a menu to show a list of open documents like gedit's
document menu. I get a segfault while the menu is updating that I can't
reproduce by writing a simplified program, so I'm trying to debug what I've
got. The program looks like this:
# self is the menu bar
# using the ID of a static item in the menu (ID_CLOSE_ALL)
frame.Bind(wx.EVT_UPDATE_UI, self.onUpdateDocList, id=wx.ID_CLOSE_ALL)
Does it make a difference if you bind to wx.EVT_MENU_OPEN instead of
wx.EVT_UPDATE_UI?
Cheers, Frank
Thanks. That worked. So now it looks like this:
frame.Bind(wx.EVT_MENU_OPEN, self.updateDocumentsMenu)
def updateDocumentsMenu(self, evt):
"""update the list of documents in the documents menu
"""
if evt.EventObject != self.documents_menu:
evt.Skip()
return
# do the update
2010/2/18 Randall
Smith:
Does it make a difference if you bind to wx.EVT_MENU_OPEN instead of
wx.EVT_UPDATE_UI?
Also see wx.FileHistory in the demo for a completely different way to
do it.
`I had never looked at wx.FileHistory before. Looking into it
also led me to wx.DocManager and friends, which will be very useful for
me.
For this task, I can’t see how FileHistory would work because it
focuses on appending without any apparent way to clear, remove or
sort. The document list I’m generating corresponds to documents opened
in tabs. It has to represent the order and state (modified or not) of
the open documents.
For this task, I can't see how FileHistory would work because it focuses
on appending without any apparent way to clear, remove or sort.
I think the intent is to keep the files in MRU order (most recently used), which is typically how it is done for recent files lists in menus.
The
document list I'm generating corresponds to documents opened in tabs. It
has to represent the order and state (modified or not) of the open
documents.
Yes, this indeed sounds like something different than what wx.FileHistory was designed for, more like what is usually done for the Window menu in applications with an MDI UI.