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 *
16 #---------------------------------------------------------------------------
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"),
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"),
61 class TestListCtrlPanel(wxPanel
):
62 def __init__(self
, parent
, log
):
63 wxPanel
.__init
__(self
, parent
, -1, style
=wxWANTS_CHARS
)
68 self
.il
= wxImageList(16, 16)
69 bmp
= wxBitmap('bitmaps/smiles.bmp', wxBITMAP_TYPE_BMP
)
70 idx1
= self
.il
.AddWithColourMask(bmp
, wxWHITE
)
72 self
.list = wxListCtrl(self
, tID
,
73 style
=wxLC_REPORT|wxSUNKEN_BORDER
)
74 self
.list.SetImageList(self
.il
, wxIMAGE_LIST_SMALL
)
76 # Why doesn't this show up on MSW???
77 self
.list.SetToolTip(wxToolTip("This is a ToolTip!"))
79 self
.list.InsertColumn(0, "Artist")
80 self
.list.InsertColumn(1, "Title", wxLIST_FORMAT_RIGHT
)
81 self
.list.InsertColumn(2, "Genre")
82 items
= musicdata
.items()
83 for x
in range(len(items
)):
85 self
.list.InsertImageStringItem(x
, data
[0], idx1
)
86 self
.list.SetStringItem(x
, 1, data
[1])
87 self
.list.SetStringItem(x
, 2, data
[2])
88 self
.list.SetItemData(x
, key
)
90 self
.list.SetColumnWidth(0, wxLIST_AUTOSIZE
)
91 self
.list.SetColumnWidth(1, wxLIST_AUTOSIZE
)
92 ##self.list.SetColumnWidth(2, wxLIST_AUTOSIZE)
94 self
.list.SetItemState(25, wxLIST_STATE_SELECTED
, wxLIST_STATE_SELECTED
)
96 #self.list.SetItemState(25, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED)
97 #self.list.EnsureVisible(25)
99 # show how to change the colour of an item
100 item
= self
.list.GetItem(1)
101 item
.SetTextColour(wxBLUE
)
102 self
.list.SetItem(item
)
105 EVT_SIZE(self
, self
.OnSize
)
106 EVT_LIST_ITEM_SELECTED(self
, tID
, self
.OnItemSelected
)
107 EVT_LIST_ITEM_ACTIVATED(self
, tID
, self
.OnItemActivated
)
108 EVT_LIST_DELETE_ITEM(self
, tID
, self
.OnItemDelete
)
109 EVT_LIST_COL_CLICK(self
, tID
, self
.OnColClick
)
110 EVT_LEFT_DCLICK(self
.list, self
.OnDoubleClick
)
111 EVT_RIGHT_DOWN(self
.list, self
.OnRightDown
)
114 EVT_COMMAND_RIGHT_CLICK(self
.list, tID
, self
.OnRightClick
)
117 EVT_RIGHT_UP(self
.list, self
.OnRightClick
)
120 def OnRightDown(self
, event
):
121 self
.x
= event
.GetX()
122 self
.y
= event
.GetY()
123 self
.log
.WriteText("x, y = %s\n" % str((self
.x
, self
.y
)))
127 def getColumnText(self
, index
, col
):
128 item
= self
.list.GetItem(index
, col
)
129 return item
.GetText()
132 def OnItemSelected(self
, event
):
133 self
.currentItem
= event
.m_itemIndex
134 self
.log
.WriteText("OnItemSelected: %s, %s, %s\n" %
135 (self
.list.GetItemText(self
.currentItem
),
136 self
.getColumnText(self
.currentItem
, 1),
137 self
.getColumnText(self
.currentItem
, 2)))
140 def OnItemActivated(self
, event
):
141 self
.currentItem
= event
.m_itemIndex
142 self
.log
.WriteText("OnItemActivated: %s\n" % self
.list.GetItemText(self
.currentItem
))
144 def OnItemDelete(self
, event
):
145 self
.log
.WriteText("OnItemDelete\n")
147 def OnColClick(self
, event
):
148 self
.log
.WriteText("OnColClick: %d\n" % event
.m_col
)
149 self
.col
= event
.m_col
150 self
.list.SortItems(self
.ColumnSorter
)
152 def ColumnSorter(self
, key1
, key2
):
153 item1
= musicdata
[key1
][self
.col
]
154 item2
= musicdata
[key2
][self
.col
]
155 if item1
== item2
: return 0
156 elif item1
< item2
: return -1
160 def OnDoubleClick(self
, event
):
161 self
.log
.WriteText("OnDoubleClick item %s\n" % self
.list.GetItemText(self
.currentItem
))
164 def OnRightClick(self
, event
):
165 self
.log
.WriteText("OnRightClick %s\n" % self
.list.GetItemText(self
.currentItem
))
172 menu
.Append(tPopupID1
, "One")
173 menu
.Append(tPopupID2
, "Two")
174 menu
.Append(tPopupID3
, "Three")
175 menu
.Append(tPopupID4
, "DeleteAllItems")
176 menu
.Append(tPopupID5
, "GetItem")
177 EVT_MENU(self
, tPopupID1
, self
.OnPopupOne
)
178 EVT_MENU(self
, tPopupID2
, self
.OnPopupTwo
)
179 EVT_MENU(self
, tPopupID3
, self
.OnPopupThree
)
180 EVT_MENU(self
, tPopupID4
, self
.OnPopupFour
)
181 EVT_MENU(self
, tPopupID5
, self
.OnPopupFive
)
182 self
.PopupMenu(menu
, wxPoint(self
.x
, self
.y
))
186 def OnPopupOne(self
, event
):
187 self
.log
.WriteText("Popup one\n")
189 def OnPopupTwo(self
, event
):
190 self
.log
.WriteText("Popup two\n")
192 def OnPopupThree(self
, event
):
193 self
.log
.WriteText("Popup three\n")
195 def OnPopupFour(self
, event
):
196 self
.list.DeleteAllItems()
198 def OnPopupFive(self
, event
):
199 item
= self
.list.GetItem(self
.currentItem
)
200 print item
.m_text
, item
.m_itemId
, self
.list.GetItemData(self
.currentItem
)
202 def OnSize(self
, event
):
203 w
,h
= self
.GetClientSizeTuple()
204 self
.list.SetDimensions(0, 0, w
, h
)
211 #---------------------------------------------------------------------------
213 def runTest(frame
, nb
, log
):
214 win
= TestListCtrlPanel(nb
, log
)
217 #---------------------------------------------------------------------------
235 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.
238 ------------------------
242 wxListCtrl(wxWindow* parent, wxWindowID id, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = wxLC_ICON, const wxValidator& validator = wxDefaultValidator, const wxString& name = "listCtrl")
244 Constructor, creating and showing a list control.
249 parent = Parent window. Must not be NULL.
251 id = Window identifier. A value of -1 indicates a default value.
253 pos = Window position.
255 size = Window size. If the default size (-1, -1) is specified then the window is sized appropriately.
257 style = Window style. See wxListCtrl.
259 validator = Window validator.