1

I want to display a 139 cols * 121 rows image map.

(The image size is 32*32 px)

I use a gtk.Iconview with a gtk.ListStore that I fill with gtk.gdk.Pixbuf, like this :

(the two dimensional graph list contains objects that contain the images path to display)

pixbuf_passage = gtk.gdk.pixbuf_new_from_xpm_data(xpmdata)
for row in graph :
    for col in row :
        pixbuf = gtk.gdk.pixbuf_new_from_file(col.img_base)

        if col.passage :
            pixbuf_passage.composite(pixbuf, 0, 0, pixbuf_passage.props.width, pixbuf_passage.props.height, 0, 0, 1.0, 1.0, gtk.gdk.INTERP_BILINEAR, 255)

        self.grid.listStore.append([pixbuf, tooltip])

My problem is that the image loading time can be quite long, depending on the computer's configuration :

  • ~20s for a Intel Core i7 with 4Gb RAM (which is acceptable)
  • ~160s for a AMD X2 4200+ with 4Gb RAM (which is too long)

Is there any way to speed up the image loading ? Perhaps the use of a gtk.Iconview isn't optimal here ?

Thanks

Loïc G.
  • 3,087
  • 3
  • 24
  • 36
  • 1
    There's a [related discussion](http://faq.pygtk.org/index.py?req=show&file=faq13.043.htp) in the PyGTK FAQ which you can try. If that doesn't help, you can probably implement some sort of on-demand loading (IIRC Rhythmbox (or was it Banshee?) does this), but I imagine it's not easy. – Johannes Sasongko Jan 03 '12 at 11:57
  • Which version of GTK are you using ? On which platform ? – liberforce Jan 03 '12 at 12:21
  • @liberforce : I use the 2.24.0 version of PyGTK and the 2.24.8 version of GTK, on Linux (x64) but there is the same effect on windows. – Loïc G. Jan 03 '12 at 17:58
  • @Johannes Sasongko : I always forget to go see the PyGTK FAQ which is a 'gold mine' though. I've just tested to freeze IconView updates and detach the model before adding the pixbuf. The loading takes now 5s, instead of 20s ! (I can't test now on the other machine but I guess I could hardly do better). Thanks ! Can you post your solution as an answer instead of comment so I'll can accept it ? – Loïc G. Jan 03 '12 at 18:24

1 Answers1

1

The PyGTK FAQ has a few tips for this. The most important seems to be that you should freeze the treeview/iconview and unset its model temporarily while adding a lot of entries.

treeview.freeze_child_notify()
treeview.set_model(None)

# Add rows to the model
# ...

treeview.set_model(model)
treeview.thaw_child_notify()

The trick using g_idle_add is also useful to add more responsiveness to the UI.

Johannes Sasongko
  • 4,178
  • 23
  • 34