Hi!
I have a wxGrid object with a custom grid base, which "produces"
tables with different count of rows and columns and different sets of
columns labels. It works fine, but when I try to call the
AutoSizeColumns() method of my wxGrid object and then change the table
to be shown inside it, the program crashes with core dump. The same
happens when I try to manually change size of a column and then go to
another table again.
Widgets insertion diagram:
wxGrid -> wxSplitterWindow -> wxBoxSizer -> wxPanel -> wxFrame
System: FreeBSD 4.7-STABLE, wxGTK-2.4.0, wxPython-2.4.0.7, gtk-1.2.10.
Here are some fragments of the source:
···
--------------------
class MyFrame( wxFrame ):
...
def StateChanged( self,dummy ):
self.grid.BeginBatch()
self.gridBase.TableStateChanged()
self.grid.SetGridCursor( 0,0 )
self.grid.MakeCellVisible( 0,0 )
self.grid.AdjustScrollbars()
self.grid.AutoSizeColumns() ## the program crashes here!
self.grid.ForceRefresh()
self.grid.EndBatch()
class MyGridBase( wxPyGridTableBase ):
self.fields = .... ## tuple of tuples of strings
def __init__( self,data,table ):
wxPyGridTableBase.__init__( self )
self.data = data
self.table = table
self.rowcount = self.colcount = 0
def TableStateChanged( self ):
## ... some calculations on self.data ...
rowcount = len( self.data )
colcount = len( self.data[ 0 ] )
msg1 = wxGridTableMessage( self,wxGRIDTABLE_NOTIFY_ROWS_APPENDED,rowcount - self.rowcount )
msg2 = wxGridTableMessage( self,wxGRIDTABLE_NOTIFY_COLS_APPENDED,colcount - self.colcount )
msg3 = wxGridTableMessage( self,wxGRIDTABLE_REQUEST_VIEW_GET_VALUES )
for msg in [ msg1,msg2,msg3 ]:
self.GetView().ProcessTableMessage( msg )
self.rowcount = rowcount
self.colcount = colcount
def GetNumberRows( self ):
if self.data:
return len( self.data )
return 0
def GetNumberCols( self ):
if self.data:
return len( self.data[ 0 ] )
return 0
def IsEmptyCell( self,row,col ):
return false ## there are no empty cells, see GetValue()
def GetValue( self,row,col ):
if self.data:
try:
return self.data[ row ][ self.fields[ self.table[ "appe" ]][ col ]]
except KeyError:
return "?"
def GetColLabelValue( self,col ):
if self.data:
return self.fields[ self.table[ "appe" ]][ col ]
def SetValue( self,row,col,value ):
pass ## the grid is not editable
--------------------
Any ideas?
With best regards,
Dmytro Rud.