>> So the problem comes when you run the example below and then exit:
>> If you click on "All music" and then exit, then everything's fine.
>> If you click on "Artist" and then exit, I get a Python or
>> wxPython crash on Windows. This is with Win98, BeOpen Python 2.0,
>> wxPython 2.2.5.
>
> It doesn't crash here (on Win2k.) Nothing in the code is jumping out at
me
> as being wrong either.
Any chance of a Win98 user on this list reproducing my problem.
I've got crashes with this code on two different Win98 boxes
with BeOpen Python 2.0 and wxPython 2.2.2 and 2.2.5. It's not
a complete show-stopper for me, but it's irritating enough
that I'd like to know what the problem is.
The slightly modified version below shows what the problem is. The output
on win2k is this:
[C:\temp\others] crash2.py
OnSelChanged -- begin
OnSelChanged -- end
OnSelChanged -- begin
OnSelChanged -- end
OnCloseWindow - begin
OnCloseWindow - end
and on win98 it is this:
c:\stuff>python crash2.py
OnSelChanged -- begin
OnSelChanged -- end
OnSelChanged -- begin
OnSelChanged -- end
OnCloseWindow - begin
OnCloseWindow - end
OnSelChanged -- begin
OnSelChanged -- end
So you see there is a selection changed event AFTER the program has started
shutting down, probably as the selected tree item is being deleted. My
guess is that when your event handler executes this last time the list
window has already been destroyed and so is accessing memory that no longer
belongs to the process.
The fix is to either put a guard in the event handler (set a flag in
OnCloseWindow and check it there,) or perhaps to select the tree root item
in OnCloseWindow or wherever makes sense to do it.
BTW, I've found putting print statements in strategic places like this
really helpful in understanding how things work, what order events are
coming in, etc.
# ------------- BEGIN SAMPLE CODE ----------------------
from wxPython.wx import *
class MP3List(wxListCtrl):
def __init__( self, parent ):
wxListCtrl.__init__( self, parent, wxNewId() )
def Set_contents( self, song_list ):
self.ClearAll()
for row_num in range( len(song_list) ):
self.InsertStringItem( row_num, song_list[row_num] )
class RepositoryTree(wxTreeCtrl):
def __init__(self, parent, list_win ):
wxTreeCtrl.__init__( self, parent, wxNewId() )
self.list_window = list_win
EVT_TREE_SEL_CHANGED( self, self.GetId(), self.On_selection_change )
def Set_contents( self ):
self.root = self.AddRoot( "All music" )
self.artist_index = self.AppendItem( self.root, "Artist" )
self.Expand( self.root )
def On_selection_change( self, event ):
print "OnSelChanged -- begin"
#self.list_window.Set_contents( ["Song"] )
print "OnSelChanged -- end"
class Repository(wxSplitterWindow):
def __init__(self, parent):
wxSplitterWindow.__init__( self, parent, -1 )
self.list_window = MP3List( self )
self.tree_window = RepositoryTree( self, self.list_window )
self.tree_window.Set_contents()
self.SplitVertically( self.tree_window, self.list_window )
self.SetMinimumPaneSize( 100 )
self.SetSashPosition( 150 )
class ParoFrame(wxFrame):
def __init__(self, parent, id, title):
wxFrame.__init__( self, parent, id, title )
self.repository_win = Repository( self )
EVT_CLOSE(self, self.OnCloseWindow)
def OnCloseWindow( self, event ):
print "OnCloseWindow - begin"
self.Destroy()
print "OnCloseWindow - end"
class ParoApp(wxApp):
def OnInit( self ):
self.frame = ParoFrame( NULL, -1, "MyParo" )
self.frame.Show( TRUE )
self.SetTopWindow( self.frame )
return TRUE
paro_instance = ParoApp(0)
paro_instance.MainLoop()
# ------------- END SAMPLE CODE ----------------------
···
On Monday, February 19, 2001 at 12:03:59 AM, Robin Dunn wrote:
--
Robin Dunn
Software Craftsman
robin@AllDunn.com Java give you jitters?
http://wxPython.org Relax with wxPython!
_______________________________________________
wxPython-users mailing list
wxPython-users@lists.sourceforge.net
http://lists.sourceforge.net/lists/listinfo/wxpython-users