]> git.saurik.com Git - wxWidgets.git/blame - utils/wxPython/demo/wxListCtrl.py
Added some test code...
[wxWidgets.git] / utils / 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
18class TestListCtrlPanel(wxPanel):
19 def __init__(self, parent, log):
20 wxPanel.__init__(self, parent, -1)
21
22 self.log = log
23 tID = NewId()
24
25 self.il = wxImageList(16, 16)
26 idx1 = self.il.Add(wxNoRefBitmap('bitmaps/smiles.bmp', wxBITMAP_TYPE_BMP))
27
28 self.list = wxListCtrl(self, tID, wxDefaultPosition, wxDefaultSize,
29 wxLC_REPORT|wxSUNKEN_BORDER)
30 self.list.SetImageList(self.il, wxIMAGE_LIST_SMALL)
31
32 self.list.SetToolTip(wxToolTip("This is a ToolTip!"))
33 wxToolTip_Enable(true)
34
35 self.list.InsertColumn(0, "Column 0")
36 self.list.InsertColumn(1, "Column 1")
37 self.list.InsertColumn(2, "One More Column (2)")
38 for x in range(50):
39 self.list.InsertImageStringItem(x, "This is item %d" % x, idx1)
40 self.list.SetStringItem(x, 1, "Col 1, item %d" % x)
41 self.list.SetStringItem(x, 2, "item %d in column 2" % x)
e166644c 42 self.list.SetItemData(x, x*2)
cf694132
RD
43
44 self.list.SetColumnWidth(0, wxLIST_AUTOSIZE)
45 self.list.SetColumnWidth(1, wxLIST_AUTOSIZE)
46 self.list.SetColumnWidth(2, wxLIST_AUTOSIZE)
47
bb0054cd
RD
48 self.list.SetItemState(5, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED)
49
50 self.currentItem = 0
51 EVT_LIST_ITEM_SELECTED(self, tID, self.OnItemSelected)
8bf5d46e 52 EVT_LIST_DELETE_ITEM(self, tID, self.OnItemDelete)
bb0054cd 53 EVT_LEFT_DCLICK(self.list, self.OnDoubleClick)
a08cbc01
RD
54 EVT_RIGHT_DOWN(self.list, self.OnRightDown)
55
64be6958
RD
56 # for wxMSW
57 EVT_COMMAND_RIGHT_CLICK(self.list, tID, self.OnRightClick)
58
59 # for wxGTK
60 EVT_RIGHT_UP(self.list, self.OnRightClick)
61
a08cbc01
RD
62
63 def OnRightDown(self, event):
64 self.x = event.GetX()
64be6958
RD
65 self.y = event.GetY()
66 self.log.WriteText("x, y = %s\n" % str((self.x, self.y)))
a08cbc01 67 event.Skip()
bb0054cd
RD
68
69 def OnItemSelected(self, event):
70 self.currentItem = event.m_itemIndex
71 self.log.WriteText("OnItemSelected: %s\n" % self.list.GetItemText(self.currentItem))
72
8bf5d46e
RD
73 def OnItemDelete(self, event):
74 self.log.WriteText("OnItemDelete\n")
75
76
bb0054cd
RD
77 def OnDoubleClick(self, event):
78 self.log.WriteText("OnDoubleClick item %s\n" % self.list.GetItemText(self.currentItem))
79
a08cbc01 80
bb0054cd
RD
81 def OnRightClick(self, event):
82 self.log.WriteText("OnRightClick %s\n" % self.list.GetItemText(self.currentItem))
e166644c 83 menu = wxMenu()
a08cbc01
RD
84 tPopupID1 = 0
85 tPopupID2 = 1
86 tPopupID3 = 2
8bf5d46e 87 tPopupID4 = 3
e166644c
RD
88 tPopupID5 = 5
89 menu.Append(tPopupID1, "One")
90 menu.Append(tPopupID2, "Two")
91 menu.Append(tPopupID3, "Three")
92 menu.Append(tPopupID4, "DeleteAllItems")
93 menu.Append(tPopupID5, "GetItem")
a08cbc01
RD
94 EVT_MENU(self, tPopupID1, self.OnPopupOne)
95 EVT_MENU(self, tPopupID2, self.OnPopupTwo)
96 EVT_MENU(self, tPopupID3, self.OnPopupThree)
8bf5d46e 97 EVT_MENU(self, tPopupID4, self.OnPopupFour)
e166644c
RD
98 EVT_MENU(self, tPopupID5, self.OnPopupFive)
99 self.PopupMenu(menu, wxPoint(self.x, self.y))
100 menu.Destroy()
a08cbc01
RD
101
102 def OnPopupOne(self, event):
103 self.log.WriteText("Popup one\n")
104
105 def OnPopupTwo(self, event):
106 self.log.WriteText("Popup two\n")
107
108 def OnPopupThree(self, event):
109 self.log.WriteText("Popup three\n")
cf694132 110
8bf5d46e
RD
111 def OnPopupFour(self, event):
112 self.list.DeleteAllItems()
113
e166644c
RD
114 def OnPopupFive(self, event):
115 item = self.list.GetItem(self.currentItem)
116 print item.m_text, item.m_itemId, self.list.GetItemData(self.currentItem)
117
cf694132
RD
118 def OnSize(self, event):
119 w,h = self.GetClientSizeTuple()
120 self.list.SetDimensions(0, 0, w, h)
121
122
123
124
a08cbc01
RD
125
126
cf694132
RD
127#---------------------------------------------------------------------------
128
129def runTest(frame, nb, log):
130 win = TestListCtrlPanel(nb, log)
131 return win
132
133#---------------------------------------------------------------------------
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150overview = """\
151A list control presents lists in a number of formats: list view, report view, icon view and small icon view. Elements are numbered from zero.
152
153wxListCtrl()
154------------------------
155
156Default constructor.
157
158wxListCtrl(wxWindow* parent, wxWindowID id, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = wxLC_ICON, const wxValidator& validator = wxDefaultValidator, const wxString& name = "listCtrl")
159
160Constructor, creating and showing a list control.
161
162Parameters
163-------------------
164
165parent = Parent window. Must not be NULL.
166
167id = Window identifier. A value of -1 indicates a default value.
168
169pos = Window position.
170
171size = Window size. If the default size (-1, -1) is specified then the window is sized appropriately.
172
173style = Window style. See wxListCtrl.
174
175validator = Window validator.
176
177name = Window name.
178"""