Hi, I’m trying to create a list ctrl that I will only use the events When a line is selected, I’m editing the demo app but I can’t add the itens, Look at my code and please try to find the mistake:
class TestListCtrl(wx.ListCtrl, listmix.ListCtrlAutoWidthMixin):
def init(self, parent, ID, pos=wx.DefaultPosition,
size=wx.DefaultSize, style=0):
wx.ListCtrl.init(self, parent, ID, pos, size, style)
listmix.ListCtrlAutoWidthMixin.init(self)
class ListaDuplas(wx.Panel):
def init(self, parent):
wx.Panel.init(self, parent, -1, style=wx.WANTS_CHARS)
tID = wx.NewId()
sizer = wx.BoxSizer(wx.VERTICAL)
if wx.Platform == "__WXMAC__" and \
hasattr(wx.GetApp().GetTopWindow(), "LoadDemo"):
self.useNative = wx.CheckBox(self, -1, "Use native listctrl")
self.useNative.SetValue(
not wx.SystemOptions.GetOptionInt("mac.listctrl.always_use_generic") )
self.Bind(wx.EVT_CHECKBOX, self.OnUseNative, self.useNative)
sizer.Add(self.useNative, 0, wx.ALL | wx.ALIGN_RIGHT, 4)
self.list = TestListCtrl(self, tID,
style=wx.LC_REPORT
> wx.BORDER_NONE
> wx.LC_SORT_ASCENDING)
sizer.Add(self.list, 1, wx.EXPAND)
self.PopulateList()
# Now that the list exists we can init the other base class,
# see wx/lib/mixins/listctrl.py
self.itemDataMap = musicdata
self.SetSizer(sizer)
self.SetAutoLayout(True)
self.Bind(wx.EVT_LIST_ITEM_SELECTED, self.OnItemSelected, self.list)
def OnUseNative(self, event):
wx.SystemOptions.SetOptionInt("mac.listctrl.always_use_generic", not event.IsChecked())
wx.GetApp().GetTopWindow().LoadDemo("ListCtrl")
def PopulateList(self):
self.list.InsertColumn(0, "Duplas")
self.list.InsertColumn(1, "Erros", wx.LIST_FORMAT_RIGHT)
items = musicdata.items()
index = 0
for key, data in items:
self.list.SetStringItem(index, 1, data[1])
self.list.SetStringItem(index, 2, data[2])
self.list.SetItemData(index, key)
index += 1
self.list.SetColumnWidth(0, wx.LIST_AUTOSIZE)
self.list.SetColumnWidth(1, wx.LIST_AUTOSIZE)
self.list.SetColumnWidth(2, 100)
# show how to select an item
self.list.SetItemState(5, wx.LIST_STATE_SELECTED, wx.LIST_STATE_SELECTED)
# show how to change the colour of a couple items
item = self.list.GetItem(1)
item.SetTextColour(wx.BLUE)
self.list.SetItem(item)
item = self.list.GetItem(4)
item.SetTextColour(wx.RED)
self.list.SetItem(item)
self.currentItem = 0
def OnItemSelected(self, event):
##print event.GetItem().GetTextColour()
self.currentItem = event.m_itemIndex
str = list.GetItemText(self.currentItem) + self.getColumnText(self.currentItem, 1) + self.getColumnText(self.currentItem, 2)
event.Skip()