[pygtk] Making gtk.IconView sortable. Crashes at model.clear().

Osmo Maatta osmoma at gmail.com
Thu Feb 25 01:03:03 WST 2010

Ok, the case is now solved.

I made the model too complicated.
I need only to create gtk.ListStore() and that's it. There is no need to 
go via model_sort.

  model_sort = gtk.TreeModelSort(model)  

This works really well:

        model = gtk.ListStore(gobject.TYPE_STRING, # Filename
                      gtk.gdk.Pixbuf,  # Icon image
                      gobject.TYPE_FLOAT, # File date
                      gobject.TYPE_INT) # File size



        # Make iconview sortable

        # Compare function is not actually needed. The default (internal 
cmp) function is good enough.
        # model.set_sort_func(COL_THUMB_FILENAME, 
        # model.set_sort_func(COL_THUMB_FILESIZE, 
        # model.set_sort_func(COL_THUMB_FILEDATE, 

        # Set default sort order
        model.set_sort_column_id(COL_THUMB_FILESIZE, gtk.SORT_ASCENDING)
Here is a fully functional test code: 
It rocks!

   Osmo (Moma) Antero M
   Grønland, Norway

Osmo Maatta wrote:
> Hello,
> I have a small application that shows thumbnail-images in a 
> gtk.IconView widget.
> The thumbnails are sortable on filename, file size and date. The 
> sorting seems to work fine.
> But the program crashes when I try to reload the thumbnails.
> Here is a picture of the application.
> http://bildr.no/view/595635
> When I press the [Reload thumbnails] button 2'nd time, the program 
> crashes with "Segmentation fault". 
> No other error messages appear.
> The crash happens at self.clear_display() function. It simply finds 
> the model/ListStore and clears it.
> model_sort = self.get_model()
> model = model_sort.get_model()
> model.clear()
> Can you help me to spot the error.
> The first version was un-sortable and it worked very well. But I 
> really want to make it sortable.
> Here is a test-code: http://www.futuredesktop.com/tmp/Test6.zip
> My system is Ubuntu Linux 9.10, 64bit.
> -----
> Most kindly
>   Moma Antero

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.daa.com.au/pipermail/pygtk/attachments/20100224/0d28c232/attachment.htm 

More information about the pygtk mailing list