Refreshing wxListCtrl

Hi-

I'm using wxPython 2.4.0.2 on Debian Woody I've included a small toy
example which includes a "virtual" wxListCtrl i.e. which uses
wxLC_VIRTUAL.

The example is written so that whenever a user double-clicks or hits
return in the list VirtualListCtrl.update() is run. Everytime,
VirtualListCtrl.update() is run it populates VirtualListCtrl.data with
a new random data set and tries to refresh the list control.

The problem that I'm running into is that the list control doesn't
seem to be refreshing, i.e. when I double click, the data in all the
cells doesn't change. Maybe I'm doing something wrong?

Many thanks for any suggestions!

Dave

from wxPython.wx import *

import whrandom

ID_LIST = wxNewId()

def getRandomString():
    s = ""
    for i in range(0,5):
        s = s + chr(whrandom.randint(97,122)) #range 97 to 122 corresponds to ASCII 'a' to 'z'
    return s

class VirtualListCtrl(wxListCtrl):
    def __init__(self, aparent, aid):
        wxListCtrl. __init__(self, aparent, aid, style=wxLC_REPORT|wxLC_VIRTUAL|wxLC_HRULES|wxLC_VRULES)
        self.InsertColumn(0, "Integer")
        self.InsertColumn(1, "Positive Float")
        self.InsertColumn(2, "Negative Float")
        self.InsertColumn(3, "String")
        self.SetColumnWidth(0, wxLIST_AUTOSIZE_USEHEADER)
        self.SetColumnWidth(1, wxLIST_AUTOSIZE)
        self.SetColumnWidth(2, wxLIST_AUTOSIZE)
        self.SetColumnWidth(3, wxLIST_AUTOSIZE)
        self.numberItems = 25
        self.update()
        self.SetItemCount(self.numberItems)

    def OnGetItemText(self, aitem, acolumn):
        return self.data[aitem][acolumn]

    def OnGetItemImage(self, item):
        return -1.

    def update(self):
        self.data = []
        for i in range(0,self.numberItems):
            tempTuple = ( whrandom.randint(0,100), whrandom.random(), whrandom.random(), getRandomString() )
            self.data.append(tempTuple)
        self.Refresh()

class VirtualListCtrlExample(wxApp):
    def OnInit(self):
        frame = wxFrame(NULL, -1, "Sort Example")
        self.list=VirtualListCtrl(frame, ID_LIST)
        self.list.Show(true)
        EVT_LIST_ITEM_ACTIVATED(self, ID_LIST, self.OnItemActivated)
        frame.Show(true)
        self.SetTopWindow(frame)
        return true

    def OnItemActivated(self, aevent):
        self.list.update()

app = VirtualListCtrlExample(0)
app.MainLoop()

David J. Neu wrote:

Hi-

I'm using wxPython 2.4.0.2 on Debian Woody I've included a small toy
example which includes a "virtual" wxListCtrl i.e. which uses
wxLC_VIRTUAL.

The example is written so that whenever a user double-clicks or hits
return in the list VirtualListCtrl.update() is run. Everytime,
VirtualListCtrl.update() is run it populates VirtualListCtrl.data with
a new random data set and tries to refresh the list control.

The problem that I'm running into is that the list control doesn't
seem to be refreshing, i.e. when I double click, the data in all the
cells doesn't change. Maybe I'm doing something wrong?

Many thanks for any suggestions!

Instead of just calling Refresh you should do something like this:

         if self.GetItemCount():
             itemFrom = self.GetTopItem()
             itemTo = self.GetTopItem()+1 + self.GetCountPerPage()
             itemTo = min(itemTo, self.GetItemCount()-1)
             self.RefreshItems(itemFrom, itemTo)

···

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

Robin,

That works perfectly!

Thanks very much,
Dave

···

On Wed, Jun 25, 2003 at 11:22:42AM -0700, Robin Dunn wrote:

David J. Neu wrote:
>Hi-
>
>I'm using wxPython 2.4.0.2 on Debian Woody I've included a small toy
>example which includes a "virtual" wxListCtrl i.e. which uses
>wxLC_VIRTUAL.
>
>The example is written so that whenever a user double-clicks or hits
>return in the list VirtualListCtrl.update() is run. Everytime,
>VirtualListCtrl.update() is run it populates VirtualListCtrl.data with
>a new random data set and tries to refresh the list control.
>
>The problem that I'm running into is that the list control doesn't
>seem to be refreshing, i.e. when I double click, the data in all the
>cells doesn't change. Maybe I'm doing something wrong?
>
>Many thanks for any suggestions!
>

Instead of just calling Refresh you should do something like this:

        if self.GetItemCount():
            itemFrom = self.GetTopItem()
            itemTo = self.GetTopItem()+1 + self.GetCountPerPage()
            itemTo = min(itemTo, self.GetItemCount()-1)
            self.RefreshItems(itemFrom, itemTo)

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

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