]>
Commit | Line | Data |
---|---|---|
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 | ||
14 | from wxPython.wx import * | |
15 | ||
16 | #--------------------------------------------------------------------------- | |
17 | ||
dcd38683 RD |
18 | musicdata = { |
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"), | |
58 | } | |
59 | ||
60 | ||
cf694132 RD |
61 | class TestListCtrlPanel(wxPanel): |
62 | def __init__(self, parent, log): | |
c368d904 | 63 | wxPanel.__init__(self, parent, -1, style=wxWANTS_CHARS) |
cf694132 RD |
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 | 70 | |
c368d904 RD |
71 | self.list = wxListCtrl(self, tID, |
72 | style=wxLC_REPORT|wxSUNKEN_BORDER) | |
cf694132 RD |
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 | 78 | self.list.InsertColumn(0, "Artist") |
c368d904 | 79 | self.list.InsertColumn(1, "Title", wxLIST_FORMAT_RIGHT) |
dcd38683 RD |
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 | |
c368d904 RD |
93 | self.list.SetItemState(25, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED) |
94 | ||
95 | #self.list.SetItemState(25, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED) | |
96 | #self.list.EnsureVisible(25) | |
97 | ||
98 | # show how to change the colour of an item | |
99 | item = self.list.GetItem(1) | |
100 | item.SetTextColour(wxBLUE) | |
101 | self.list.SetItem(item) | |
bb0054cd RD |
102 | |
103 | self.currentItem = 0 | |
f6bcfd97 | 104 | EVT_SIZE(self, self.OnSize) |
bb0054cd | 105 | EVT_LIST_ITEM_SELECTED(self, tID, self.OnItemSelected) |
c368d904 | 106 | EVT_LIST_ITEM_ACTIVATED(self, tID, self.OnItemActivated) |
8bf5d46e | 107 | EVT_LIST_DELETE_ITEM(self, tID, self.OnItemDelete) |
dcd38683 | 108 | EVT_LIST_COL_CLICK(self, tID, self.OnColClick) |
bb0054cd | 109 | EVT_LEFT_DCLICK(self.list, self.OnDoubleClick) |
a08cbc01 RD |
110 | EVT_RIGHT_DOWN(self.list, self.OnRightDown) |
111 | ||
64be6958 RD |
112 | # for wxMSW |
113 | EVT_COMMAND_RIGHT_CLICK(self.list, tID, self.OnRightClick) | |
114 | ||
115 | # for wxGTK | |
116 | EVT_RIGHT_UP(self.list, self.OnRightClick) | |
117 | ||
a08cbc01 RD |
118 | |
119 | def OnRightDown(self, event): | |
120 | self.x = event.GetX() | |
64be6958 RD |
121 | self.y = event.GetY() |
122 | self.log.WriteText("x, y = %s\n" % str((self.x, self.y))) | |
a08cbc01 | 123 | event.Skip() |
bb0054cd RD |
124 | |
125 | def OnItemSelected(self, event): | |
126 | self.currentItem = event.m_itemIndex | |
127 | self.log.WriteText("OnItemSelected: %s\n" % self.list.GetItemText(self.currentItem)) | |
128 | ||
c368d904 RD |
129 | def OnItemActivated(self, event): |
130 | self.currentItem = event.m_itemIndex | |
131 | self.log.WriteText("OnItemActivated: %s\n" % self.list.GetItemText(self.currentItem)) | |
132 | ||
8bf5d46e RD |
133 | def OnItemDelete(self, event): |
134 | self.log.WriteText("OnItemDelete\n") | |
135 | ||
dcd38683 RD |
136 | def OnColClick(self, event): |
137 | self.log.WriteText("OnColClick: %d\n" % event.m_col) | |
138 | self.col = event.m_col | |
139 | self.list.SortItems(self.ColumnSorter) | |
140 | ||
141 | def ColumnSorter(self, key1, key2): | |
142 | item1 = musicdata[key1][self.col] | |
143 | item2 = musicdata[key2][self.col] | |
144 | if item1 == item2: return 0 | |
145 | elif item1 < item2: return -1 | |
146 | else: return 1 | |
147 | ||
8bf5d46e | 148 | |
bb0054cd RD |
149 | def OnDoubleClick(self, event): |
150 | self.log.WriteText("OnDoubleClick item %s\n" % self.list.GetItemText(self.currentItem)) | |
151 | ||
a08cbc01 | 152 | |
bb0054cd RD |
153 | def OnRightClick(self, event): |
154 | self.log.WriteText("OnRightClick %s\n" % self.list.GetItemText(self.currentItem)) | |
e166644c | 155 | menu = wxMenu() |
a08cbc01 RD |
156 | tPopupID1 = 0 |
157 | tPopupID2 = 1 | |
158 | tPopupID3 = 2 | |
8bf5d46e | 159 | tPopupID4 = 3 |
e166644c RD |
160 | tPopupID5 = 5 |
161 | menu.Append(tPopupID1, "One") | |
162 | menu.Append(tPopupID2, "Two") | |
163 | menu.Append(tPopupID3, "Three") | |
164 | menu.Append(tPopupID4, "DeleteAllItems") | |
165 | menu.Append(tPopupID5, "GetItem") | |
a08cbc01 RD |
166 | EVT_MENU(self, tPopupID1, self.OnPopupOne) |
167 | EVT_MENU(self, tPopupID2, self.OnPopupTwo) | |
168 | EVT_MENU(self, tPopupID3, self.OnPopupThree) | |
8bf5d46e | 169 | EVT_MENU(self, tPopupID4, self.OnPopupFour) |
e166644c RD |
170 | EVT_MENU(self, tPopupID5, self.OnPopupFive) |
171 | self.PopupMenu(menu, wxPoint(self.x, self.y)) | |
172 | menu.Destroy() | |
a08cbc01 RD |
173 | |
174 | def OnPopupOne(self, event): | |
175 | self.log.WriteText("Popup one\n") | |
176 | ||
177 | def OnPopupTwo(self, event): | |
178 | self.log.WriteText("Popup two\n") | |
179 | ||
180 | def OnPopupThree(self, event): | |
181 | self.log.WriteText("Popup three\n") | |
cf694132 | 182 | |
8bf5d46e RD |
183 | def OnPopupFour(self, event): |
184 | self.list.DeleteAllItems() | |
185 | ||
e166644c RD |
186 | def OnPopupFive(self, event): |
187 | item = self.list.GetItem(self.currentItem) | |
188 | print item.m_text, item.m_itemId, self.list.GetItemData(self.currentItem) | |
189 | ||
cf694132 RD |
190 | def OnSize(self, event): |
191 | w,h = self.GetClientSizeTuple() | |
192 | self.list.SetDimensions(0, 0, w, h) | |
193 | ||
194 | ||
195 | ||
196 | ||
a08cbc01 RD |
197 | |
198 | ||
cf694132 RD |
199 | #--------------------------------------------------------------------------- |
200 | ||
201 | def runTest(frame, nb, log): | |
202 | win = TestListCtrlPanel(nb, log) | |
203 | return win | |
204 | ||
205 | #--------------------------------------------------------------------------- | |
206 | ||
207 | ||
208 | ||
209 | ||
210 | ||
211 | ||
212 | ||
213 | ||
214 | ||
215 | ||
216 | ||
217 | ||
218 | ||
219 | ||
220 | ||
221 | ||
222 | overview = """\ | |
223 | 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. | |
224 | ||
225 | wxListCtrl() | |
226 | ------------------------ | |
227 | ||
228 | Default constructor. | |
229 | ||
230 | 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") | |
231 | ||
232 | Constructor, creating and showing a list control. | |
233 | ||
234 | Parameters | |
235 | ------------------- | |
236 | ||
237 | parent = Parent window. Must not be NULL. | |
238 | ||
239 | id = Window identifier. A value of -1 indicates a default value. | |
240 | ||
241 | pos = Window position. | |
242 | ||
243 | size = Window size. If the default size (-1, -1) is specified then the window is sized appropriately. | |
244 | ||
245 | style = Window style. See wxListCtrl. | |
246 | ||
247 | validator = Window validator. | |
248 | ||
249 | name = Window name. | |
250 | """ |