]> git.saurik.com Git - wxWidgets.git/blame - wxPython/demo/ListCtrl_virtual.py
Script updates
[wxWidgets.git] / wxPython / demo / ListCtrl_virtual.py
CommitLineData
8fa876ca
RD
1
2import wx
3import images
c7e7022c
RD
4
5#----------------------------------------------------------------------
6
8fa876ca 7class TestVirtualList(wx.ListCtrl):
c7e7022c 8 def __init__(self, parent, log):
8fa876ca
RD
9 wx.ListCtrl.__init__(
10 self, parent, -1,
11 style=wx.LC_REPORT|wx.LC_VIRTUAL|wx.LC_HRULES|wx.LC_VRULES
12 )
13
c7e7022c
RD
14 self.log = log
15
8fa876ca 16 self.il = wx.ImageList(16, 16)
d25a6098 17 self.idx1 = self.il.Add(images.getSmilesBitmap())
8fa876ca 18 self.SetImageList(self.il, wx.IMAGE_LIST_SMALL)
d25a6098
RD
19
20
c7e7022c
RD
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)
27
28 self.SetItemCount(1000000)
29
8fa876ca 30 self.attr1 = wx.ListItemAttr()
00b6c4e3 31 self.attr1.SetBackgroundColour("yellow")
c7e7022c 32
8fa876ca 33 self.attr2 = wx.ListItemAttr()
00b6c4e3 34 self.attr2.SetBackgroundColour("light blue")
c7e7022c 35
8fa876ca
RD
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)
c7e7022c 39
462f07ca
RD
40
41 def OnItemSelected(self, event):
42 self.currentItem = event.m_itemIndex
43 self.log.WriteText('OnItemSelected: "%s", "%s", "%s", "%s"\n' %
44 (self.currentItem,
45 self.GetItemText(self.currentItem),
46 self.getColumnText(self.currentItem, 1),
47 self.getColumnText(self.currentItem, 2)))
48
49 def OnItemActivated(self, event):
50 self.currentItem = event.m_itemIndex
1e4a197e
RD
51 self.log.WriteText("OnItemActivated: %s\nTopItem: %s\n" %
52 (self.GetItemText(self.currentItem), self.GetTopItem()))
462f07ca
RD
53
54 def getColumnText(self, index, col):
55 item = self.GetItem(index, col)
56 return item.GetText()
57
198f875b 58 def OnItemDeselected(self, evt):
1fded56b 59 self.log.WriteText("OnItemDeselected: %s" % evt.m_itemIndex)
198f875b
RD
60
61
462f07ca
RD
62 #---------------------------------------------------
63 # These methods are callbacks for implementing the
d25a6098
RD
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
8b9a4190 67 # this demo we'll just calculate them
c7e7022c
RD
68 def OnGetItemText(self, item, col):
69 return "Item %d, column %d" % (item, col)
70
71 def OnGetItemImage(self, item):
d25a6098
RD
72 if item % 3 == 0:
73 return self.idx1
74 else:
75 return -1
c7e7022c
RD
76
77 def OnGetItemAttr(self, item):
00b6c4e3
RD
78 if item % 3 == 1:
79 return self.attr1
80 elif item % 3 == 2:
81 return self.attr2
82 else:
83 return None
c7e7022c
RD
84
85
86#----------------------------------------------------------------------
87
88def runTest(frame, nb, log):
89 win = TestVirtualList(nb, log)
90 return win
91
92#----------------------------------------------------------------------
93
94
6f48b1b5 95overview = """\
8fa876ca
RD
96This example demonstrates the ListCtrl's Virtual List features. A Virtual list
97can contain any number of cells, but data is not loaded into the control itself.
98It is loaded on demand via virtual methods <code>OnGetItemText(), OnGetItemImage()</code>,
99and <code>OnGetItemAttr()</code>. This greatly reduces the amount of memory required
100without limiting what can be done with the list control itself.
6f48b1b5
RD
101"""
102
c7e7022c
RD
103
104
6f48b1b5
RD
105if __name__ == '__main__':
106 import sys,os
107 import run
108 run.main(['', os.path.basename(sys.argv[0])])
c7e7022c 109