]>
Commit | Line | Data |
---|---|---|
c7e7022c | 1 | |
c7e7022c RD |
2 | from wxPython.wx import * |
3 | ||
4 | #---------------------------------------------------------------------- | |
5 | ||
6 | class TestVirtualList(wxListCtrl): | |
7 | def __init__(self, parent, log): | |
8 | wxListCtrl.__init__(self, parent, -1, | |
9 | style=wxLC_REPORT|wxLC_VIRTUAL|wxLC_HRULES|wxLC_VRULES) | |
10 | self.log = log | |
11 | ||
12 | self.InsertColumn(0, "First") | |
13 | self.InsertColumn(1, "Second") | |
14 | self.InsertColumn(2, "Third") | |
15 | self.SetColumnWidth(0, 175) | |
16 | self.SetColumnWidth(1, 175) | |
17 | self.SetColumnWidth(2, 175) | |
18 | ||
19 | self.SetItemCount(1000000) | |
20 | ||
00b6c4e3 RD |
21 | self.attr1 = wxListItemAttr() |
22 | self.attr1.SetBackgroundColour("yellow") | |
c7e7022c | 23 | |
00b6c4e3 RD |
24 | self.attr2 = wxListItemAttr() |
25 | self.attr2.SetBackgroundColour("light blue") | |
c7e7022c | 26 | |
462f07ca RD |
27 | EVT_LIST_ITEM_SELECTED(self, self.GetId(), self.OnItemSelected) |
28 | EVT_LIST_ITEM_ACTIVATED(self, self.GetId(), self.OnItemActivated) | |
198f875b | 29 | EVT_LIST_ITEM_DESELECTED(self, self.GetId(), self.OnItemDeselected) |
c7e7022c | 30 | |
462f07ca RD |
31 | |
32 | def OnItemSelected(self, event): | |
33 | self.currentItem = event.m_itemIndex | |
34 | self.log.WriteText('OnItemSelected: "%s", "%s", "%s", "%s"\n' % | |
35 | (self.currentItem, | |
36 | self.GetItemText(self.currentItem), | |
37 | self.getColumnText(self.currentItem, 1), | |
38 | self.getColumnText(self.currentItem, 2))) | |
39 | ||
40 | def OnItemActivated(self, event): | |
41 | self.currentItem = event.m_itemIndex | |
42 | self.log.WriteText("OnItemActivated: %s\n" % self.GetItemText(self.currentItem)) | |
43 | ||
44 | def getColumnText(self, index, col): | |
45 | item = self.GetItem(index, col) | |
46 | return item.GetText() | |
47 | ||
198f875b RD |
48 | def OnItemDeselected(self, evt): |
49 | print evt.m_itemIndex | |
50 | ||
51 | ||
462f07ca RD |
52 | #--------------------------------------------------- |
53 | # These methods are callbacks for implementing the | |
54 | # "virtualness" of the list... | |
c7e7022c RD |
55 | def OnGetItemText(self, item, col): |
56 | return "Item %d, column %d" % (item, col) | |
57 | ||
a1bfae9d | 58 | |
c7e7022c | 59 | def OnGetItemImage(self, item): |
a1bfae9d RD |
60 | return -1 # if used you should return the index in the ImageList |
61 | ||
c7e7022c RD |
62 | |
63 | def OnGetItemAttr(self, item): | |
00b6c4e3 RD |
64 | if item % 3 == 1: |
65 | return self.attr1 | |
66 | elif item % 3 == 2: | |
67 | return self.attr2 | |
68 | else: | |
69 | return None | |
c7e7022c RD |
70 | |
71 | ||
72 | #---------------------------------------------------------------------- | |
73 | ||
74 | def runTest(frame, nb, log): | |
75 | win = TestVirtualList(nb, log) | |
76 | return win | |
77 | ||
78 | #---------------------------------------------------------------------- | |
79 | ||
80 | ||
81 | ||
82 | ||
83 | ||
6f48b1b5 RD |
84 | overview = """\ |
85 | """ | |
86 | ||
c7e7022c RD |
87 | |
88 | ||
6f48b1b5 RD |
89 | if __name__ == '__main__': |
90 | import sys,os | |
91 | import run | |
92 | run.main(['', os.path.basename(sys.argv[0])]) | |
c7e7022c | 93 |