3 import  wx
.grid 
as  gridlib
 
   5 #--------------------------------------------------------------------------- 
   7 class HugeTable(gridlib
.PyGridTableBase
): 
  10     This is all it takes to make a custom data table to plug into a 
  11     wxGrid.  There are many more methods that can be overridden, but 
  12     the ones shown below are the required ones.  This table simply 
  13     provides strings containing the row and column values. 
  16     def __init__(self
, log
): 
  17         gridlib
.PyGridTableBase
.__init
__(self
) 
  20         self
.odd
=gridlib
.GridCellAttr() 
  21         self
.odd
.SetBackgroundColour("sky blue") 
  22         self
.even
=gridlib
.GridCellAttr() 
  23         self
.even
.SetBackgroundColour("sea green") 
  25     def GetAttr(self
, row
, col
, kind
): 
  26         attr 
= [self
.even
, self
.odd
][row 
% 2] 
  30     def GetNumberRows(self
): 
  33     def GetNumberCols(self
): 
  36     def IsEmptyCell(self
, row
, col
): 
  39     def GetValue(self
, row
, col
): 
  40         return str( (row
, col
) ) 
  42     def SetValue(self
, row
, col
, value
): 
  43         self
.log
.write('SetValue(%d, %d, "%s") ignored.\n' % (row
, col
, value
)) 
  46 #--------------------------------------------------------------------------- 
  50 class HugeTableGrid(gridlib
.Grid
): 
  51     def __init__(self
, parent
, log
): 
  52         gridlib
.Grid
.__init
__(self
, parent
, -1) 
  54         table 
= HugeTable(log
) 
  56         # The second parameter means that the grid is to take ownership of the 
  57         # table and will destroy it when done.  Otherwise you would need to keep 
  58         # a reference to it and call it's Destroy method later. 
  59         self
.SetTable(table
, True) 
  61         self
.Bind(gridlib
.EVT_GRID_CELL_RIGHT_CLICK
, self
.OnRightDown
)   
  63     def OnRightDown(self
, event
): 
  65         print self
.GetSelectedRows() 
  68 #--------------------------------------------------------------------------- 
  70 class TestFrame(wx
.Frame
): 
  71     def __init__(self
, parent
, log
): 
  72         wx
.Frame
.__init
__(self
, parent
, -1, "Huge (virtual) Table Demo", size
=(640,480)) 
  73         grid 
= HugeTableGrid(self
, log
) 
  75         grid
.SetReadOnly(5,5, True) 
  77 #--------------------------------------------------------------------------- 
  79 if __name__ 
== '__main__': 
  81     app 
= wx
.PySimpleApp() 
  82     frame 
= TestFrame(None, sys
.stdout
) 
  87 #---------------------------------------------------------------------------