]> git.saurik.com Git - wxWidgets.git/blame - utils/wxPython/demo/wxListCtrl.py
Makefile for mingw/gcc-2.95
[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)
42
43 self.list.SetColumnWidth(0, wxLIST_AUTOSIZE)
44 self.list.SetColumnWidth(1, wxLIST_AUTOSIZE)
45 self.list.SetColumnWidth(2, wxLIST_AUTOSIZE)
46
bb0054cd
RD
47 self.list.SetItemState(5, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED)
48
49 self.currentItem = 0
50 EVT_LIST_ITEM_SELECTED(self, tID, self.OnItemSelected)
8bf5d46e 51 EVT_LIST_DELETE_ITEM(self, tID, self.OnItemDelete)
bb0054cd 52 EVT_LEFT_DCLICK(self.list, self.OnDoubleClick)
a08cbc01
RD
53 EVT_RIGHT_DOWN(self.list, self.OnRightDown)
54
64be6958
RD
55 # for wxMSW
56 EVT_COMMAND_RIGHT_CLICK(self.list, tID, self.OnRightClick)
57
58 # for wxGTK
59 EVT_RIGHT_UP(self.list, self.OnRightClick)
60
a08cbc01
RD
61
62 def OnRightDown(self, event):
63 self.x = event.GetX()
64be6958
RD
64 self.y = event.GetY()
65 self.log.WriteText("x, y = %s\n" % str((self.x, self.y)))
a08cbc01 66 event.Skip()
bb0054cd
RD
67
68 def OnItemSelected(self, event):
69 self.currentItem = event.m_itemIndex
70 self.log.WriteText("OnItemSelected: %s\n" % self.list.GetItemText(self.currentItem))
71
8bf5d46e
RD
72 def OnItemDelete(self, event):
73 self.log.WriteText("OnItemDelete\n")
74
75
bb0054cd
RD
76 def OnDoubleClick(self, event):
77 self.log.WriteText("OnDoubleClick item %s\n" % self.list.GetItemText(self.currentItem))
78
a08cbc01 79
bb0054cd
RD
80 def OnRightClick(self, event):
81 self.log.WriteText("OnRightClick %s\n" % self.list.GetItemText(self.currentItem))
64be6958 82 self.menu = wxMenu()
a08cbc01
RD
83 tPopupID1 = 0
84 tPopupID2 = 1
85 tPopupID3 = 2
8bf5d46e 86 tPopupID4 = 3
64be6958
RD
87 self.menu.Append(tPopupID1, "One")
88 self.menu.Append(tPopupID2, "Two")
89 self.menu.Append(tPopupID3, "Three")
8bf5d46e 90 self.menu.Append(tPopupID4, "DeleteAllItems")
a08cbc01
RD
91 EVT_MENU(self, tPopupID1, self.OnPopupOne)
92 EVT_MENU(self, tPopupID2, self.OnPopupTwo)
93 EVT_MENU(self, tPopupID3, self.OnPopupThree)
8bf5d46e
RD
94 EVT_MENU(self, tPopupID4, self.OnPopupFour)
95 self.PopupMenu(self.menu, wxPoint(self.x, self.y))
a08cbc01
RD
96
97 def OnPopupOne(self, event):
98 self.log.WriteText("Popup one\n")
99
100 def OnPopupTwo(self, event):
101 self.log.WriteText("Popup two\n")
102
103 def OnPopupThree(self, event):
104 self.log.WriteText("Popup three\n")
cf694132 105
8bf5d46e
RD
106 def OnPopupFour(self, event):
107 self.list.DeleteAllItems()
108
cf694132
RD
109 def OnSize(self, event):
110 w,h = self.GetClientSizeTuple()
111 self.list.SetDimensions(0, 0, w, h)
112
113
114
115
a08cbc01
RD
116
117
cf694132
RD
118#---------------------------------------------------------------------------
119
120def runTest(frame, nb, log):
121 win = TestListCtrlPanel(nb, log)
122 return win
123
124#---------------------------------------------------------------------------
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141overview = """\
142A list control presents lists in a number of formats: list view, report view, icon view and small icon view. Elements are numbered from zero.
143
144wxListCtrl()
145------------------------
146
147Default constructor.
148
149wxListCtrl(wxWindow* parent, wxWindowID id, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = wxLC_ICON, const wxValidator& validator = wxDefaultValidator, const wxString& name = "listCtrl")
150
151Constructor, creating and showing a list control.
152
153Parameters
154-------------------
155
156parent = Parent window. Must not be NULL.
157
158id = Window identifier. A value of -1 indicates a default value.
159
160pos = Window position.
161
162size = Window size. If the default size (-1, -1) is specified then the window is sized appropriately.
163
164style = Window style. See wxListCtrl.
165
166validator = Window validator.
167
168name = Window name.
169"""