]> git.saurik.com Git - wxWidgets.git/blame - wxPython/demo/wxListCtrl_virtual.py
fixed wrong #ifdefs
[wxWidgets.git] / wxPython / demo / wxListCtrl_virtual.py
CommitLineData
c7e7022c 1
c7e7022c 2from wxPython.wx import *
d25a6098 3import images
c7e7022c
RD
4
5#----------------------------------------------------------------------
6
7class TestVirtualList(wxListCtrl):
8 def __init__(self, parent, log):
9 wxListCtrl.__init__(self, parent, -1,
10 style=wxLC_REPORT|wxLC_VIRTUAL|wxLC_HRULES|wxLC_VRULES)
11 self.log = log
12
d25a6098
RD
13 self.il = wxImageList(16, 16)
14 self.idx1 = self.il.Add(images.getSmilesBitmap())
15 self.SetImageList(self.il, wxIMAGE_LIST_SMALL)
16
17
c7e7022c
RD
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)
24
25 self.SetItemCount(1000000)
26
00b6c4e3
RD
27 self.attr1 = wxListItemAttr()
28 self.attr1.SetBackgroundColour("yellow")
c7e7022c 29
00b6c4e3
RD
30 self.attr2 = wxListItemAttr()
31 self.attr2.SetBackgroundColour("light blue")
c7e7022c 32
462f07ca
RD
33 EVT_LIST_ITEM_SELECTED(self, self.GetId(), self.OnItemSelected)
34 EVT_LIST_ITEM_ACTIVATED(self, self.GetId(), self.OnItemActivated)
198f875b 35 EVT_LIST_ITEM_DESELECTED(self, self.GetId(), self.OnItemDeselected)
c7e7022c 36
462f07ca
RD
37
38 def OnItemSelected(self, event):
39 self.currentItem = event.m_itemIndex
40 self.log.WriteText('OnItemSelected: "%s", "%s", "%s", "%s"\n' %
41 (self.currentItem,
42 self.GetItemText(self.currentItem),
43 self.getColumnText(self.currentItem, 1),
44 self.getColumnText(self.currentItem, 2)))
45
46 def OnItemActivated(self, event):
47 self.currentItem = event.m_itemIndex
1e4a197e
RD
48 self.log.WriteText("OnItemActivated: %s\nTopItem: %s\n" %
49 (self.GetItemText(self.currentItem), self.GetTopItem()))
462f07ca
RD
50
51 def getColumnText(self, index, col):
52 item = self.GetItem(index, col)
53 return item.GetText()
54
198f875b 55 def OnItemDeselected(self, evt):
1fded56b 56 self.log.WriteText("OnItemDeselected: %s" % evt.m_itemIndex)
198f875b
RD
57
58
462f07ca
RD
59 #---------------------------------------------------
60 # These methods are callbacks for implementing the
d25a6098
RD
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
8b9a4190 64 # this demo we'll just calculate them
c7e7022c
RD
65 def OnGetItemText(self, item, col):
66 return "Item %d, column %d" % (item, col)
67
68 def OnGetItemImage(self, item):
d25a6098
RD
69 if item % 3 == 0:
70 return self.idx1
71 else:
72 return -1
c7e7022c
RD
73
74 def OnGetItemAttr(self, item):
00b6c4e3
RD
75 if item % 3 == 1:
76 return self.attr1
77 elif item % 3 == 2:
78 return self.attr2
79 else:
80 return None
c7e7022c
RD
81
82
83#----------------------------------------------------------------------
84
85def runTest(frame, nb, log):
86 win = TestVirtualList(nb, log)
87 return win
88
89#----------------------------------------------------------------------
90
91
92
93
94
6f48b1b5
RD
95overview = """\
96"""
97
c7e7022c
RD
98
99
6f48b1b5
RD
100if __name__ == '__main__':
101 import sys,os
102 import run
103 run.main(['', os.path.basename(sys.argv[0])])
c7e7022c 104