2 #----------------------------------------------------------------------------
4 # Purpose: Testing lots of stuff, controls, window types, etc.
6 # Author: Robin Dunn & Gary Dumer
10 # Copyright: (c) 1998 by Total Control Software
11 # Licence: wxWindows license
12 #----------------------------------------------------------------------------
14 from wxPython
.wx
import *
15 from wxPython
.lib
.mixins
.listctrl
import wxColumnSorterMixin
17 #---------------------------------------------------------------------------
20 1 : ("Bad English", "The Price Of Love", "Rock"),
21 2 : ("DNA featuring Suzanne Vega", "Tom's Diner", "Rock"),
22 3 : ("George Michael", "Praying For Time", "Rock"),
23 4 : ("Gloria Estefan", "Here We Are", "Rock"),
24 5 : ("Linda Ronstadt", "Don't Know Much", "Rock"),
25 6 : ("Michael Bolton", "How Am I Supposed To Live Without You", "Blues"),
26 7 : ("Paul Young", "Oh Girl", "Rock"),
27 8 : ("Paula Abdul", "Opposites Attract", "Rock"),
28 9 : ("Richard Marx", "Should've Known Better", "Rock"),
29 10: ("Rod Stewart", "Forever Young", "Rock"),
30 11: ("Roxette", "Dangerous", "Rock"),
31 12: ("Sheena Easton", "The Lover In Me", "Rock"),
32 13: ("Sinead O'Connor", "Nothing Compares 2 U", "Rock"),
33 14: ("Stevie B.", "Because I Love You", "Rock"),
34 15: ("Taylor Dayne", "Love Will Lead You Back", "Rock"),
35 16: ("The Bangles", "Eternal Flame", "Rock"),
36 17: ("Wilson Phillips", "Release Me", "Rock"),
37 18: ("Billy Joel", "Blonde Over Blue", "Rock"),
38 19: ("Billy Joel", "Famous Last Words", "Rock"),
39 20: ("Billy Joel", "Lullabye (Goodnight, My Angel)", "Rock"),
40 21: ("Billy Joel", "The River Of Dreams", "Rock"),
41 22: ("Billy Joel", "Two Thousand Years", "Rock"),
42 23: ("Janet Jackson", "Alright", "Rock"),
43 24: ("Janet Jackson", "Black Cat", "Rock"),
44 25: ("Janet Jackson", "Come Back To Me", "Rock"),
45 26: ("Janet Jackson", "Escapade", "Rock"),
46 27: ("Janet Jackson", "Love Will Never Do (Without You)", "Rock"),
47 28: ("Janet Jackson", "Miss You Much", "Rock"),
48 29: ("Janet Jackson", "Rhythm Nation", "Rock"),
49 30: ("Janet Jackson", "State Of The World", "Rock"),
50 31: ("Janet Jackson", "The Knowledge", "Rock"),
51 32: ("Spyro Gyra", "End of Romanticism", "Jazz"),
52 33: ("Spyro Gyra", "Heliopolis", "Jazz"),
53 34: ("Spyro Gyra", "Jubilee", "Jazz"),
54 35: ("Spyro Gyra", "Little Linda", "Jazz"),
55 36: ("Spyro Gyra", "Morning Dance", "Jazz"),
56 37: ("Spyro Gyra", "Song for Lorraine", "Jazz"),
57 38: ("Yes", "Owner Of A Lonely Heart", "Rock"),
58 39: ("Yes", "Rhythm Of Love", "Rock"),
59 40: ("Cusco", "Dream Catcher", "New Age"),
60 41: ("Cusco", "Geronimos Laughter", "New Age"),
61 42: ("Cusco", "Ghost Dance", "New Age"),
62 43: ("Blue Man Group", "Drumbone", "New Age"),
63 44: ("Blue Man Group", "Endless Column", "New Age"),
64 45: ("Blue Man Group", "Klein Mandelbrot", "New Age"),
65 46: ("Kenny G", "Silhouette", "Jazz"),
66 47: ("Sade", "Smooth Operator", "Jazz"),
67 48: ("David Arkenstone", "Papillon (On The Wings Of The Butterfly)", "New Age"),
68 49: ("David Arkenstone", "Stepping Stars", "New Age"),
69 50: ("David Arkenstone", "Carnation Lily Lily Rose", "New Age"),
70 51: ("David Lanz", "Behind The Waterfall", "New Age"),
71 52: ("David Lanz", "Cristofori's Dream", "New Age"),
72 53: ("David Lanz", "Heartsounds", "New Age"),
73 54: ("David Lanz", "Leaves on the Seine", "New Age"),
78 class TestListCtrlPanel(wxPanel
, wxColumnSorterMixin
):
79 def __init__(self
, parent
, log
):
80 wxPanel
.__init
__(self
, parent
, -1, style
=wxWANTS_CHARS
)
85 self
.il
= wxImageList(16, 16)
86 bmp
= images
.getSmilesBitmap()
87 #idx1 = self.il.AddWithColourMask(bmp, wxWHITE)
88 idx1
= self
.il
.Add(bmp
)
89 bmp
= images
.getSmallUpArrowBitmap()
90 self
.sm_up
= self
.il
.Add(bmp
)
91 bmp
= images
.getSmallDnArrowBitmap()
92 self
.sm_dn
= self
.il
.Add(bmp
)
95 self
.list = wxListCtrl(self
, tID
,
96 style
=wxLC_REPORT|wxSUNKEN_BORDER
)#|wxLC_VRULES|wxLC_HRULES)
97 self
.list.SetImageList(self
.il
, wxIMAGE_LIST_SMALL
)
99 # Why doesn't this show up on MSW???
100 self
.list.SetToolTip(wxToolTip("This is a ToolTip!"))
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")
108 # but since we want images on the column header we have to do it the hard way:
110 info
.m_mask
= wxLIST_MASK_TEXT | wxLIST_MASK_IMAGE | wxLIST_MASK_FORMAT
113 info
.m_text
= "Artist"
114 self
.list.InsertColumnInfo(0, info
)
116 info
.m_format
= wxLIST_FORMAT_RIGHT
117 info
.m_text
= "Title"
118 self
.list.InsertColumnInfo(1, info
)
121 info
.m_text
= "Genre"
122 self
.list.InsertColumnInfo(2, info
)
126 items
= musicdata
.items()
127 for x
in range(len(items
)):
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
)
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)
140 self
.list.SetColumnWidth(0, wxLIST_AUTOSIZE
)
141 self
.list.SetColumnWidth(1, wxLIST_AUTOSIZE
)
142 self
.list.SetColumnWidth(2, 100)
144 # show how to select an item
145 self
.list.SetItemState(5, wxLIST_STATE_SELECTED
, wxLIST_STATE_SELECTED
)
147 # show how to change the colour of a couple items
148 item
= self
.list.GetItem(1)
149 item
.SetTextColour(wxBLUE
)
150 self
.list.SetItem(item
)
151 item
= self
.list.GetItem(4)
152 item
.SetTextColour(wxRED
)
153 self
.list.SetItem(item
)
156 EVT_SIZE(self
, self
.OnSize
)
157 EVT_LIST_ITEM_SELECTED(self
, tID
, self
.OnItemSelected
)
158 EVT_LIST_ITEM_ACTIVATED(self
, tID
, self
.OnItemActivated
)
159 EVT_LIST_DELETE_ITEM(self
, tID
, self
.OnItemDelete
)
160 EVT_LIST_COL_CLICK(self
, tID
, self
.OnColClick
)
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
)
166 EVT_LEFT_DCLICK(self
.list, self
.OnDoubleClick
)
167 EVT_RIGHT_DOWN(self
.list, self
.OnRightDown
)
170 EVT_COMMAND_RIGHT_CLICK(self
.list, tID
, self
.OnRightClick
)
173 EVT_RIGHT_UP(self
.list, self
.OnRightClick
)
176 # Used by the wxColumnSorterMixin, see wxPython/lib/mixins/listctrl.py
177 def GetListCtrl(self
):
180 # Used by the wxColumnSorterMixin, see wxPython/lib/mixins/listctrl.py
181 def GetSortImages(self
):
182 return (self
.sm_dn
, self
.sm_up
)
186 def OnRightDown(self
, event
):
187 self
.x
= event
.GetX()
188 self
.y
= event
.GetY()
189 self
.log
.WriteText("x, y = %s\n" % str((self
.x
, self
.y
)))
190 print event
.GetEventObject()
194 def getColumnText(self
, index
, col
):
195 item
= self
.list.GetItem(index
, col
)
196 return item
.GetText()
199 def OnItemSelected(self
, event
):
200 self
.currentItem
= event
.m_itemIndex
201 self
.log
.WriteText("OnItemSelected: %s, %s, %s, %s\n" %
203 self
.list.GetItemText(self
.currentItem
),
204 self
.getColumnText(self
.currentItem
, 1),
205 self
.getColumnText(self
.currentItem
, 2)))
206 if self
.currentItem
== 10:
207 self
.log
.WriteText("OnItemSelected: Veto'd selection\n")
208 #event.Veto() # doesn't work
210 self
.list.SetItemState(10, 0, wxLIST_STATE_SELECTED
)
212 def OnItemActivated(self
, event
):
213 self
.currentItem
= event
.m_itemIndex
214 self
.log
.WriteText("OnItemActivated: %s\n" % self
.list.GetItemText(self
.currentItem
))
216 def OnItemDelete(self
, event
):
217 self
.log
.WriteText("OnItemDelete\n")
219 def OnColClick(self
, event
):
220 self
.log
.WriteText("OnColClick: %d\n" % event
.GetColumn())
222 def OnColRightClick(self
, event
):
223 self
.log
.WriteText("OnColRightClick: %d\n" % event
.GetColumn())
225 def OnColBeginDrag(self
, event
):
226 self
.log
.WriteText("OnColBeginDrag\n")
228 def OnColDragging(self
, event
):
229 self
.log
.WriteText("OnColDragging\n")
231 def OnColEndDrag(self
, event
):
232 self
.log
.WriteText("OnColEndDrag\n")
234 def OnDoubleClick(self
, event
):
235 self
.log
.WriteText("OnDoubleClick item %s\n" % self
.list.GetItemText(self
.currentItem
))
238 def OnRightClick(self
, event
):
239 self
.log
.WriteText("OnRightClick %s\n" % self
.list.GetItemText(self
.currentItem
))
246 #menu.Append(tPopupID1, "One")
247 item
= wxMenuItem(menu
, tPopupID1
,"One")
248 item
.SetBitmap(images
.getSmilesBitmap())
249 menu
.AppendItem(item
)
250 menu
.Append(tPopupID2
, "Two")
251 menu
.Append(tPopupID3
, "Three")
252 menu
.Append(tPopupID4
, "DeleteAllItems")
253 menu
.Append(tPopupID5
, "GetItem")
254 EVT_MENU(self
, tPopupID1
, self
.OnPopupOne
)
255 EVT_MENU(self
, tPopupID2
, self
.OnPopupTwo
)
256 EVT_MENU(self
, tPopupID3
, self
.OnPopupThree
)
257 EVT_MENU(self
, tPopupID4
, self
.OnPopupFour
)
258 EVT_MENU(self
, tPopupID5
, self
.OnPopupFive
)
259 self
.PopupMenu(menu
, wxPoint(self
.x
, self
.y
))
263 def OnPopupOne(self
, event
):
264 self
.log
.WriteText("Popup one\n")
266 def OnPopupTwo(self
, event
):
267 self
.log
.WriteText("Popup two\n")
269 def OnPopupThree(self
, event
):
270 self
.log
.WriteText("Popup three\n")
272 def OnPopupFour(self
, event
):
273 self
.list.DeleteAllItems()
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
)
279 def OnSize(self
, event
):
280 w
,h
= self
.GetClientSizeTuple()
281 self
.list.SetDimensions(0, 0, w
, h
)
288 #---------------------------------------------------------------------------
290 def runTest(frame
, nb
, log
):
291 win
= TestListCtrlPanel(nb
, log
)
294 #---------------------------------------------------------------------------
312 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.