views:

60

answers:

2

Hi everybody.

I am working on a gtk+ application written in python. I obviously use pygtk. My application is about collections of videos. It's a kind of F-spo or picasa, but for video.

As you can see in these two apps, you have a central area where you can see all of your photos with tag thumbnails under.

In my app, I want to implement the same kinf of view. For now I simply use this :

a gtk.Table containing a Vbox, inside the vbox a pixbuf (my video thumbnail) and a hbox, and inside the hbox, as many pixbuf as tags

It's working but it's ugly and It seems like It's not the better solution.

Looking deeply in the docs, I have found two widgets near my neeeds : IconView and TreeView

But IconView can only display one pixbuf per "row" and TreeView don't display as a grid like IconView.

So my question is : Here is a way to display a TreeView like an IconView (in a grid) ? How would you implement the F-spot way of arranging photos and tags under ? Thanks ;)

A: 

IconView is what you need. In the ListStore every row represent just one pixbuf but the IconView adjusts the images in a grid. Here a small example, launch it with the image files you want to show as arguments, for example:

python example.py /usr/share/icons/hicolor/16x16/apps/*

.

import sys
import gtk


store = gtk.ListStore(gtk.gdk.Pixbuf)
iv = gtk.IconView(store)
iv.set_pixbuf_column(0)
for arg in sys.argv[1:]:
    pixbuf = gtk.gdk.pixbuf_new_from_file(arg)
    store.append((pixbuf, ))

w = gtk.Window()
w.connect('destroy', lambda w: gtk.main_quit())
sw = gtk.ScrolledWindow()
w.add(sw)
sw.add(iv)
w.show_all()
gtk.main()
mg
perhaps I don't explain myself clearly enough : I am able tu render my videos thumbnail in an IconView already but I am not able to render in the same cell my video thumbnail and tag thumbnail relative to it. For a better explanation, you can just look at f-spot ui. This is the reason why I am looking for treemodel/treeview where you can define parents and childs.parents for my video thumbnail, child for every tag thumbnail attached to it.Unfortunately, treeview cant display as a grid like IconView
boblefrag
I'm sorry but i cannot what tag thumbnail is. Can you better explain it? Isn't it a label for the thumbnail?
mg
sure, take a grid, in each cell put a photo, this is my video thumbnail. Under each video thumbnail, put some smaller photo aligned in a row : this is my thumbnails tag.
boblefrag
Ok, i tried f-spot and it extends `gtk.Layout` to implements it's iconview. If don't want to follow the same road, the simplest way it comes in my mind is to dynamically create a new image (with imagemagick) which contains the tag thumbnail and use the standard `gtk.IconView`.
mg
I thought of this too, with PIL, but, well, admit it, it smell bad ... For now, I stick with text-tag and no thumbnails tag. When I will feel comfortable enough with pytgk, I'll try to hack this.What I'd like to do, but I don't know how is to take the bobince idea and make a CellRenderer Layout wich can take gtk.Hbox().
boblefrag
A: 

The best approach is either to stick with a table and reimplement selections or Use a custom version of IconView with a custom cellrenderer wich can take gtk.HBox().

Some guidelines about custom cellrenderer are :

http://faq.pygtk.org/index.py?req=show&file=faq13.045.htp

http://faq.pygtk.org/index.py?req=show&file=faq13.056.htp

a discuss occured on pygtk mailing list :

htp://old.nabble.com/Drawing-widgets-in-a-custom-cellrenderer-td14207692.html

WWWalter make a sample code : http://www.translate.org.za/blogs/walter/en/content/conquering-cellrendererwidget

According to Ruben Vermeersch, f-pot use a modified version of IconView. Code can be found here : http://git.gnome.org/browse/f-spot/?h=icon-view-cleanup

boblefrag