Virtual List Control not getting Callbacks

Hello,

I am trying to use a virtual list, but I am not getting the callbacks
to populate the fields. I basically end up with an empty virtural
list control.

Below is my code that creates it.

I am creating a virtual list control that resides inside of a static
box, that sits on a panel.

Thanks in advance,

John

class InvoiceDetailsPanel(wx.Panel):
    def __init__(self, parent):
        wx.Panel.__init__(self, parent, -1)

        tID = wx.NewId()
        self.product_list = wx.ListCtrl( self, tID, pos=(-1,-1),
size=(400, -1), style=wx.LC_REPORT | wx.LC_VIRTUAL | wx.LC_VRULES |
wx.BORDER_NONE )

        # Creating the Box
        box = wx.StaticBox(self, -1, "Ordered Items")
        bsizer = wx.StaticBoxSizer(box, wx.HORIZONTAL)

        self.parent = parent

        # Create the sizer and place my controls within it
        gbs = wx.GridBagSizer(5, 5)

        # for normal, simple columns, you can add them like this:
        self.product_list.InsertColumn(0, "Qty", wx.LIST_FORMAT_RIGHT )
        self.product_list.InsertColumn(1, "Item #", wx.LIST_FORMAT_CENTER)
        self.product_list.InsertColumn(2, "Desc", wx.LIST_FORMAT_LEFT)
        self.product_list.InsertColumn(3, "Total",wx.LIST_FORMAT_RIGHT)
        self.product_list.SetColumnWidth(0, 40)
        self.product_list.SetColumnWidth(1, 80)
        self.product_list.SetColumnWidth(2, 210)
        self.product_list.SetColumnWidth(3, 70)

        gbs.Add( self.product_list, (0,0), (1,1), flag=wx.EXPAND )

        gbs.AddGrowableRow(0)
        gbs.AddGrowableCol(0)

        bsizer.Add(gbs, 1, wx.TOP|wx.LEFT|wx.EXPAND, 0)
        
        border = wx.BoxSizer()
        border.Add(bsizer, 1, wx.EXPAND|wx.ALL, 3)
        self.SetSizer(border)

        self.product_list.SetItemCount( 25 )

    def OnGetItemText(self, item, col):
        print "OnGetItemText"
        return "Item %d, column %d" % (item, col)

    def OnGetItemImage(self, item):
        print "OnGetItemImage"
        return -1

    def OnGetItemAttr(self, item):
        print "OnGetItemAttr"
        return None

Hi John,

You need to subclass the wxListCtrl and put the OnGetItem methods in there.
You've added these methods to a wxPanel which won't be queried for items for
the list control. Other than that the code looks fine.

Regards,

Steven

···

-----Original Message-----
From: John W [mailto:jmw136@gmail.com]
Sent: Wednesday, 17 August 2005 12:23 PM
To: wxPython-users@lists.wxwidgets.org
Subject: [wxPython-users] Virtual List Control not getting Callbacks

Hello,

I am trying to use a virtual list, but I am not getting the callbacks to
populate the fields. I basically end up with an empty virtural list
control.

Below is my code that creates it.

I am creating a virtual list control that resides inside of a static box,
that sits on a panel.

Thanks in advance,

John

class InvoiceDetailsPanel(wx.Panel):
    def __init__(self, parent):
        wx.Panel.__init__(self, parent, -1)

        tID = wx.NewId()
        self.product_list = wx.ListCtrl( self, tID, pos=(-1,-1), size=(400,
-1), style=wx.LC_REPORT | wx.LC_VIRTUAL | wx.LC_VRULES | wx.BORDER_NONE )

        # Creating the Box
        box = wx.StaticBox(self, -1, "Ordered Items")
        bsizer = wx.StaticBoxSizer(box, wx.HORIZONTAL)

        self.parent = parent

        # Create the sizer and place my controls within it
        gbs = wx.GridBagSizer(5, 5)

        # for normal, simple columns, you can add them like this:
        self.product_list.InsertColumn(0, "Qty", wx.LIST_FORMAT_RIGHT )
        self.product_list.InsertColumn(1, "Item #", wx.LIST_FORMAT_CENTER)
        self.product_list.InsertColumn(2, "Desc", wx.LIST_FORMAT_LEFT)
        self.product_list.InsertColumn(3, "Total",wx.LIST_FORMAT_RIGHT)
        self.product_list.SetColumnWidth(0, 40)
        self.product_list.SetColumnWidth(1, 80)
        self.product_list.SetColumnWidth(2, 210)
        self.product_list.SetColumnWidth(3, 70)

        gbs.Add( self.product_list, (0,0), (1,1), flag=wx.EXPAND )

        gbs.AddGrowableRow(0)
        gbs.AddGrowableCol(0)

        bsizer.Add(gbs, 1, wx.TOP|wx.LEFT|wx.EXPAND, 0)
        
        border = wx.BoxSizer()
        border.Add(bsizer, 1, wx.EXPAND|wx.ALL, 3)
        self.SetSizer(border)

        self.product_list.SetItemCount( 25 )

    def OnGetItemText(self, item, col):
        print "OnGetItemText"
        return "Item %d, column %d" % (item, col)

    def OnGetItemImage(self, item):
        print "OnGetItemImage"
        return -1

    def OnGetItemAttr(self, item):
        print "OnGetItemAttr"
        return None

---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwidgets.org
For additional commands, e-mail: wxPython-users-help@lists.wxwidgets.org