]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/demo/ListCtrl_virtual.py
5 #----------------------------------------------------------------------
7 class TestVirtualList(wx
.ListCtrl
):
8 def __init__(self
, parent
, log
):
11 style
=wx
.LC_REPORT|wx
.LC_VIRTUAL|wx
.LC_HRULES|wx
.LC_VRULES
16 self
.il
= wx
.ImageList(16, 16)
17 self
.idx1
= self
.il
.Add(images
.getSmilesBitmap())
18 self
.SetImageList(self
.il
, wx
.IMAGE_LIST_SMALL
)
21 self
.InsertColumn(0, "First")
22 self
.InsertColumn(1, "Second")
23 self
.InsertColumn(2, "Third")
24 self
.SetColumnWidth(0, 175)
25 self
.SetColumnWidth(1, 175)
26 self
.SetColumnWidth(2, 175)
28 self
.SetItemCount(1000000)
30 self
.attr1
= wx
.ListItemAttr()
31 self
.attr1
.SetBackgroundColour("yellow")
33 self
.attr2
= wx
.ListItemAttr()
34 self
.attr2
.SetBackgroundColour("light blue")
36 self
.Bind(wx
.EVT_LIST_ITEM_SELECTED
, self
.OnItemSelected
)
37 self
.Bind(wx
.EVT_LIST_ITEM_ACTIVATED
, self
.OnItemActivated
)
38 self
.Bind(wx
.EVT_LIST_ITEM_DESELECTED
, self
.OnItemDeselected
)
41 def OnItemSelected(self
, event
):
42 self
.currentItem
= event
.m_itemIndex
43 self
.log
.WriteText('OnItemSelected: "%s", "%s", "%s", "%s"\n' %
45 self
.GetItemText(self
.currentItem
),
46 self
.getColumnText(self
.currentItem
, 1),
47 self
.getColumnText(self
.currentItem
, 2)))
49 def OnItemActivated(self
, event
):
50 self
.currentItem
= event
.m_itemIndex
51 self
.log
.WriteText("OnItemActivated: %s\nTopItem: %s\n" %
52 (self
.GetItemText(self
.currentItem
), self
.GetTopItem()))
54 def getColumnText(self
, index
, col
):
55 item
= self
.GetItem(index
, col
)
58 def OnItemDeselected(self
, evt
):
59 self
.log
.WriteText("OnItemDeselected: %s" % evt
.m_itemIndex
)
62 #---------------------------------------------------
63 # These methods are callbacks for implementing the
64 # "virtualness" of the list... Normally you would
65 # determine the text, attributes and/or image based
66 # on values from some external data source, but for
67 # this demo we'll just calculate them
68 def OnGetItemText(self
, item
, col
):
69 return "Item %d, column %d" % (item
, col
)
71 def OnGetItemImage(self
, item
):
77 def OnGetItemAttr(self
, item
):
86 #----------------------------------------------------------------------
88 def runTest(frame
, nb
, log
):
89 win
= TestVirtualList(nb
, log
)
92 #----------------------------------------------------------------------
96 This example demonstrates the ListCtrl's Virtual List features. A Virtual list
97 can contain any number of cells, but data is not loaded into the control itself.
98 It is loaded on demand via virtual methods <code>OnGetItemText(), OnGetItemImage()</code>,
99 and <code>OnGetItemAttr()</code>. This greatly reduces the amount of memory required
100 without limiting what can be done with the list control itself.
105 if __name__
== '__main__':
108 run
.main(['', os
.path
.basename(sys
.argv
[0])])