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()