]> git.saurik.com Git - wxWidgets.git/blob - wxPython/samples/wxPIA_book/Chapter-14/grid_table_header.py
fix building/running of tex2rtf
[wxWidgets.git] / wxPython / samples / wxPIA_book / Chapter-14 / grid_table_header.py
1 import wx
2 import wx.grid
3
4 class 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 class TestFrame(wx.Frame):
51 def __init__(self):
52 wx.Frame.__init__(self, None, title="Grid Table",
53 size=(640,480))
54
55 grid = wx.grid.Grid(self)
56
57 table = TestTable()
58 grid.SetTable(table, True)
59
60
61 app = wx.PySimpleApp()
62 frame = TestFrame()
63 frame.Show()
64 app.MainLoop()