On 2010-07-13 3:48, Cornelius Kölbel wrote:
> Dear list,
>
> I got an array of dictionaries, that I want to add to a GTKListStore,
> that is displayed an a treeview.
>
> This is very slow. I already replaced the liststore.append by
> liststore.insert, which is much much faster.
> But still, filling the 10.000 values takes about 50 seconds.
>
> Is there any cool mapping function, to push the array to the liststore?
> I used a for loop to iterate over the array...
> I also tried while an to pop the array elements...
>
> It is something like this:
>
> data: array of dictionaries
>
> data = array( { 'v1' : 'something', 'v2': 'something else' } ,
>                { 'v1' : 'another',   'v2': 'something completely diff' }
>               )
>
>
> for d in data:
>     self.liststore.insert( 0, ( d.get("v1"), d.get("v2") ....))
>
>
> ...is there a better way than doing a for loop?
> ...or a way to not have to interate over the 10.000 dicts?
>
> ...or is there a cool reading on performance tuning pyton?

Some general ideas:
  - Make sure the store isn't being viewed when you insert data, that
    will slow it down.

  - Do attribute lookups outside big loops:

     append = self.liststore.append
     get = d.get
     for d in data:
         append(0, (get('v1'), get('v2'), ...))

  - Put the treeview into fixed height and width mode. Automatic sizing
    is the enemy of treeview performance. This only works if all your
    rows are the same height. The function calls you need are:
      gtk.TreeViewColumn.set_sizing
         with the gtk.TREE_VIEW_COLUMN_FIXED value
      gtk.TreeViewColumn.set_fixed_width
      gtk.TreeView.set_fixed_height_mode

  - If your list is large enough it may be worth subclassing
    gtk.TreeModel and overriding the required methods. It's complex, but
    it can avoid referencing all your data at tree build time, instead
    loading as the user scrolls.

  - Write it in C. Always valid, even if as a last resort.

-- 
Tim Evans
Applied Research Associates NZ
http://www.aranz.com/
_______________________________________________
pygtk mailing list   [email protected]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://faq.pygtk.org/

Reply via email to