Trying to write string to a ListCtrl , I don’t understand the logic completely. Is this the proper way?
self.rightPanel = wx.ListCtrl(spliter, -1, style=wx.LC_REPORT)
self.rightPanel.InsertColumn(0, 'LineNumber')
self.rightPanel.InsertColumn(1, 'log')
self.rightPanel.SetColumnWidth(0, 8)
self.rightPanel.SetColumnWidth(1, 80)
def writeConsole(self,str):
item = wx.ListItem()
item.SetText(str)
item.SetTextColour(wx.RED)
item.SetBackgroundColour(wx.BLACK)
index = self.rightPanel.GetItemCount()
self.rightPanel.InsertItem(item)
self.rightPanel.SetStringItem(index, 0, str(index))
self.rightPanel.SetStringItem(index, 1, item.GetText())
1-Why text is not displayed in color ?
2-Why there are 2 different methods for display text in ListCtrl?
ListCtrl.InsertItem()
ListCtrl.SetStringItem()
I think InsertItem just loads the item to list.SetString but displays the item content.(Not Sure)
SetTextColour()andSetBackgroundColour()are methods of the entire listctrl, not of items.For items you should use (valid only for report mode):
InsertItem(index, item)(item here is an instance ofwx.ListItem) is one of theInsertItem()methods to add a new row on a ListCtrl.SetStringItem(index, col, label, imageId=-1)(where index and col parameters are the row and column indexes for a cell) allows setting strings in any selected column. Other insert methods work only for the first column.Reference: wxPython in Action, Noel Rappin and Robin Dunn.