segmentation fault in Virtual ListCtrl

Hello,

i have a problem with setting the ListItemAttr in a Virtual ListCtrl.
When i implement the OnGetItemAttr and do not return None but a
ListItemAttr then i get a segmentation fault. This happens in my
wxPython2.8.8.0 under ubuntu and wxPython 2.8.7.1 under Win32. The
SegFault does NOT occur under wxPython2.6.3.2 under ubuntu. I think it
is a bug.

Here is the code. when i run it, it closes immediately with a
segfault. Any ideas?

···

--------------------------------------------------------------------------
#!/usr/bin/env python
# -*- coding: iso-8859-15 -*-
# generated by wxGlade 0.6.3 on Fri May 29 13:45:51 2009

import wxversion
# wxversion.select('2.6')
import wx

# begin wxGlade: extracode
# end wxGlade

class MyVirtualListCtrl(wx.ListCtrl):

     def __init__(self, *args, **kwds):
          wx.ListCtrl.__init__(self, *args, **kwds)
          self.InsertColumn(0, 'Name', width = 300)
          self.SetItemCount(4)

     def OnGetItemAttr(self, index):
         txtclr = wx.NamedColour('black')
         bgclr = wx.NamedColour('white')
         attr = wx.ListItemAttr(txtclr, bgclr, wx.NORMAL_FONT)
         return attr

     def OnGetItemText(self, item, column):
         return 'hello'

class MyFrame(wx.Frame):
    def __init__(self, *args, **kwds):
        # begin wxGlade: MyFrame.__init__
        kwds["style"] = wx.DEFAULT_FRAME_STYLE
        wx.Frame.__init__(self, *args, **kwds)
        self.list_ctrl_1 = MyVirtualListCtrl(self, -1,
style=wx.LC_REPORT|wx.LC_VIRTUAL|wx.LC_HRULES|wx.LC_VRULES|
wx.SUNKEN_BORDER)

        self.__set_properties()
        self.__do_layout()
        # end wxGlade

    def __set_properties(self):
        # begin wxGlade: MyFrame.__set_properties
        self.SetTitle("frame_1")
        # end wxGlade

    def __do_layout(self):
        # begin wxGlade: MyFrame.__do_layout
        sizer_6 = wx.BoxSizer(wx.VERTICAL)
        sizer_6.Add(self.list_ctrl_1, 1, wx.EXPAND, 0)
        self.SetSizer(sizer_6)
        sizer_6.Fit(self)
        self.Layout()
        # end wxGlade

# end of class MyFrame

if __name__ == "__main__":
    app = wx.PySimpleApp(0)
    wx.InitAllImageHandlers()
    frame_1 = MyFrame(None, -1, "")
    app.SetTopWindow(frame_1)
    frame_1.Show()
    app.MainLoop()

-------------------------------------------------------------

terminator_user wrote:

Hello,

i have a problem with setting the ListItemAttr in a Virtual ListCtrl.
When i implement the OnGetItemAttr and do not return None but a
ListItemAttr then i get a segmentation fault. This happens in my
wxPython2.8.8.0 under ubuntu and wxPython 2.8.7.1 under Win32. The
SegFault does NOT occur under wxPython2.6.3.2 under ubuntu. I think it
is a bug.

Here is the code. when i run it, it closes immediately with a
segfault. Any ideas?

Hmm... I thought I had this fixed, but apparently not since I just duplicated the problem in the current release. You can work around the problem by holding a reference to the attr object. It doesn't have to be forever, just long enough for the attribute value to be returned and used by the listctrl.

      def OnGetItemAttr(self, index):
          txtclr = wx.NamedColour('black')
          bgclr = wx.NamedColour('white')
          self.attr = wx.ListItemAttr(txtclr, bgclr, wx.NORMAL_FONT)
          return self.attr

···

--
Robin Dunn
Software Craftsman

Hi Robin,

thank you for your workaround. This is good enough for the first time.
the thing is: in the meantime i have fallen into another segfault
which arises only in wxPython 2.8 *annoyed*

it has to do with drag and drop. I derived a class from
PyDataObjectSimple and passed an instance to a drop source object.
Then i called DoDragDrop and got the segfault. in wxpython 2.6 it
works fine.
maybe i will send an example later when i have localized the problem
better.

greets

Martin

···

On May 29, 7:12 pm, Robin Dunn <ro...@alldunn.com> wrote:

terminator_user wrote:
> Hello,

> i have a problem with setting the ListItemAttr in a Virtual ListCtrl.
> When i implement the OnGetItemAttr and do not return None but a
> ListItemAttr then i get a segmentation fault. This happens in my
> wxPython2.8.8.0 under ubuntu and wxPython 2.8.7.1 under Win32. The
> SegFault does NOT occur under wxPython2.6.3.2 under ubuntu. I think it
> is a bug.

> Here is the code. when i run it, it closes immediately with a
> segfault. Any ideas?

Hmm... I thought I had this fixed, but apparently not since I just
duplicated the problem in the current release. You can work around the
problem by holding a reference to the attr object. It doesn't have to
be forever, just long enough for the attribute value to be returned and
used by the listctrl.

  def OnGetItemAttr\(self, index\):
      txtclr = wx\.NamedColour\(&#39;black&#39;\)
      bgclr = wx\.NamedColour\(&#39;white&#39;\)
      self\.attr = wx\.ListItemAttr\(txtclr, bgclr, wx\.NORMAL\_FONT\)
      return self\.attr

--
Robin Dunn
Software Craftsmanhttp://wxPython.org