]>
Commit | Line | Data |
---|---|---|
cf694132 RD |
1 | #---------------------------------------------------------------------------- |
2 | # Name: ListCtrl.py | |
3 | # Purpose: Testing lots of stuff, controls, window types, etc. | |
4 | # | |
5 | # Author: Robin Dunn & Gary Dumer | |
6 | # | |
7 | # Created: | |
8 | # RCS-ID: $Id$ | |
9 | # Copyright: (c) 1998 by Total Control Software | |
10 | # Licence: wxWindows license | |
11 | #---------------------------------------------------------------------------- | |
12 | ||
13 | from wxPython.wx import * | |
6d19860f | 14 | from wxPython.lib.mixins.listctrl import wxColumnSorterMixin |
cf694132 RD |
15 | |
16 | #--------------------------------------------------------------------------- | |
17 | ||
dcd38683 RD |
18 | musicdata = { |
19 | 1 : ("Bad English", "The Price Of Love", "Rock"), | |
20 | 2 : ("DNA featuring Suzanne Vega", "Tom's Diner", "Rock"), | |
21 | 3 : ("George Michael", "Praying For Time", "Rock"), | |
22 | 4 : ("Gloria Estefan", "Here We Are", "Rock"), | |
23 | 5 : ("Linda Ronstadt", "Don't Know Much", "Rock"), | |
24 | 6 : ("Michael Bolton", "How Am I Supposed To Live Without You", "Blues"), | |
cd096152 RD |
25 | 7 : ("Paul Young", "Oh Girl", "Rock"), |
26 | 8 : ("Paula Abdul", "Opposites Attract", "Rock"), | |
27 | 9 : ("Richard Marx", "Should've Known Better", "Rock"), | |
28 | 10: ("Rod Stewart", "Forever Young", "Rock"), | |
29 | 11: ("Roxette", "Dangerous", "Rock"), | |
30 | 12: ("Sheena Easton", "The Lover In Me", "Rock"), | |
31 | 13: ("Sinead O'Connor", "Nothing Compares 2 U", "Rock"), | |
32 | 14: ("Stevie B.", "Because I Love You", "Rock"), | |
33 | 15: ("Taylor Dayne", "Love Will Lead You Back", "Rock"), | |
34 | 16: ("The Bangles", "Eternal Flame", "Rock"), | |
35 | 17: ("Wilson Phillips", "Release Me", "Rock"), | |
36 | 18: ("Billy Joel", "Blonde Over Blue", "Rock"), | |
37 | 19: ("Billy Joel", "Famous Last Words", "Rock"), | |
38 | 20: ("Billy Joel", "Lullabye (Goodnight, My Angel)", "Rock"), | |
39 | 21: ("Billy Joel", "The River Of Dreams", "Rock"), | |
40 | 22: ("Billy Joel", "Two Thousand Years", "Rock"), | |
41 | 23: ("Janet Jackson", "Alright", "Rock"), | |
42 | 24: ("Janet Jackson", "Black Cat", "Rock"), | |
43 | 25: ("Janet Jackson", "Come Back To Me", "Rock"), | |
44 | 26: ("Janet Jackson", "Escapade", "Rock"), | |
45 | 27: ("Janet Jackson", "Love Will Never Do (Without You)", "Rock"), | |
46 | 28: ("Janet Jackson", "Miss You Much", "Rock"), | |
47 | 29: ("Janet Jackson", "Rhythm Nation", "Rock"), | |
48 | 30: ("Janet Jackson", "State Of The World", "Rock"), | |
49 | 31: ("Janet Jackson", "The Knowledge", "Rock"), | |
50 | 32: ("Spyro Gyra", "End of Romanticism", "Jazz"), | |
51 | 33: ("Spyro Gyra", "Heliopolis", "Jazz"), | |
52 | 34: ("Spyro Gyra", "Jubilee", "Jazz"), | |
53 | 35: ("Spyro Gyra", "Little Linda", "Jazz"), | |
54 | 36: ("Spyro Gyra", "Morning Dance", "Jazz"), | |
55 | 37: ("Spyro Gyra", "Song for Lorraine", "Jazz"), | |
56 | 38: ("Yes", "Owner Of A Lonely Heart", "Rock"), | |
57 | 39: ("Yes", "Rhythm Of Love", "Rock"), | |
b1cfebd9 RD |
58 | 40: ("Cusco", "Dream Catcher", "New Age"), |
59 | 41: ("Cusco", "Geronimos Laughter", "New Age"), | |
60 | 42: ("Cusco", "Ghost Dance", "New Age"), | |
61 | 43: ("Blue Man Group", "Drumbone", "New Age"), | |
62 | 44: ("Blue Man Group", "Endless Column", "New Age"), | |
63 | 45: ("Blue Man Group", "Klein Mandelbrot", "New Age"), | |
64 | 46: ("Kenny G", "Silhouette", "Jazz"), | |
65 | 47: ("Sade", "Smooth Operator", "Jazz"), | |
66 | 48: ("David Arkenstone", "Papillon (On The Wings Of The Butterfly)", "New Age"), | |
67 | 49: ("David Arkenstone", "Stepping Stars", "New Age"), | |
68 | 50: ("David Arkenstone", "Carnation Lily Lily Rose", "New Age"), | |
69 | 51: ("David Lanz", "Behind The Waterfall", "New Age"), | |
70 | 52: ("David Lanz", "Cristofori's Dream", "New Age"), | |
71 | 53: ("David Lanz", "Heartsounds", "New Age"), | |
72 | 54: ("David Lanz", "Leaves on the Seine", "New Age"), | |
dcd38683 RD |
73 | } |
74 | ||
96bfd053 | 75 | import images |
dcd38683 | 76 | |
6d19860f | 77 | class TestListCtrlPanel(wxPanel, wxColumnSorterMixin): |
cf694132 | 78 | def __init__(self, parent, log): |
c368d904 | 79 | wxPanel.__init__(self, parent, -1, style=wxWANTS_CHARS) |
cf694132 RD |
80 | |
81 | self.log = log | |
f6bcfd97 | 82 | tID = wxNewId() |
cf694132 RD |
83 | |
84 | self.il = wxImageList(16, 16) | |
6d19860f | 85 | |
00887b39 RD |
86 | idx1 = self.il.Add(images.getSmilesBitmap()) |
87 | self.sm_up = self.il.Add(images.getSmallUpArrowBitmap()) | |
88 | self.sm_dn = self.il.Add(images.getSmallDnArrowBitmap()) | |
89 | ||
90 | #idx1 = self.il.AddIcon(wxIconFromXPMData(images.getSmilesData())) | |
91 | #self.sm_up = self.il.AddIcon(wxIconFromXPMData(images.getSmallUpArrowData())) | |
92 | #self.sm_dn = self.il.AddIcon(wxIconFromXPMData(images.getSmallDnArrowData())) | |
cf694132 | 93 | |
c368d904 | 94 | self.list = wxListCtrl(self, tID, |
c7e7022c | 95 | style=wxLC_REPORT|wxSUNKEN_BORDER)#|wxLC_VRULES|wxLC_HRULES) |
cf694132 RD |
96 | self.list.SetImageList(self.il, wxIMAGE_LIST_SMALL) |
97 | ||
185d7c3e | 98 | # Why doesn't this show up on MSW??? |
cf694132 | 99 | self.list.SetToolTip(wxToolTip("This is a ToolTip!")) |
cf694132 | 100 | |
6d19860f RD |
101 | if 0: |
102 | # for normal simple columns, you can add them like this: | |
103 | self.list.InsertColumn(0, "Artist") | |
104 | self.list.InsertColumn(1, "Title", wxLIST_FORMAT_RIGHT) | |
105 | self.list.InsertColumn(2, "Genre") | |
106 | else: | |
107 | # but since we want images on the column header we have to do it the hard way: | |
108 | info = wxListItem() | |
109 | info.m_mask = wxLIST_MASK_TEXT | wxLIST_MASK_IMAGE | wxLIST_MASK_FORMAT | |
110 | info.m_image = -1 | |
111 | info.m_format = 0 | |
112 | info.m_text = "Artist" | |
113 | self.list.InsertColumnInfo(0, info) | |
114 | ||
115 | info.m_format = wxLIST_FORMAT_RIGHT | |
116 | info.m_text = "Title" | |
117 | self.list.InsertColumnInfo(1, info) | |
118 | ||
119 | info.m_format = 0 | |
120 | info.m_text = "Genre" | |
121 | self.list.InsertColumnInfo(2, info) | |
122 | ||
123 | ||
0e947004 | 124 | |
dcd38683 RD |
125 | items = musicdata.items() |
126 | for x in range(len(items)): | |
127 | key, data = items[x] | |
128 | self.list.InsertImageStringItem(x, data[0], idx1) | |
129 | self.list.SetStringItem(x, 1, data[1]) | |
130 | self.list.SetStringItem(x, 2, data[2]) | |
131 | self.list.SetItemData(x, key) | |
cf694132 | 132 | |
6d19860f RD |
133 | # Now that the list exists we can init the other base class, |
134 | # see wxPython/lib/mixins/listctrl.py | |
135 | self.itemDataMap = musicdata | |
136 | wxColumnSorterMixin.__init__(self, 3) | |
137 | #self.SortListItems(0, true) | |
138 | ||
cf694132 RD |
139 | self.list.SetColumnWidth(0, wxLIST_AUTOSIZE) |
140 | self.list.SetColumnWidth(1, wxLIST_AUTOSIZE) | |
0e947004 | 141 | self.list.SetColumnWidth(2, 100) |
cf694132 | 142 | |
6d19860f | 143 | # show how to select an item |
9416aa89 | 144 | self.list.SetItemState(5, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED) |
c368d904 | 145 | |
6d19860f | 146 | # show how to change the colour of a couple items |
c368d904 RD |
147 | item = self.list.GetItem(1) |
148 | item.SetTextColour(wxBLUE) | |
149 | self.list.SetItem(item) | |
c7e7022c RD |
150 | item = self.list.GetItem(4) |
151 | item.SetTextColour(wxRED) | |
152 | self.list.SetItem(item) | |
153 | ||
bb0054cd | 154 | self.currentItem = 0 |
f6bcfd97 | 155 | EVT_SIZE(self, self.OnSize) |
bb0054cd | 156 | EVT_LIST_ITEM_SELECTED(self, tID, self.OnItemSelected) |
c368d904 | 157 | EVT_LIST_ITEM_ACTIVATED(self, tID, self.OnItemActivated) |
8bf5d46e | 158 | EVT_LIST_DELETE_ITEM(self, tID, self.OnItemDelete) |
dcd38683 | 159 | EVT_LIST_COL_CLICK(self, tID, self.OnColClick) |
6d19860f RD |
160 | EVT_LIST_COL_RIGHT_CLICK(self, tID, self.OnColRightClick) |
161 | EVT_LIST_COL_BEGIN_DRAG(self, tID, self.OnColBeginDrag) | |
162 | EVT_LIST_COL_DRAGGING(self, tID, self.OnColDragging) | |
163 | EVT_LIST_COL_END_DRAG(self, tID, self.OnColEndDrag) | |
164 | ||
bb0054cd | 165 | EVT_LEFT_DCLICK(self.list, self.OnDoubleClick) |
a08cbc01 RD |
166 | EVT_RIGHT_DOWN(self.list, self.OnRightDown) |
167 | ||
64be6958 RD |
168 | # for wxMSW |
169 | EVT_COMMAND_RIGHT_CLICK(self.list, tID, self.OnRightClick) | |
170 | ||
171 | # for wxGTK | |
172 | EVT_RIGHT_UP(self.list, self.OnRightClick) | |
173 | ||
a08cbc01 | 174 | |
6d19860f RD |
175 | # Used by the wxColumnSorterMixin, see wxPython/lib/mixins/listctrl.py |
176 | def GetListCtrl(self): | |
177 | return self.list | |
178 | ||
179 | # Used by the wxColumnSorterMixin, see wxPython/lib/mixins/listctrl.py | |
180 | def GetSortImages(self): | |
181 | return (self.sm_dn, self.sm_up) | |
182 | ||
183 | ||
184 | ||
a08cbc01 RD |
185 | def OnRightDown(self, event): |
186 | self.x = event.GetX() | |
64be6958 RD |
187 | self.y = event.GetY() |
188 | self.log.WriteText("x, y = %s\n" % str((self.x, self.y))) | |
b1cfebd9 | 189 | print event.GetEventObject() |
a08cbc01 | 190 | event.Skip() |
bb0054cd | 191 | |
185d7c3e RD |
192 | |
193 | def getColumnText(self, index, col): | |
194 | item = self.list.GetItem(index, col) | |
195 | return item.GetText() | |
196 | ||
197 | ||
bb0054cd RD |
198 | def OnItemSelected(self, event): |
199 | self.currentItem = event.m_itemIndex | |
9416aa89 RD |
200 | self.log.WriteText("OnItemSelected: %s, %s, %s, %s\n" % |
201 | (self.currentItem, | |
202 | self.list.GetItemText(self.currentItem), | |
185d7c3e RD |
203 | self.getColumnText(self.currentItem, 1), |
204 | self.getColumnText(self.currentItem, 2))) | |
9416aa89 RD |
205 | if self.currentItem == 10: |
206 | self.log.WriteText("OnItemSelected: Veto'd selection\n") | |
207 | #event.Veto() # doesn't work | |
208 | # this does | |
209 | self.list.SetItemState(10, 0, wxLIST_STATE_SELECTED) | |
185d7c3e | 210 | |
c368d904 RD |
211 | def OnItemActivated(self, event): |
212 | self.currentItem = event.m_itemIndex | |
213 | self.log.WriteText("OnItemActivated: %s\n" % self.list.GetItemText(self.currentItem)) | |
214 | ||
8bf5d46e RD |
215 | def OnItemDelete(self, event): |
216 | self.log.WriteText("OnItemDelete\n") | |
217 | ||
dcd38683 | 218 | def OnColClick(self, event): |
6d19860f RD |
219 | self.log.WriteText("OnColClick: %d\n" % event.GetColumn()) |
220 | ||
221 | def OnColRightClick(self, event): | |
222 | self.log.WriteText("OnColRightClick: %d\n" % event.GetColumn()) | |
dcd38683 | 223 | |
6d19860f RD |
224 | def OnColBeginDrag(self, event): |
225 | self.log.WriteText("OnColBeginDrag\n") | |
c7e7022c | 226 | |
6d19860f RD |
227 | def OnColDragging(self, event): |
228 | self.log.WriteText("OnColDragging\n") | |
dcd38683 | 229 | |
6d19860f RD |
230 | def OnColEndDrag(self, event): |
231 | self.log.WriteText("OnColEndDrag\n") | |
8bf5d46e | 232 | |
bb0054cd RD |
233 | def OnDoubleClick(self, event): |
234 | self.log.WriteText("OnDoubleClick item %s\n" % self.list.GetItemText(self.currentItem)) | |
185d7c3e | 235 | event.Skip() |
a08cbc01 | 236 | |
bb0054cd RD |
237 | def OnRightClick(self, event): |
238 | self.log.WriteText("OnRightClick %s\n" % self.list.GetItemText(self.currentItem)) | |
e166644c | 239 | menu = wxMenu() |
a08cbc01 RD |
240 | tPopupID1 = 0 |
241 | tPopupID2 = 1 | |
242 | tPopupID3 = 2 | |
8bf5d46e | 243 | tPopupID4 = 3 |
e166644c | 244 | tPopupID5 = 5 |
d56cebe7 RD |
245 | #menu.Append(tPopupID1, "One") |
246 | item = wxMenuItem(menu, tPopupID1,"One") | |
247 | item.SetBitmap(images.getSmilesBitmap()) | |
248 | menu.AppendItem(item) | |
e166644c RD |
249 | menu.Append(tPopupID2, "Two") |
250 | menu.Append(tPopupID3, "Three") | |
251 | menu.Append(tPopupID4, "DeleteAllItems") | |
252 | menu.Append(tPopupID5, "GetItem") | |
a08cbc01 RD |
253 | EVT_MENU(self, tPopupID1, self.OnPopupOne) |
254 | EVT_MENU(self, tPopupID2, self.OnPopupTwo) | |
255 | EVT_MENU(self, tPopupID3, self.OnPopupThree) | |
8bf5d46e | 256 | EVT_MENU(self, tPopupID4, self.OnPopupFour) |
e166644c RD |
257 | EVT_MENU(self, tPopupID5, self.OnPopupFive) |
258 | self.PopupMenu(menu, wxPoint(self.x, self.y)) | |
259 | menu.Destroy() | |
185d7c3e | 260 | event.Skip() |
a08cbc01 RD |
261 | |
262 | def OnPopupOne(self, event): | |
263 | self.log.WriteText("Popup one\n") | |
264 | ||
265 | def OnPopupTwo(self, event): | |
266 | self.log.WriteText("Popup two\n") | |
267 | ||
268 | def OnPopupThree(self, event): | |
269 | self.log.WriteText("Popup three\n") | |
cf694132 | 270 | |
8bf5d46e RD |
271 | def OnPopupFour(self, event): |
272 | self.list.DeleteAllItems() | |
273 | ||
e166644c RD |
274 | def OnPopupFive(self, event): |
275 | item = self.list.GetItem(self.currentItem) | |
276 | print item.m_text, item.m_itemId, self.list.GetItemData(self.currentItem) | |
277 | ||
cf694132 RD |
278 | def OnSize(self, event): |
279 | w,h = self.GetClientSizeTuple() | |
280 | self.list.SetDimensions(0, 0, w, h) | |
281 | ||
282 | ||
283 | ||
284 | ||
a08cbc01 RD |
285 | |
286 | ||
cf694132 RD |
287 | #--------------------------------------------------------------------------- |
288 | ||
289 | def runTest(frame, nb, log): | |
290 | win = TestListCtrlPanel(nb, log) | |
291 | return win | |
292 | ||
293 | #--------------------------------------------------------------------------- | |
294 | ||
295 | ||
296 | ||
297 | ||
298 | ||
299 | ||
300 | ||
301 | ||
302 | ||
303 | ||
304 | ||
305 | ||
306 | ||
307 | ||
308 | ||
309 | ||
310 | overview = """\ | |
311 | A list control presents lists in a number of formats: list view, report view, icon view and small icon view. Elements are numbered from zero. | |
312 | ||
cf694132 | 313 | """ |