ListCtrl not updating

I am trying to use a ListCtrl widget in wxPython 2.4.2.1
which gets updated when the wx.EVT_IDLE event is processed.

The OnIdle event function I created is called, the new item
is added to the ListCtrl widget, and in code I can verify
the item is there....but no text is ever displayed in the
ListCtrl widget. The vertical scroll bar even becomes
visible when enough items have been added.

If I update the ListCtrl widget from a direct button click
instead of on idle events then text is displayed as
expected.

Anyone have a solution to this? Unfortunately upgrading to
a newer version of wxPython is not possible.

Below is the relevant bits of code.

--David

    def OnInit(self):
        ...
        self.listBox = wx.ListCtrl(self, -1,
                style = wx.LC_REPORT
                        > wx.LC_SINGLE_SEL
                        > wx.LC_HRULES
                        > wx.LC_VRULES
                        > wx.SUNKEN_BORDER,
                size = (485, 450))
        wx.EVT_IDLE(self.listBox, self.OnIndexBoxIdle)
        self.listBox.InsertColumn(0, "Type")
        self.listBox.InsertColumn(1, "Log File Time")
        self.listBox.InsertColumn(2, "Packet Time")
        self.listBox.InsertColumn(3, "AppID")
        self.listBox.SetColumnWidth(0, 100)
        self.listBox.SetColumnWidth(1, 160)
        self.listBox.SetColumnWidth(2, 160)
        self.listBox.SetColumnWidth(3, 50)
    #end def OnIndexBoxIdle

    ...

    def OnIndexBoxIdle(self, evt):
        if len(self.__newData) > 0:
            # self.__newData gets populated with items to
            # add to self.listBox
            data = self.__newData.pop(0)

            item = self.listBox.GetItemCount()

            self.listBox.InsertStringItem(item, data['type'])
            self.listBox.SetStringItem(item, 1, str(data['time']))

            ptime = self.__reader.GetSendTime(data['offset'])
            if ptime: self.listBox.SetStringItem(item, 2, str(ptime))
            else : self.listBox.SetStringItem(item, 2, "")

            self.listBox.SetStringItem(item, 3, str(data['appid']))

            self.listBox.EnsureVisible(item)
        #end if
    #end def OnIndexBoxIdle

David Morris wrote:

I am trying to use a ListCtrl widget in wxPython 2.4.2.1
which gets updated when the wx.EVT_IDLE event is processed.

The OnIdle event function I created is called, the new item
is added to the ListCtrl widget, and in code I can verify
the item is there....but no text is ever displayed in the
ListCtrl widget. The vertical scroll bar even becomes
visible when enough items have been added.

If I update the ListCtrl widget from a direct button click
instead of on idle events then text is displayed as
expected.

Anyone have a solution to this? Unfortunately upgrading to
a newer version of wxPython is not possible.

Have you tried calling self.listBox.Refresh()?

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

I did try that and it changed nothing. I tried just about
everything I could think of to force a refresh and nothing
worked.

I did, however, stumble on a workaround: I set the EVT_IDLE
event on the parent of the ListCtrl widget and the data
displayed as expected.

I'll try and run some tests on a more recent version of
wxPython at some point to see if this bug still exists or
has been taken care of at some point.

--David

···

On Sat, Mar 26, 2005 at 12:55:51PM -0800, Robin Dunn wrote:

David Morris wrote:
>The OnIdle event function I created is called, the new
>item is added to the ListCtrl widget, and in code I can
>verify the item is there....but no text is ever displayed
>in the ListCtrl widget. The vertical scroll bar even
>becomes visible when enough items have been added.

Have you tried calling self.listBox.Refresh()?

David Morris wrote:

···

On Sat, Mar 26, 2005 at 12:55:51PM -0800, Robin Dunn wrote:

David Morris wrote:

The OnIdle event function I created is called, the new
item is added to the ListCtrl widget, and in code I can
verify the item is there....but no text is ever displayed
in the ListCtrl widget. The vertical scroll bar even
becomes visible when enough items have been added.

Have you tried calling self.listBox.Refresh()?

I did try that and it changed nothing. I tried just about
everything I could think of to force a refresh and nothing
worked.

I did, however, stumble on a workaround: I set the EVT_IDLE
event on the parent of the ListCtrl widget and the data
displayed as expected.

Ah, I think I know what it is. Are you using a wxGTK build? IIRC there are some things that are done in idle time for that version of the wxListCtrl and since you didn't call evt.Skip then the built-in EVT_IDLE handler didn't get called. try doing that and see if it makes it work.

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!