AddItems in ListCtrl at once possible?

I wondered whether there is a possibilty to add items at once (would it
bring a good deal of performance)

instead of:
for i in items:
  InsertStringItem, SetStringItem, SetItemData

to cut short with InsertItems(i), where the listctrl separates to i[0],
i[1], ...

Hi,

···

On Wed, Aug 4, 2010 at 5:16 PM, FranzSt franz.steinhaeusler@gmx.at wrote:

I wondered whether there is a possibilty to add items at once (would it

bring a good deal of performance)

instead of:

for i in items:

InsertStringItem, SetStringItem, SetItemData

to cut short with InsertItems(i), where the listctrl separates to i[0],

i[1], …

ObjectListView has something like this. And you could use a VirtualList with the LC_VIRTUAL style flag that would update in a completely different way. See the wxPython demo for an example of the latter.

Mike Driscoll

Blog: http://blog.pythonlibrary.org

Mike Driscoll wrote:

Hi,

I wondered whether there is a possibilty to add items at once (would it
bring a good deal of performance)

instead of:
for i in items:
InsertStringItem, SetStringItem, SetItemData

to cut short with InsertItems(i), where the listctrl separates to i[0],
i[1], ...

ObjectListView has something like this. And you could use a VirtualList with
the LC_VIRTUAL style flag that would update in a completely different way.
See the wxPython demo for an example of the latter.

Aha, thanks Mike. I will take a look at this. When it does't result in a
significant performance win (in list with a lot of entries), then it
doesn't matter so much.

···

On Wed, Aug 4, 2010 at 5:16 PM, FranzSt <franz.steinhaeusler@gmx.at> wrote:

wx.ListCtrl has this helper function added to it:

     def Append(self, entry):
         '''Append an item to the list control. The entry parameter should be a
            sequence with an item for each column'''
         if len(entry):
             if wx.USE_UNICODE:
                 cvtfunc = unicode
             else:
                 cvtfunc = str
             pos = self.GetItemCount()
             self.InsertStringItem(pos, cvtfunc(entry[0]))
             for i in range(1, len(entry)):
                 self.SetStringItem(pos, i, cvtfunc(entry[i]))
             return pos

A trivial implementation of what you want could be implemented like this:

     def AppendItems(self, items):
         for item in items:
             self.Append(item)

···

On 8/4/10 3:16 PM, FranzSt wrote:

I wondered whether there is a possibilty to add items at once (would it
bring a good deal of performance)

instead of:
for i in items:
   InsertStringItem, SetStringItem, SetItemData

to cut short with InsertItems(i), where the listctrl separates to i[0],
i[1], ...

--
Robin Dunn
Software Craftsman