1 from wxPython
.wx
import *
5 class MyFrame(wxFrame
):
6 def __init__(self
, parent
, id, title
):
7 wxFrame
.__init
__(self
, parent
, id, title
,
8 wxDefaultPosition
, wxSize(400, 400))
9 self
.panel
= wxPanel(self
, -1)
10 self
.list = wxListCtrl(self
.panel
, LIST_ID
,
11 wxPoint(10, 10), wxSize(370, 330),
12 wxLC_REPORT|wxSUNKEN_BORDER
)
13 self
.list.InsertColumn(0, "Id")
14 self
.list.InsertColumn(1, "Type")
15 self
.list.InsertColumn(2, "Description")
17 self
.insertRow(self
.list, 0, 'CD', 'Dark Side of the Moon')
18 self
.insertRow(self
.list, 1, 'DVD', 'The Matrix')
19 self
.insertRow(self
.list, 2, 'Book', 'Crime and Punishment')
21 self
.list.SetColumnWidth(0, wxLIST_AUTOSIZE_USEHEADER
)
22 self
.list.SetColumnWidth(1, wxLIST_AUTOSIZE
)
23 self
.list.SetColumnWidth(2, wxLIST_AUTOSIZE_USEHEADER
)
25 EVT_LIST_ITEM_SELECTED(self
.panel
, LIST_ID
, self
.OnListSelect
)
30 def OnListSelect(self
, event
):
31 item
= self
.list.GetItem(event
.m_itemIndex
, 1)
32 print item
.m_itemId
, item
.m_col
, item
.m_state
33 type = self
.list.GetItem(event
.m_itemIndex
, col
=1).m_text
34 desc
= self
.list.GetItem(event
.m_itemIndex
, col
=2).m_text
35 print ('Row Selected: Id: %d, Type: %s, Desc: %s' %
36 (event
.m_itemIndex
, `
type`
, `desc`
))
39 def insertRow(self
, list, row
, type, desc
):
40 list.InsertStringItem(row
, 'label' + `row`
)
41 list.SetStringItem(row
, 0, `row`
)
42 list.SetStringItem(row
, 1, type)
43 list.SetStringItem(row
, 2, desc
)
46 def OnCloseWindow(self
, event
):
54 frame
= MyFrame(None, -1, 'ListCtrl Test')
56 self
.SetTopWindow(frame
)