]>
Commit | Line | Data |
---|---|---|
8fa876ca RD |
1 | # 11/20/2003 - Jeff Grimmett (grimmtooth@softhome.net) |
2 | # | |
3 | # o Updated for wx namespace | |
4 | # | |
5 | # 11/29/2003 - Jeff Grimmett (grimmtooth@softhome.net) | |
6 | # | |
7 | # o wx.ListItem.GetText() returns a wxString pointer, not the text. | |
8 | # | |
9 | ||
10 | import wx | |
11 | import images | |
c7e7022c RD |
12 | |
13 | #---------------------------------------------------------------------- | |
14 | ||
8fa876ca | 15 | class TestVirtualList(wx.ListCtrl): |
c7e7022c | 16 | def __init__(self, parent, log): |
8fa876ca RD |
17 | wx.ListCtrl.__init__( |
18 | self, parent, -1, | |
19 | style=wx.LC_REPORT|wx.LC_VIRTUAL|wx.LC_HRULES|wx.LC_VRULES | |
20 | ) | |
21 | ||
c7e7022c RD |
22 | self.log = log |
23 | ||
8fa876ca | 24 | self.il = wx.ImageList(16, 16) |
d25a6098 | 25 | self.idx1 = self.il.Add(images.getSmilesBitmap()) |
8fa876ca | 26 | self.SetImageList(self.il, wx.IMAGE_LIST_SMALL) |
d25a6098 RD |
27 | |
28 | ||
c7e7022c RD |
29 | self.InsertColumn(0, "First") |
30 | self.InsertColumn(1, "Second") | |
31 | self.InsertColumn(2, "Third") | |
32 | self.SetColumnWidth(0, 175) | |
33 | self.SetColumnWidth(1, 175) | |
34 | self.SetColumnWidth(2, 175) | |
35 | ||
36 | self.SetItemCount(1000000) | |
37 | ||
8fa876ca | 38 | self.attr1 = wx.ListItemAttr() |
00b6c4e3 | 39 | self.attr1.SetBackgroundColour("yellow") |
c7e7022c | 40 | |
8fa876ca | 41 | self.attr2 = wx.ListItemAttr() |
00b6c4e3 | 42 | self.attr2.SetBackgroundColour("light blue") |
c7e7022c | 43 | |
8fa876ca RD |
44 | self.Bind(wx.EVT_LIST_ITEM_SELECTED, self.OnItemSelected) |
45 | self.Bind(wx.EVT_LIST_ITEM_ACTIVATED, self.OnItemActivated) | |
46 | self.Bind(wx.EVT_LIST_ITEM_DESELECTED, self.OnItemDeselected) | |
c7e7022c | 47 | |
462f07ca RD |
48 | |
49 | def OnItemSelected(self, event): | |
50 | self.currentItem = event.m_itemIndex | |
51 | self.log.WriteText('OnItemSelected: "%s", "%s", "%s", "%s"\n' % | |
52 | (self.currentItem, | |
53 | self.GetItemText(self.currentItem), | |
54 | self.getColumnText(self.currentItem, 1), | |
55 | self.getColumnText(self.currentItem, 2))) | |
56 | ||
57 | def OnItemActivated(self, event): | |
58 | self.currentItem = event.m_itemIndex | |
1e4a197e RD |
59 | self.log.WriteText("OnItemActivated: %s\nTopItem: %s\n" % |
60 | (self.GetItemText(self.currentItem), self.GetTopItem())) | |
462f07ca RD |
61 | |
62 | def getColumnText(self, index, col): | |
63 | item = self.GetItem(index, col) | |
64 | return item.GetText() | |
65 | ||
198f875b | 66 | def OnItemDeselected(self, evt): |
1fded56b | 67 | self.log.WriteText("OnItemDeselected: %s" % evt.m_itemIndex) |
198f875b RD |
68 | |
69 | ||
462f07ca RD |
70 | #--------------------------------------------------- |
71 | # These methods are callbacks for implementing the | |
d25a6098 RD |
72 | # "virtualness" of the list... Normally you would |
73 | # determine the text, attributes and/or image based | |
74 | # on values from some external data source, but for | |
8b9a4190 | 75 | # this demo we'll just calculate them |
c7e7022c RD |
76 | def OnGetItemText(self, item, col): |
77 | return "Item %d, column %d" % (item, col) | |
78 | ||
79 | def OnGetItemImage(self, item): | |
d25a6098 RD |
80 | if item % 3 == 0: |
81 | return self.idx1 | |
82 | else: | |
83 | return -1 | |
c7e7022c RD |
84 | |
85 | def OnGetItemAttr(self, item): | |
00b6c4e3 RD |
86 | if item % 3 == 1: |
87 | return self.attr1 | |
88 | elif item % 3 == 2: | |
89 | return self.attr2 | |
90 | else: | |
91 | return None | |
c7e7022c RD |
92 | |
93 | ||
94 | #---------------------------------------------------------------------- | |
95 | ||
96 | def runTest(frame, nb, log): | |
97 | win = TestVirtualList(nb, log) | |
98 | return win | |
99 | ||
100 | #---------------------------------------------------------------------- | |
101 | ||
102 | ||
6f48b1b5 | 103 | overview = """\ |
8fa876ca RD |
104 | This example demonstrates the ListCtrl's Virtual List features. A Virtual list |
105 | can contain any number of cells, but data is not loaded into the control itself. | |
106 | It is loaded on demand via virtual methods <code>OnGetItemText(), OnGetItemImage()</code>, | |
107 | and <code>OnGetItemAttr()</code>. This greatly reduces the amount of memory required | |
108 | without limiting what can be done with the list control itself. | |
6f48b1b5 RD |
109 | """ |
110 | ||
c7e7022c RD |
111 | |
112 | ||
6f48b1b5 RD |
113 | if __name__ == '__main__': |
114 | import sys,os | |
115 | import run | |
116 | run.main(['', os.path.basename(sys.argv[0])]) | |
c7e7022c | 117 |