]> git.saurik.com Git - wxWidgets.git/blame - wxPython/samples/wxPIA_book/Chapter-14/grid_table.py
fix building/running of tex2rtf
[wxWidgets.git] / wxPython / samples / wxPIA_book / Chapter-14 / grid_table.py
CommitLineData
be05b434
RD
1import wx
2import wx.grid
3
4class TestTable(wx.grid.PyGridTableBase):
5 def __init__(self):
6 wx.grid.PyGridTableBase.__init__(self)
7 self.data = { (1,1) : "Here",
8 (2,2) : "is",
9 (3,3) : "some",
10 (4,4) : "data",
11 }
12
13 self.odd=wx.grid.GridCellAttr()
14 self.odd.SetBackgroundColour("sky blue")
15 self.odd.SetFont(wx.Font(10, wx.SWISS, wx.NORMAL, wx.BOLD))
16
17 self.even=wx.grid.GridCellAttr()
18 self.even.SetBackgroundColour("sea green")
19 self.even.SetFont(wx.Font(10, wx.SWISS, wx.NORMAL, wx.BOLD))
20
21
22 # these five are the required methods
23 def GetNumberRows(self):
24 return 50
25
26 def GetNumberCols(self):
27 return 50
28
29 def IsEmptyCell(self, row, col):
30 return self.data.get((row, col)) is not None
31
32 def GetValue(self, row, col):
33 value = self.data.get((row, col))
34 if value is not None:
35 return value
36 else:
37 return ''
38
39 def SetValue(self, row, col, value):
40 self.data[(row,col)] = value
41
42
43 # the table can also provide the attribute for each cell
44 def GetAttr(self, row, col, kind):
45 attr = [self.even, self.odd][row % 2]
46 attr.IncRef()
47 return attr
48
49
50
51class TestFrame(wx.Frame):
52 def __init__(self):
53 wx.Frame.__init__(self, None, title="Grid Table",
54 size=(640,480))
55
56 grid = wx.grid.Grid(self)
57
58 table = TestTable()
59 grid.SetTable(table, True)
60
61
62app = wx.PySimpleApp()
63frame = TestFrame()
64frame.Show()
65app.MainLoop()