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"),
63 class TestListCtrlPanel(wxPanel
, wxColumnSorterMixin
):
64 def __init__(self
, parent
, log
):
65 wxPanel
.__init
__(self
, parent
, -1, style
=wxWANTS_CHARS
)
70 self
.il
= wxImageList(16, 16)
71 bmp
= images
.getSmilesBitmap()
72 #idx1 = self.il.AddWithColourMask(bmp, wxWHITE)
73 idx1
= self
.il
.Add(bmp
)
74 bmp
= images
.getSmallUpArrowBitmap()
75 self
.sm_up
= self
.il
.Add(bmp
)
76 bmp
= images
.getSmallDnArrowBitmap()
77 self
.sm_dn
= self
.il
.Add(bmp
)
80 self
.list = wxListCtrl(self
, tID
,
81 style
=wxLC_REPORT|wxSUNKEN_BORDER
)#|wxLC_VRULES|wxLC_HRULES)
82 self
.list.SetImageList(self
.il
, wxIMAGE_LIST_SMALL
)
84 # Why doesn't this show up on MSW???
85 self
.list.SetToolTip(wxToolTip("This is a ToolTip!"))
88 # for normal simple columns, you can add them like this:
89 self
.list.InsertColumn(0, "Artist")
90 self
.list.InsertColumn(1, "Title", wxLIST_FORMAT_RIGHT
)
91 self
.list.InsertColumn(2, "Genre")
93 # but since we want images on the column header we have to do it the hard way:
95 info
.m_mask
= wxLIST_MASK_TEXT | wxLIST_MASK_IMAGE | wxLIST_MASK_FORMAT
98 info
.m_text
= "Artist"
99 self
.list.InsertColumnInfo(0, info
)
101 info
.m_format
= wxLIST_FORMAT_RIGHT
102 info
.m_text
= "Title"
103 self
.list.InsertColumnInfo(1, info
)
106 info
.m_text
= "Genre"
107 self
.list.InsertColumnInfo(2, info
)
110 items
= musicdata
.items()
111 for x
in range(len(items
)):
113 self
.list.InsertImageStringItem(x
, data
[0], idx1
)
114 self
.list.SetStringItem(x
, 1, data
[1])
115 self
.list.SetStringItem(x
, 2, data
[2])
116 self
.list.SetItemData(x
, key
)
118 # Now that the list exists we can init the other base class,
119 # see wxPython/lib/mixins/listctrl.py
120 self
.itemDataMap
= musicdata
121 wxColumnSorterMixin
.__init
__(self
, 3)
122 #self.SortListItems(0, true)
124 self
.list.SetColumnWidth(0, wxLIST_AUTOSIZE
)
125 self
.list.SetColumnWidth(1, wxLIST_AUTOSIZE
)
127 # show how to select an item
128 self
.list.SetItemState(5, wxLIST_STATE_SELECTED
, wxLIST_STATE_SELECTED
)
130 # show how to change the colour of a couple items
131 item
= self
.list.GetItem(1)
132 item
.SetTextColour(wxBLUE
)
133 self
.list.SetItem(item
)
134 item
= self
.list.GetItem(4)
135 item
.SetTextColour(wxRED
)
136 self
.list.SetItem(item
)
139 EVT_SIZE(self
, self
.OnSize
)
140 EVT_LIST_ITEM_SELECTED(self
, tID
, self
.OnItemSelected
)
141 EVT_LIST_ITEM_ACTIVATED(self
, tID
, self
.OnItemActivated
)
142 EVT_LIST_DELETE_ITEM(self
, tID
, self
.OnItemDelete
)
143 EVT_LIST_COL_CLICK(self
, tID
, self
.OnColClick
)
144 EVT_LIST_COL_RIGHT_CLICK(self
, tID
, self
.OnColRightClick
)
145 EVT_LIST_COL_BEGIN_DRAG(self
, tID
, self
.OnColBeginDrag
)
146 EVT_LIST_COL_DRAGGING(self
, tID
, self
.OnColDragging
)
147 EVT_LIST_COL_END_DRAG(self
, tID
, self
.OnColEndDrag
)
149 EVT_LEFT_DCLICK(self
.list, self
.OnDoubleClick
)
150 EVT_RIGHT_DOWN(self
.list, self
.OnRightDown
)
153 EVT_COMMAND_RIGHT_CLICK(self
.list, tID
, self
.OnRightClick
)
156 EVT_RIGHT_UP(self
.list, self
.OnRightClick
)
159 # Used by the wxColumnSorterMixin, see wxPython/lib/mixins/listctrl.py
160 def GetListCtrl(self
):
163 # Used by the wxColumnSorterMixin, see wxPython/lib/mixins/listctrl.py
164 def GetSortImages(self
):
165 return (self
.sm_dn
, self
.sm_up
)
169 def OnRightDown(self
, event
):
170 self
.x
= event
.GetX()
171 self
.y
= event
.GetY()
172 self
.log
.WriteText("x, y = %s\n" % str((self
.x
, self
.y
)))
176 def getColumnText(self
, index
, col
):
177 item
= self
.list.GetItem(index
, col
)
178 return item
.GetText()
181 def OnItemSelected(self
, event
):
182 self
.currentItem
= event
.m_itemIndex
183 self
.log
.WriteText("OnItemSelected: %s, %s, %s, %s\n" %
185 self
.list.GetItemText(self
.currentItem
),
186 self
.getColumnText(self
.currentItem
, 1),
187 self
.getColumnText(self
.currentItem
, 2)))
188 if self
.currentItem
== 10:
189 self
.log
.WriteText("OnItemSelected: Veto'd selection\n")
190 #event.Veto() # doesn't work
192 self
.list.SetItemState(10, 0, wxLIST_STATE_SELECTED
)
194 def OnItemActivated(self
, event
):
195 self
.currentItem
= event
.m_itemIndex
196 self
.log
.WriteText("OnItemActivated: %s\n" % self
.list.GetItemText(self
.currentItem
))
198 def OnItemDelete(self
, event
):
199 self
.log
.WriteText("OnItemDelete\n")
201 def OnColClick(self
, event
):
202 self
.log
.WriteText("OnColClick: %d\n" % event
.GetColumn())
204 def OnColRightClick(self
, event
):
205 self
.log
.WriteText("OnColRightClick: %d\n" % event
.GetColumn())
207 def OnColBeginDrag(self
, event
):
208 self
.log
.WriteText("OnColBeginDrag\n")
210 def OnColDragging(self
, event
):
211 self
.log
.WriteText("OnColDragging\n")
213 def OnColEndDrag(self
, event
):
214 self
.log
.WriteText("OnColEndDrag\n")
216 def OnDoubleClick(self
, event
):
217 self
.log
.WriteText("OnDoubleClick item %s\n" % self
.list.GetItemText(self
.currentItem
))
220 def OnRightClick(self
, event
):
221 self
.log
.WriteText("OnRightClick %s\n" % self
.list.GetItemText(self
.currentItem
))
228 #menu.Append(tPopupID1, "One")
229 item
= wxMenuItem(menu
, tPopupID1
,"One")
230 item
.SetBitmap(images
.getSmilesBitmap())
231 menu
.AppendItem(item
)
232 menu
.Append(tPopupID2
, "Two")
233 menu
.Append(tPopupID3
, "Three")
234 menu
.Append(tPopupID4
, "DeleteAllItems")
235 menu
.Append(tPopupID5
, "GetItem")
236 EVT_MENU(self
, tPopupID1
, self
.OnPopupOne
)
237 EVT_MENU(self
, tPopupID2
, self
.OnPopupTwo
)
238 EVT_MENU(self
, tPopupID3
, self
.OnPopupThree
)
239 EVT_MENU(self
, tPopupID4
, self
.OnPopupFour
)
240 EVT_MENU(self
, tPopupID5
, self
.OnPopupFive
)
241 self
.PopupMenu(menu
, wxPoint(self
.x
, self
.y
))
245 def OnPopupOne(self
, event
):
246 self
.log
.WriteText("Popup one\n")
248 def OnPopupTwo(self
, event
):
249 self
.log
.WriteText("Popup two\n")
251 def OnPopupThree(self
, event
):
252 self
.log
.WriteText("Popup three\n")
254 def OnPopupFour(self
, event
):
255 self
.list.DeleteAllItems()
257 def OnPopupFive(self
, event
):
258 item
= self
.list.GetItem(self
.currentItem
)
259 print item
.m_text
, item
.m_itemId
, self
.list.GetItemData(self
.currentItem
)
261 def OnSize(self
, event
):
262 w
,h
= self
.GetClientSizeTuple()
263 self
.list.SetDimensions(0, 0, w
, h
)
270 #---------------------------------------------------------------------------
272 def runTest(frame
, nb
, log
):
273 win
= TestListCtrlPanel(nb
, log
)
276 #---------------------------------------------------------------------------
294 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.