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