]>
Commit | Line | Data |
---|---|---|
8fa876ca RD |
1 | |
2 | import wx | |
3 | import wx.grid as gridlib | |
f6bcfd97 BP |
4 | |
5 | #--------------------------------------------------------------------------- | |
6 | ||
8fa876ca | 7 | class HugeTable(gridlib.PyGridTableBase): |
f6bcfd97 BP |
8 | |
9 | """ | |
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. | |
14 | """ | |
15 | ||
16 | def __init__(self, log): | |
8fa876ca | 17 | gridlib.PyGridTableBase.__init__(self) |
f6bcfd97 BP |
18 | self.log = log |
19 | ||
372bde9b | 20 | self.odd=gridlib.GridCellAttr() |
5499dd89 | 21 | self.odd.SetBackgroundColour("sky blue") |
372bde9b | 22 | self.even=gridlib.GridCellAttr() |
5499dd89 RD |
23 | self.even.SetBackgroundColour("sea green") |
24 | ||
fbd5dd1d | 25 | def GetAttr(self, row, col, kind): |
5499dd89 RD |
26 | attr = [self.even, self.odd][row % 2] |
27 | attr.IncRef() | |
28 | return attr | |
29 | ||
f6bcfd97 BP |
30 | def GetNumberRows(self): |
31 | return 10000 | |
32 | ||
33 | def GetNumberCols(self): | |
34 | return 10000 | |
35 | ||
36 | def IsEmptyCell(self, row, col): | |
1e4a197e | 37 | return False |
f6bcfd97 BP |
38 | |
39 | def GetValue(self, row, col): | |
40 | return str( (row, col) ) | |
41 | ||
42 | def SetValue(self, row, col, value): | |
43 | self.log.write('SetValue(%d, %d, "%s") ignored.\n' % (row, col, value)) | |
44 | ||
45 | ||
46 | #--------------------------------------------------------------------------- | |
47 | ||
48 | ||
49 | ||
8fa876ca | 50 | class HugeTableGrid(gridlib.Grid): |
f6bcfd97 | 51 | def __init__(self, parent, log): |
8fa876ca | 52 | gridlib.Grid.__init__(self, parent, -1) |
f6bcfd97 BP |
53 | |
54 | table = HugeTable(log) | |
55 | ||
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. | |
1e4a197e RD |
59 | self.SetTable(table, True) |
60 | ||
8fa876ca | 61 | self.Bind(gridlib.EVT_GRID_CELL_RIGHT_CLICK, self.OnRightDown) |
1e4a197e | 62 | |
8fa876ca | 63 | def OnRightDown(self, event): |
1e4a197e | 64 | print "hello" |
8fa876ca | 65 | print self.GetSelectedRows() |
f6bcfd97 BP |
66 | |
67 | ||
68 | #--------------------------------------------------------------------------- | |
69 | ||
8fa876ca | 70 | class TestFrame(wx.Frame): |
f6bcfd97 | 71 | def __init__(self, parent, log): |
8fa876ca | 72 | wx.Frame.__init__(self, parent, -1, "Huge (virtual) Table Demo", size=(640,480)) |
f6bcfd97 BP |
73 | grid = HugeTableGrid(self, log) |
74 | ||
1e4a197e | 75 | grid.SetReadOnly(5,5, True) |
f6bcfd97 BP |
76 | |
77 | #--------------------------------------------------------------------------- | |
78 | ||
79 | if __name__ == '__main__': | |
80 | import sys | |
8fa876ca | 81 | app = wx.PySimpleApp() |
f6bcfd97 | 82 | frame = TestFrame(None, sys.stdout) |
1e4a197e | 83 | frame.Show(True) |
f6bcfd97 BP |
84 | app.MainLoop() |
85 | ||
86 | ||
87 | #--------------------------------------------------------------------------- |