]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/demo/ListCtrl_virtual.py
1 # 11/20/2003 - Jeff Grimmett (grimmtooth@softhome.net)
3 # o Updated for wx namespace
5 # 11/29/2003 - Jeff Grimmett (grimmtooth@softhome.net)
7 # o wx.ListItem.GetText() returns a wxString pointer, not the text.
13 #----------------------------------------------------------------------
15 class TestVirtualList(wx
.ListCtrl
):
16 def __init__(self
, parent
, log
):
19 style
=wx
.LC_REPORT|wx
.LC_VIRTUAL|wx
.LC_HRULES|wx
.LC_VRULES
24 self
.il
= wx
.ImageList(16, 16)
25 self
.idx1
= self
.il
.Add(images
.getSmilesBitmap())
26 self
.SetImageList(self
.il
, wx
.IMAGE_LIST_SMALL
)
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)
36 self
.SetItemCount(1000000)
38 self
.attr1
= wx
.ListItemAttr()
39 self
.attr1
.SetBackgroundColour("yellow")
41 self
.attr2
= wx
.ListItemAttr()
42 self
.attr2
.SetBackgroundColour("light blue")
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
)
49 def OnItemSelected(self
, event
):
50 self
.currentItem
= event
.m_itemIndex
51 self
.log
.WriteText('OnItemSelected: "%s", "%s", "%s", "%s"\n' %
53 self
.GetItemText(self
.currentItem
),
54 self
.getColumnText(self
.currentItem
, 1),
55 self
.getColumnText(self
.currentItem
, 2)))
57 def OnItemActivated(self
, event
):
58 self
.currentItem
= event
.m_itemIndex
59 self
.log
.WriteText("OnItemActivated: %s\nTopItem: %s\n" %
60 (self
.GetItemText(self
.currentItem
), self
.GetTopItem()))
62 def getColumnText(self
, index
, col
):
63 item
= self
.GetItem(index
, col
)
66 def OnItemDeselected(self
, evt
):
67 self
.log
.WriteText("OnItemDeselected: %s" % evt
.m_itemIndex
)
70 #---------------------------------------------------
71 # These methods are callbacks for implementing the
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
75 # this demo we'll just calculate them
76 def OnGetItemText(self
, item
, col
):
77 return "Item %d, column %d" % (item
, col
)
79 def OnGetItemImage(self
, item
):
85 def OnGetItemAttr(self
, item
):
94 #----------------------------------------------------------------------
96 def runTest(frame
, nb
, log
):
97 win
= TestVirtualList(nb
, log
)
100 #----------------------------------------------------------------------
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.
113 if __name__
== '__main__':
116 run
.main(['', os
.path
.basename(sys
.argv
[0])])