]> git.saurik.com Git - wxWidgets.git/blob - wxPython/demo/wxListCtrl_virtual.py
reversed order of configurations to make the IDE happy about the default one
[wxWidgets.git] / wxPython / demo / wxListCtrl_virtual.py
1
2 from wxPython.wx import *
3 import images
4
5 #----------------------------------------------------------------------
6
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)
11 self.log = log
12
13 self.il = wxImageList(16, 16)
14 self.idx1 = self.il.Add(images.getSmilesBitmap())
15 self.SetImageList(self.il, wxIMAGE_LIST_SMALL)
16
17
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
27 self.attr1 = wxListItemAttr()
28 self.attr1.SetBackgroundColour("yellow")
29
30 self.attr2 = wxListItemAttr()
31 self.attr2.SetBackgroundColour("light blue")
32
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)
36
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
48 self.log.WriteText("OnItemActivated: %s\nTopItem: %s\n" %
49 (self.GetItemText(self.currentItem), self.GetTopItem()))
50
51 def getColumnText(self, index, col):
52 item = self.GetItem(index, col)
53 return item.GetText()
54
55 def OnItemDeselected(self, evt):
56 self.log.WriteText("OnItemDeselected: %s" % evt.m_itemIndex)
57
58
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)
67
68 def OnGetItemImage(self, item):
69 if item % 3 == 0:
70 return self.idx1
71 else:
72 return -1
73
74 def OnGetItemAttr(self, item):
75 if item % 3 == 1:
76 return self.attr1
77 elif item % 3 == 2:
78 return self.attr2
79 else:
80 return None
81
82
83 #----------------------------------------------------------------------
84
85 def runTest(frame, nb, log):
86 win = TestVirtualList(nb, log)
87 return win
88
89 #----------------------------------------------------------------------
90
91
92
93
94
95 overview = """\
96 """
97
98
99
100 if __name__ == '__main__':
101 import sys,os
102 import run
103 run.main(['', os.path.basename(sys.argv[0])])
104