Hello,
I am getting this error
Traceback (most recent call last):
File “/usr/lib/python2.7/dist-packages/wx-3.0-gtk2/wx/lib/agw/ultimatelistctrl.py”, line 2256, in OnSetFocus
select = listCtrl.GetItemState(self._itemId, ULC_STATE_SELECTED)
File “/usr/lib/python2.7/dist-packages/wx-3.0-gtk2/wx/lib/agw/ultimatelistctrl.py”, line 8989, in GetItemState
raise Exception(“invalid item index in GetItemState”)
Exception: invalid item index in GetItemState
after having inserted a button into a ultimatelistctrl.
The error appears when clicking on the row after randomly adding and removing rows for some time…
A small script reproducing this problem is shown below.
Thank you in advance for helping,
Bertrand Roessli
import wx
import sys
import wx.lib.agw.ultimatelistctrl as ulc
from wx.lib.mixins.listctrl import ListCtrlAutoWidthMixin
class AutoWidthListCtrl(ulc.UltimateListCtrl, ListCtrlAutoWidthMixin):
def init(self,parent):
ulc.UltimateListCtrl.init(self, parent,id=wx.ID_ANY, agwStyle=wx.LC_REPORT|ulc.ULC_HAS_VARIABLE_ROW_HEIGHT)
ListCtrlAutoWidthMixin.init(self)
DATA = [(“0”, “Zero”), (“1”, “One”), (“2”, “Two”)]
class MainWindow(wx.Frame):
def init(self, *args, **kwargs):
wx.Frame.init(self, *args, **kwargs)
self.panel = wx.Panel(self)
self.list = AutoWidthListCtrl(self.panel)
self.list.Bind(wx.EVT_LIST_ITEM_SELECTED,self.OnSelected)
self.list.InsertColumn(0, “#”)
self.list.InsertColumn(1, “Number”)
self.list.InsertColumn(1, “Button”)
self.appendbutton = wx.Button(self.panel, label=“Append list”)
self.appendbutton.Bind(wx.EVT_BUTTON, self.OnAppendButton)
self.deletebutton = wx.Button(self.panel, label=“Delete row”)
self.deletebutton.Bind(wx.EVT_BUTTON, self.OnDeleteButton)
self.sizer = wx.BoxSizer(wx.VERTICAL)
self.sizer.Add(self.list, 1, wx.ALL | wx.EXPAND, 5)
self.sizer.Add(self.appendbutton, 0, wx.ALL | wx.EXPAND, 5)
self.sizer.Add(self.deletebutton, 0, wx.ALL | wx.EXPAND, 5)
self.panel.SetSizerAndFit(self.sizer)
self.Show()
self.row_index=-1
self.color_picker=dict()
def OnSelected(self, event):
try:
self.row_index=event.GetIndex()
except Exception as err:
print err.args
def OnDeleteButton(self,event):
try:
self.list.DeleteItem(self.row_index)
except Exception as err:
#print err.args
pass
def OnAppendButton(self, event):
for data in DATA:
idx = self.list.InsertStringItem(sys.maxint,data[0])
self.list.SetStringItem(idx, 1, data[0])
button = wx.Button(self.list,idx)
button.SetBackgroundColour((0,0,0))
self.list.SetItemWindow(idx, col=2, wnd=button, expand = True)
if name == “main”:
app = wx.App(False)
win = MainWindow(None)
app.MainLoop()