I just invested a bit of time learning about the virtual ListCtrl, and I’m very glad I did. However, I’m looking for advice on how the control can be re-used to display different content.
My simple example includes a method in the VirtualListCtrl class that loads a new file into the control as follows:
def load_file(self, filename):
fd = open(filename)
self.lines = fd.readlines()
self.Select(0)
fd.close()
My question is: Is this all you have to do in order to “reload” the control?
The example is attached and does work, but I’m concerned that I’m making a fatal assumption that will come back to bite me later.
I’m also hopeful that this example might assist others who found the wxPython Demo version just a bit too involved as a first encounter with this lovely control.
I just invested a bit of time learning about the virtual ListCtrl, and
I'm very glad I did. However, I'm looking for advice on how the control
can be re-used to display different content.
My simple example includes a method in the VirtualListCtrl class that
loads a new file into the control as follows:
My question is: Is this all you have to do in order to "reload" the
control?
You also need to adjust the item count, like you did when you first load the content. I would just move that call to SetItemCount into the load_files method since it is being called from open_files anyway.
The example is attached and does work, but I'm concerned that I'm making
a fatal assumption that will come back to bite me later.
Nope. Other than keeping the item count accurate your approach is good. If you ever have more items than can comfortably fit in memory at the same time then you may want to look into using the CACHE_HINT event and implement some scheme to keep a subset of items in memory and fetch more when the cache event is sent. But you probably don't need to worry about that until you've got a few hundred thousand items to deal with.
I'm also hopeful that this example might assist others who found the
wxPython Demo version just a bit too involved as a first encounter with
this lovely control.
You should put it on the wiki as a recipe and commentary that provides the details that you found confusing at first, or other things that you've learned about it along the way.
My question is: Is this all you have to do in order to “reload” the
control?
You also need to adjust the item count, like you did when you first load the content. I would just move that call to SetItemCount into the load_files method since it is being called from open_files anyway.
The example is attached and does work, but I’m concerned that I’m making
a fatal assumption that will come back to bite me later.
Nope. Other than keeping the item count accurate your approach is good. If you ever have more items than can comfortably fit in memory at the same time then you may want to look into using the CACHE_HINT event and implement some scheme to keep a subset of items in memory and fetch more when the cache event is sent. But you probably don’t need to worry about that until you’ve got a few hundred thousand items to deal with.
I’m also hopeful that this example might assist others who found the
wxPython Demo version just a bit too involved as a first encounter with
this lovely control.
You should put it on the wiki as a recipe and commentary that provides the details that you found confusing at first, or other things that you’ve learned about it along the way.