1 # 11/6/2003 - Jeff Grimmett (grimmtooth@softhome.net)
3 # o Updated for wx namespace
7 import wx
.grid
as gridlib
9 #---------------------------------------------------------------------------
11 class HugeTable(gridlib
.PyGridTableBase
):
14 This is all it takes to make a custom data table to plug into a
15 wxGrid. There are many more methods that can be overridden, but
16 the ones shown below are the required ones. This table simply
17 provides strings containing the row and column values.
20 def __init__(self
, log
):
21 gridlib
.PyGridTableBase
.__init
__(self
)
24 self
.odd
=wxGridCellAttr()
25 self
.odd
.SetBackgroundColour("sky blue")
26 self
.even
=wxGridCellAttr()
27 self
.even
.SetBackgroundColour("sea green")
29 def GetAttr(self
, row
, col
, kind
):
30 attr
= [self
.even
, self
.odd
][row
% 2]
34 def GetNumberRows(self
):
37 def GetNumberCols(self
):
40 def IsEmptyCell(self
, row
, col
):
43 def GetValue(self
, row
, col
):
44 return str( (row
, col
) )
46 def SetValue(self
, row
, col
, value
):
47 self
.log
.write('SetValue(%d, %d, "%s") ignored.\n' % (row
, col
, value
))
50 #---------------------------------------------------------------------------
54 class HugeTableGrid(gridlib
.Grid
):
55 def __init__(self
, parent
, log
):
56 gridlib
.Grid
.__init
__(self
, parent
, -1)
58 table
= HugeTable(log
)
60 # The second parameter means that the grid is to take ownership of the
61 # table and will destroy it when done. Otherwise you would need to keep
62 # a reference to it and call it's Destroy method later.
63 self
.SetTable(table
, True)
65 self
.Bind(gridlib
.EVT_GRID_CELL_RIGHT_CLICK
, self
.OnRightDown
)
67 def OnRightDown(self
, event
):
69 print self
.GetSelectedRows()
72 #---------------------------------------------------------------------------
74 class TestFrame(wx
.Frame
):
75 def __init__(self
, parent
, log
):
76 wx
.Frame
.__init
__(self
, parent
, -1, "Huge (virtual) Table Demo", size
=(640,480))
77 grid
= HugeTableGrid(self
, log
)
79 grid
.SetReadOnly(5,5, True)
81 #---------------------------------------------------------------------------
83 if __name__
== '__main__':
85 app
= wx
.PySimpleApp()
86 frame
= TestFrame(None, sys
.stdout
)
91 #---------------------------------------------------------------------------