]>
Commit | Line | Data |
---|---|---|
1 | ||
2 | import wx | |
3 | import wx.grid as gridlib | |
4 | ||
5 | #--------------------------------------------------------------------------- | |
6 | ||
7 | class HugeTable(gridlib.PyGridTableBase): | |
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): | |
17 | gridlib.PyGridTableBase.__init__(self) | |
18 | self.log = log | |
19 | ||
20 | self.odd=gridlib.GridCellAttr() | |
21 | self.odd.SetBackgroundColour("sky blue") | |
22 | self.even=gridlib.GridCellAttr() | |
23 | self.even.SetBackgroundColour("sea green") | |
24 | ||
25 | def GetAttr(self, row, col, kind): | |
26 | attr = [self.even, self.odd][row % 2] | |
27 | attr.IncRef() | |
28 | return attr | |
29 | ||
30 | def GetNumberRows(self): | |
31 | return 10000 | |
32 | ||
33 | def GetNumberCols(self): | |
34 | return 10000 | |
35 | ||
36 | def IsEmptyCell(self, row, col): | |
37 | return False | |
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 | ||
50 | class HugeTableGrid(gridlib.Grid): | |
51 | def __init__(self, parent, log): | |
52 | gridlib.Grid.__init__(self, parent, -1) | |
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. | |
59 | self.SetTable(table, True) | |
60 | ||
61 | self.Bind(gridlib.EVT_GRID_CELL_RIGHT_CLICK, self.OnRightDown) | |
62 | ||
63 | def OnRightDown(self, event): | |
64 | print "hello" | |
65 | print self.GetSelectedRows() | |
66 | ||
67 | ||
68 | #--------------------------------------------------------------------------- | |
69 | ||
70 | class TestFrame(wx.Frame): | |
71 | def __init__(self, parent, log): | |
72 | wx.Frame.__init__(self, parent, -1, "Huge (virtual) Table Demo", size=(640,480)) | |
73 | grid = HugeTableGrid(self, log) | |
74 | ||
75 | grid.SetReadOnly(5,5, True) | |
76 | ||
77 | #--------------------------------------------------------------------------- | |
78 | ||
79 | if __name__ == '__main__': | |
80 | import sys | |
81 | app = wx.PySimpleApp() | |
82 | frame = TestFrame(None, sys.stdout) | |
83 | frame.Show(True) | |
84 | app.MainLoop() | |
85 | ||
86 | ||
87 | #--------------------------------------------------------------------------- |