Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
385 views
in Technique[技术] by (71.8m points)

python - Is this possible to draw GtkTreeView listed like GtkIconView?

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-spot 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.

My question: Is there 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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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()

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...