Virtual ListCtrl : An example with a question

Hello All,

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.

Cheers!!

Dermot.

simple_virtual_list.py (2.07 KB)

Dermot Doran wrote:

Hello All,

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?

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.

···

--
Robin Dunn
Software Craftsman

Thanks very much for reviewing this and providing advice, Robin.

Cheers!!

Dermot.

···

On 16 March 2013 03:03, Robin Dunn robin@alldunn.com wrote:

Dermot Doran wrote:

Hello All,

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?

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.

Robin Dunn

Software Craftsman

http://wxPython.org

You received this message because you are subscribed to the Google Groups “wxPython-users” group.

To unsubscribe from this group and stop receiving emails from it, send an email to wxpython-users+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/groups/opt_out.