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