]> git.saurik.com Git - wxWidgets.git/blob - utils/wxPython/demo/wxListCtrl.py
df3a9f53d29f155761d5e5ff1259cc25066eb3df
[wxWidgets.git] / utils / wxPython / demo / wxListCtrl.py
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
18 class 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
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)
51 EVT_LEFT_DCLICK(self.list, self.OnDoubleClick)
52 EVT_COMMAND_RIGHT_CLICK(self.list, tID, self.OnRightClick)
53 EVT_RIGHT_DOWN(self.list, self.OnRightDown)
54
55
56 def OnRightDown(self, event):
57 self.x = event.GetX()
58 self.log.WriteText("x = %d\n" % self.x)
59 event.Skip()
60
61 def OnItemSelected(self, event):
62 self.currentItem = event.m_itemIndex
63 self.log.WriteText("OnItemSelected: %s\n" % self.list.GetItemText(self.currentItem))
64
65 def OnDoubleClick(self, event):
66 self.log.WriteText("OnDoubleClick item %s\n" % self.list.GetItemText(self.currentItem))
67
68
69 def OnRightClick(self, event):
70 self.log.WriteText("OnRightClick %s\n" % self.list.GetItemText(self.currentItem))
71 menu = wxPyMenu()
72 tPopupID1 = 0
73 tPopupID2 = 1
74 tPopupID3 = 2
75 menu.Append(tPopupID1, "One")
76 menu.Append(tPopupID2, "Two")
77 menu.Append(tPopupID3, "Three")
78 EVT_MENU(self, tPopupID1, self.OnPopupOne)
79 EVT_MENU(self, tPopupID2, self.OnPopupTwo)
80 EVT_MENU(self, tPopupID3, self.OnPopupThree)
81 pos = self.list.GetItemPosition(self.currentItem)
82 self.PopupMenu(menu, self.x, pos.y)
83
84 def OnPopupOne(self, event):
85 self.log.WriteText("Popup one\n")
86
87 def OnPopupTwo(self, event):
88 self.log.WriteText("Popup two\n")
89
90 def OnPopupThree(self, event):
91 self.log.WriteText("Popup three\n")
92
93 def OnSize(self, event):
94 w,h = self.GetClientSizeTuple()
95 self.list.SetDimensions(0, 0, w, h)
96
97
98
99
100
101
102 #---------------------------------------------------------------------------
103
104 def runTest(frame, nb, log):
105 win = TestListCtrlPanel(nb, log)
106 return win
107
108 #---------------------------------------------------------------------------
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125 overview = """\
126 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.
127
128 wxListCtrl()
129 ------------------------
130
131 Default constructor.
132
133 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")
134
135 Constructor, creating and showing a list control.
136
137 Parameters
138 -------------------
139
140 parent = Parent window. Must not be NULL.
141
142 id = Window identifier. A value of -1 indicates a default value.
143
144 pos = Window position.
145
146 size = Window size. If the default size (-1, -1) is specified then the window is sized appropriately.
147
148 style = Window style. See wxListCtrl.
149
150 validator = Window validator.
151
152 name = Window name.
153 """