Virtual ListCtrl and GetItemData: recursion error

Wojciech Śmigaj w.smigaj at gmail.com
Sat Jul 21 03:13:59 PDT 2007


Hello,

I'm trying to implement a virtual list control which would retrieve its 
contents from a (partially cached) database. I want to identify the 
items by the numbers set by ListCtrl.SetItemData(). So, in my 
OnGetItemText() function, I call GetItemData(), which however leads to 
recursion errors:

Traceback (most recent call last):
   File "test-vlist.py", line 24, in OnGetItemText
     d = self.GetItemData(item)
RuntimeError: maximum recursion depth exceeded

It looks as if each call of GetItemData() resulted in a new call of the 
OnGetItemText() function -- I don't understand why (could it be a bug in 
wxWidgets/wxPython?).

Here is my sample code:

import wx

class VirtualList(wx.ListCtrl):
     def __init__(self, parent, id=-1):
         wx.ListCtrl.__init__(self, parent, id,
                              style=wx.LC_REPORT | wx.LC_VIRTUAL)

         # Initialize items
         ids = [0, 1, 2]
         self.SetItemCount(len(ids))
         for n, id in enumerate(ids):
             print "Item data:", n, id
             self.SetItemData(n, id)

         # Create headers
         self.InsertColumn(0, "Col 0")
         self.InsertColumn(1, "Col 1")

     def OnGetItemText(self, item, col):
         print "OnGetItemText:", item, col
         # In the practical application, I would now retrieve from a
         # database the text corresponding to the key returned by
         # GetItemData().
         d = self.GetItemData(item)
         return str(d)

class MyFrame(wx.Frame):
    def __init__(self, parent, ID, title):
        wx.Frame.__init__(self, parent, ID, title)

        self.list = VirtualList(self)

app = wx.PySimpleApp()
frame = MyFrame(None, -1, "Virtual ListCtrl Test")
frame.Show()
app.MainLoop()

Does anybody see where the problem lies?

Best regards,
Wojciech Śmigaj




More information about the wxpython-users mailing list