Make stock gtk icons from your own images and pixbufs
If you want to set a cell to a pixmap, ok no problem, but what about setting individual liststore values to a pixmap? You can’t do set_value directly unless you’re using a gtk.STOCK_ image. Here’s a way around that little problem.
Make an icon factory
|
|
ifactory = gtk.IconFactory() ifactory.add_default() |
And register your image files as stock icons!
|
|
image = os.path.join(os.path.dirname(__file__), 'pic.png') ifactory.add('my_name', gtk.gdk.pixbuf_new_from_file(image)) gtk.stock_add([('fancy_name', 'label string', 0, 0, '')]) |
Now refer to the name you gave your icon wherever you used to use stock icons such as gtk.STOCK_YES
|
|
liststore.set_value(iter, column, 'fancy_name') |
There’s nothing stopping you from setting pixbuf properties on cells directly if you still need that ability. Just use the image the same as you did for the factory add.
I’ll open it with a size to force column uniformity using multiple files that might be different sizes.
|
|
image = os.path.join(os.path.dirname(__file__), 'pic.png') pic = gtk.gdk.pixbuf_new_from_file_at_size(image, 48, 48) cell.set_property('pixbuf', pic) |