]> git.saurik.com Git - wxWidgets.git/blob - wxPython/tests/listGetItem.py
adapted to new sending for radiobutton events for unselecting too
[wxWidgets.git] / wxPython / tests / listGetItem.py
1 from wxPython.wx import *
2
3 LIST_ID = 101
4
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")
16
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')
20
21 self.list.SetColumnWidth(0, wxLIST_AUTOSIZE_USEHEADER)
22 self.list.SetColumnWidth(1, wxLIST_AUTOSIZE)
23 self.list.SetColumnWidth(2, wxLIST_AUTOSIZE_USEHEADER)
24
25 EVT_LIST_ITEM_SELECTED(self.panel, LIST_ID, self.OnListSelect)
26
27 self.panel.Layout()
28 return
29
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`))
37 return
38
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)
44 return
45
46 def OnCloseWindow(self, event):
47 self.Destroy()
48 return
49
50
51
52 class MyApp(wxApp):
53 def OnInit(self):
54 frame = MyFrame(None, -1, 'ListCtrl Test')
55 frame.Show(1)
56 self.SetTopWindow(frame)
57 return 1
58
59
60 app = MyApp(0)
61 app.MainLoop()