Frage

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

War es hilfreich?

Lösung

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.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top