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