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