]> git.saurik.com Git - wxWidgets.git/blame - wxPython/demo/wxListCtrl.py
added toolbar handling
[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 *
15
16#---------------------------------------------------------------------------
17
dcd38683
RD
18musicdata = {
191 : ("Bad English", "The Price Of Love", "Rock"),
202 : ("DNA featuring Suzanne Vega", "Tom's Diner", "Rock"),
213 : ("George Michael", "Praying For Time", "Rock"),
224 : ("Gloria Estefan", "Here We Are", "Rock"),
235 : ("Linda Ronstadt", "Don't Know Much", "Rock"),
246 : ("Michael Bolton", "How Am I Supposed To Live Without You", "Blues"),
257 : ("Paul Young", "Oh Girl", "Rock"),
268 : ("Paula Abdul", "Opposites Attract", "Rock"),
279 : ("Richard Marx", "Should've Known Better", "Rock"),
2810: ("Rod Stewart", "Forever Young", "Rock"),
2911: ("Roxette", "Dangerous", "Rock"),
3012: ("Sheena Easton", "The Lover In Me", "Rock"),
3113: ("Sinead O'Connor", "Nothing Compares 2 U", "Rock"),
3214: ("Stevie B.", "Because I Love You", "Rock"),
3315: ("Taylor Dayne", "Love Will Lead You Back", "Rock"),
3416: ("The Bangles", "Eternal Flame", "Rock"),
3517: ("Wilson Phillips", "Release Me", "Rock"),
3618: ("Billy Joel", "Blonde Over Blue", "Rock"),
3719: ("Billy Joel", "Famous Last Words", "Rock"),
3820: ("Billy Joel", "Lullabye (Goodnight, My Angel)", "Rock"),
3921: ("Billy Joel", "The River Of Dreams", "Rock"),
4022: ("Billy Joel", "Two Thousand Years", "Rock"),
4123: ("Janet Jackson", "Alright", "Rock"),
4224: ("Janet Jackson", "Black Cat", "Rock"),
4325: ("Janet Jackson", "Come Back To Me", "Rock"),
4426: ("Janet Jackson", "Escapade", "Rock"),
4527: ("Janet Jackson", "Love Will Never Do (Without You)", "Rock"),
4628: ("Janet Jackson", "Miss You Much", "Rock"),
4729: ("Janet Jackson", "Rhythm Nation", "Rock"),
4830: ("Janet Jackson", "State Of The World", "Rock"),
4931: ("Janet Jackson", "The Knowledge", "Rock"),
5032: ("Spyro Gyra", "End of Romanticism", "Jazz"),
5133: ("Spyro Gyra", "Heliopolis", "Jazz"),
5234: ("Spyro Gyra", "Jubilee", "Jazz"),
5335: ("Spyro Gyra", "Little Linda", "Jazz"),
5436: ("Spyro Gyra", "Morning Dance", "Jazz"),
5537: ("Spyro Gyra", "Song for Lorraine", "Jazz"),
5638: ("Yes", "Owner Of A Lonely Heart", "Rock"),
5739: ("Yes", "Rhythm Of Love", "Rock"),
58}
59
60
cf694132
RD
61class TestListCtrlPanel(wxPanel):
62 def __init__(self, parent, log):
63 wxPanel.__init__(self, parent, -1)
64
65 self.log = log
f6bcfd97 66 tID = wxNewId()
cf694132
RD
67
68 self.il = wxImageList(16, 16)
694759cf 69 idx1 = self.il.Add(wxBitmap('bitmaps/smiles.bmp', wxBITMAP_TYPE_BMP))
cf694132
RD
70
71 self.list = wxListCtrl(self, tID, wxDefaultPosition, wxDefaultSize,
72 wxLC_REPORT|wxSUNKEN_BORDER)
73 self.list.SetImageList(self.il, wxIMAGE_LIST_SMALL)
74
75 self.list.SetToolTip(wxToolTip("This is a ToolTip!"))
76 wxToolTip_Enable(true)
77
dcd38683
RD
78 self.list.InsertColumn(0, "Artist")
79 self.list.InsertColumn(1, "Title")
80 self.list.InsertColumn(2, "Genre")
81 items = musicdata.items()
82 for x in range(len(items)):
83 key, data = items[x]
84 self.list.InsertImageStringItem(x, data[0], idx1)
85 self.list.SetStringItem(x, 1, data[1])
86 self.list.SetStringItem(x, 2, data[2])
87 self.list.SetItemData(x, key)
cf694132
RD
88
89 self.list.SetColumnWidth(0, wxLIST_AUTOSIZE)
90 self.list.SetColumnWidth(1, wxLIST_AUTOSIZE)
dcd38683 91 ##self.list.SetColumnWidth(2, wxLIST_AUTOSIZE)
cf694132 92
bb0054cd
RD
93 self.list.SetItemState(5, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED)
94
95 self.currentItem = 0
f6bcfd97 96 EVT_SIZE(self, self.OnSize)
bb0054cd 97 EVT_LIST_ITEM_SELECTED(self, tID, self.OnItemSelected)
8bf5d46e 98 EVT_LIST_DELETE_ITEM(self, tID, self.OnItemDelete)
dcd38683 99 EVT_LIST_COL_CLICK(self, tID, self.OnColClick)
bb0054cd 100 EVT_LEFT_DCLICK(self.list, self.OnDoubleClick)
a08cbc01
RD
101 EVT_RIGHT_DOWN(self.list, self.OnRightDown)
102
64be6958
RD
103 # for wxMSW
104 EVT_COMMAND_RIGHT_CLICK(self.list, tID, self.OnRightClick)
105
106 # for wxGTK
107 EVT_RIGHT_UP(self.list, self.OnRightClick)
108
a08cbc01
RD
109
110 def OnRightDown(self, event):
111 self.x = event.GetX()
64be6958
RD
112 self.y = event.GetY()
113 self.log.WriteText("x, y = %s\n" % str((self.x, self.y)))
a08cbc01 114 event.Skip()
bb0054cd
RD
115
116 def OnItemSelected(self, event):
117 self.currentItem = event.m_itemIndex
118 self.log.WriteText("OnItemSelected: %s\n" % self.list.GetItemText(self.currentItem))
119
8bf5d46e
RD
120 def OnItemDelete(self, event):
121 self.log.WriteText("OnItemDelete\n")
122
dcd38683
RD
123 def OnColClick(self, event):
124 self.log.WriteText("OnColClick: %d\n" % event.m_col)
125 self.col = event.m_col
126 self.list.SortItems(self.ColumnSorter)
127
128 def ColumnSorter(self, key1, key2):
129 item1 = musicdata[key1][self.col]
130 item2 = musicdata[key2][self.col]
131 if item1 == item2: return 0
132 elif item1 < item2: return -1
133 else: return 1
134
8bf5d46e 135
bb0054cd
RD
136 def OnDoubleClick(self, event):
137 self.log.WriteText("OnDoubleClick item %s\n" % self.list.GetItemText(self.currentItem))
138
a08cbc01 139
bb0054cd
RD
140 def OnRightClick(self, event):
141 self.log.WriteText("OnRightClick %s\n" % self.list.GetItemText(self.currentItem))
e166644c 142 menu = wxMenu()
a08cbc01
RD
143 tPopupID1 = 0
144 tPopupID2 = 1
145 tPopupID3 = 2
8bf5d46e 146 tPopupID4 = 3
e166644c
RD
147 tPopupID5 = 5
148 menu.Append(tPopupID1, "One")
149 menu.Append(tPopupID2, "Two")
150 menu.Append(tPopupID3, "Three")
151 menu.Append(tPopupID4, "DeleteAllItems")
152 menu.Append(tPopupID5, "GetItem")
a08cbc01
RD
153 EVT_MENU(self, tPopupID1, self.OnPopupOne)
154 EVT_MENU(self, tPopupID2, self.OnPopupTwo)
155 EVT_MENU(self, tPopupID3, self.OnPopupThree)
8bf5d46e 156 EVT_MENU(self, tPopupID4, self.OnPopupFour)
e166644c
RD
157 EVT_MENU(self, tPopupID5, self.OnPopupFive)
158 self.PopupMenu(menu, wxPoint(self.x, self.y))
159 menu.Destroy()
a08cbc01
RD
160
161 def OnPopupOne(self, event):
162 self.log.WriteText("Popup one\n")
163
164 def OnPopupTwo(self, event):
165 self.log.WriteText("Popup two\n")
166
167 def OnPopupThree(self, event):
168 self.log.WriteText("Popup three\n")
cf694132 169
8bf5d46e
RD
170 def OnPopupFour(self, event):
171 self.list.DeleteAllItems()
172
e166644c
RD
173 def OnPopupFive(self, event):
174 item = self.list.GetItem(self.currentItem)
175 print item.m_text, item.m_itemId, self.list.GetItemData(self.currentItem)
176
cf694132
RD
177 def OnSize(self, event):
178 w,h = self.GetClientSizeTuple()
179 self.list.SetDimensions(0, 0, w, h)
180
181
182
183
a08cbc01
RD
184
185
cf694132
RD
186#---------------------------------------------------------------------------
187
188def runTest(frame, nb, log):
189 win = TestListCtrlPanel(nb, log)
190 return win
191
192#---------------------------------------------------------------------------
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209overview = """\
210A list control presents lists in a number of formats: list view, report view, icon view and small icon view. Elements are numbered from zero.
211
212wxListCtrl()
213------------------------
214
215Default constructor.
216
217wxListCtrl(wxWindow* parent, wxWindowID id, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = wxLC_ICON, const wxValidator& validator = wxDefaultValidator, const wxString& name = "listCtrl")
218
219Constructor, creating and showing a list control.
220
221Parameters
222-------------------
223
224parent = Parent window. Must not be NULL.
225
226id = Window identifier. A value of -1 indicates a default value.
227
228pos = Window position.
229
230size = Window size. If the default size (-1, -1) is specified then the window is sized appropriately.
231
232style = Window style. See wxListCtrl.
233
234validator = Window validator.
235
236name = Window name.
237"""