2 from wxPython
.wx
import *
5 #----------------------------------------------------------------------
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
)
13 self
.il
= wxImageList(16, 16)
14 self
.idx1
= self
.il
.Add(images
.getSmilesBitmap())
15 self
.SetImageList(self
.il
, wxIMAGE_LIST_SMALL
)
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)
25 self
.SetItemCount(1000000)
27 self
.attr1
= wxListItemAttr()
28 self
.attr1
.SetBackgroundColour("yellow")
30 self
.attr2
= wxListItemAttr()
31 self
.attr2
.SetBackgroundColour("light blue")
33 EVT_LIST_ITEM_SELECTED(self
, self
.GetId(), self
.OnItemSelected
)
34 EVT_LIST_ITEM_ACTIVATED(self
, self
.GetId(), self
.OnItemActivated
)
35 EVT_LIST_ITEM_DESELECTED(self
, self
.GetId(), self
.OnItemDeselected
)
38 def OnItemSelected(self
, event
):
39 self
.currentItem
= event
.m_itemIndex
40 self
.log
.WriteText('OnItemSelected: "%s", "%s", "%s", "%s"\n' %
42 self
.GetItemText(self
.currentItem
),
43 self
.getColumnText(self
.currentItem
, 1),
44 self
.getColumnText(self
.currentItem
, 2)))
46 def OnItemActivated(self
, event
):
47 self
.currentItem
= event
.m_itemIndex
48 self
.log
.WriteText("OnItemActivated: %s\nTopItem: %s\n" %
49 (self
.GetItemText(self
.currentItem
), self
.GetTopItem()))
51 def getColumnText(self
, index
, col
):
52 item
= self
.GetItem(index
, col
)
55 def OnItemDeselected(self
, evt
):
59 #---------------------------------------------------
60 # These methods are callbacks for implementing the
61 # "virtualness" of the list... Normally you would
62 # determine the text, attributes and/or image based
63 # on values from some external data source, but for
64 # this demo we'll just calcualte them
65 def OnGetItemText(self
, item
, col
):
66 return "Item %d, column %d" % (item
, col
)
68 def OnGetItemImage(self
, item
):
74 def OnGetItemAttr(self
, item
):
83 #----------------------------------------------------------------------
85 def runTest(frame
, nb
, log
):
86 win
= TestVirtualList(nb
, log
)
89 #----------------------------------------------------------------------
100 if __name__
== '__main__':
103 run
.main(['', os
.path
.basename(sys
.argv
[0])])