]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/demo/GridHugeTable.py
1 from wxPython
.wx
import *
2 from wxPython
.grid
import *
4 #---------------------------------------------------------------------------
6 class HugeTable(wxPyGridTableBase
):
9 This is all it takes to make a custom data table to plug into a
10 wxGrid. There are many more methods that can be overridden, but
11 the ones shown below are the required ones. This table simply
12 provides strings containing the row and column values.
15 def __init__(self
, log
):
16 wxPyGridTableBase
.__init
__(self
)
19 self
.odd
=wxGridCellAttr()
20 self
.odd
.SetBackgroundColour("sky blue")
21 self
.even
=wxGridCellAttr()
22 self
.even
.SetBackgroundColour("sea green")
24 def GetAttr(self
, row
, col
, kind
):
25 attr
= [self
.even
, self
.odd
][row
% 2]
29 def GetNumberRows(self
):
32 def GetNumberCols(self
):
35 def IsEmptyCell(self
, row
, col
):
38 def GetValue(self
, row
, col
):
39 return str( (row
, col
) )
41 def SetValue(self
, row
, col
, value
):
42 self
.log
.write('SetValue(%d, %d, "%s") ignored.\n' % (row
, col
, value
))
45 #---------------------------------------------------------------------------
49 class HugeTableGrid(wxGrid
):
50 def __init__(self
, parent
, log
):
51 wxGrid
.__init
__(self
, parent
, -1)
53 table
= HugeTable(log
)
55 # The second parameter means that the grid is to take ownership of the
56 # table and will destroy it when done. Otherwise you would need to keep
57 # a reference to it and call it's Destroy method later.
58 self
.SetTable(table
, True)
60 EVT_GRID_CELL_RIGHT_CLICK(self
, self
.OnRightDown
) #added
62 def OnRightDown(self
, event
): #added
64 print self
.GetSelectedRows() #added
70 #---------------------------------------------------------------------------
72 class TestFrame(wxFrame
):
73 def __init__(self
, parent
, log
):
74 wxFrame
.__init
__(self
, parent
, -1, "Huge (virtual) Table Demo", size
=(640,480))
75 grid
= HugeTableGrid(self
, log
)
77 grid
.SetReadOnly(5,5, True)
79 #---------------------------------------------------------------------------
81 if __name__
== '__main__':
84 frame
= TestFrame(None, sys
.stdout
)
89 #---------------------------------------------------------------------------