Hi,
I'm trying to set a custom function to render the images on a
gtk.IconView, instead of the usual "gtk.IconView.set_pixbuf_column()"
method.
To do it, I'm using "set_cell_data_func" method that gtk.IconView
inherits from gtk.CellLayout [1] and [2].
It doesn't work, reporting next error.
"""
iconview.py:19: GtkWarning:
gtk_icon_view_cell_layout_set_cell_data_func: assertion `info != NULL'
failed
self.set_cell_data_func(crpb, self.cell_pixbuf_func)
"""
See the attached example.
Any idea?
I succesfully use "set_cell_data_func" method with treeviews, so the
issue comes within gtk.IconView...
My purpose is to render the pixbufs according to some "size"
preference so images are shown smaller or bigger.
The option of filling the store each time "size" preference is changed
is not a valid solution as there a lot of rows there so it would be
very slow.
Thanks,
Iñigo Serna
[1] http://www.pygtk.org/docs/pygtk/class-gtkiconview.html
[2]
http://www.pygtk.org/docs/pygtk/class-gtkcelllayout.html#method-gtkcelllayout--set-cell-data-func
import gtk
class IconView(gtk.IconView):
def __init__(self):
super(IconView, self).__init__()
# populate model
model = gtk.ListStore(str, gtk.gdk.Pixbuf)
for attr in dir(gtk):
if attr.startswith('STOCK_'):
stock_id = getattr(gtk, attr)
pixbuf = self.render_icon(stock_id,
size=gtk.ICON_SIZE_BUTTON, detail=None)
if pixbuf:
model.append(['gtk.%s' % attr, pixbuf])
# drawing section
self.set_text_column(0)
# self.set_pixbuf_column(1) # use a function to fill the image
crpb = gtk.CellRendererPixbuf()
self.set_cell_data_func(crpb, self.cell_pixbuf_func)
# set model
self.set_model(model)
def cell_pixbuf_func(self, celllayout, cell, model, iter, user_data):
print self, celllayout, cell, model, iter, user_data
cell.set_property('pixbuf', model[0][1])
win = gtk.Window()
win.set_default_size(400, 400)
win.connect("destroy", lambda w: gtk.main_quit())
view = IconView()
sw = gtk.ScrolledWindow()
sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
sw.add_with_viewport(view)
win.add(sw)
win.show_all()
gtk.main()
_______________________________________________
pygtk mailing list [email protected]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://faq.pygtk.org/