[pygtk] [CellRenderer] - Put icons in the TreeView

Demidov Andrey andrey.demidov at gmail.com
Tue Nov 11 23:59:41 WST 2008


Thank you for the link and the explanation.

I think there is a little error in second code block:

-  rendererer = gtk.CellRendererPixbuf()
+  renderer = gtk.CellRendererPixbuf()
  column.pack_start(renderer, expand=False)
  column.add_attribute(renderer, 'pixbuf', COL_PIXBUF)

I cannot change that page so if somebody have permssions to edit this page
please fix it.

Andrey


On Mon, Nov 10, 2008 at 1:55 PM, Thomas Mills Hinkle <tmhinkle at gmail.com>wrote:

> You're using the "stock=" attribute of the CellRendererPixbuf -- that's
> designed to grab a stock icon. You want to be using the pixbuf= attribute.
> Assuming you don't want to mix and match (that you just want to use
> pixbufs), changing stock to pixbuf in the code below should get you what you
> want (you'll see that the "stock" items will break and your items will
> work).
>
> That said, the code below looks a little fancy for what you need -- you
> might want to look at:
> http://faq.pygtk.org/index.py?req=show&file=faq13.006.htp
>
> Tom
>
> On Mon, Nov 10, 2008 at 2:22 AM, Demidov Andrey <andrey.demidov at gmail.com>wrote:
>
>> Hi,
>>
>> I want to put my icons in the treeview cell.   I have found this example
>> code (http://www.pygtk.org/pygtk2tutorial/examples/treeviewcolumn.py) and
>> tried to change it:
>>
>> #!/usr/bin/env python
>>
>> import pygtk
>> pygtk.require('2.0')
>> import gtk
>>
>> class TreeViewColumnExample:
>>
>>     # close the window and quit
>>     def delete_event(self, widget, event, data=None):
>>         gtk.main_quit()
>>         return False
>>
>>     def __init__(self):
>>         # Create a new window
>>         self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
>>         self.window.connect("delete_event", self.delete_event)
>>         self.liststore = gtk.ListStore(str, str, str, 'gboolean')
>>         self.treeview = gtk.TreeView(self.liststore)
>>         self.tvcolumn = gtk.TreeViewColumn('Pixbuf and Text')
>>
>>         pixbuf =
>> gtk.gdk.pixbuf_new_from_file('arch.png')
>> # <-- my code
>>         self.liststore.append(['Open', gtk.STOCK_OPEN, 'Open a File',
>> True])
>>         self.liststore.append(['New', pixbuf, 'New File',
>> True])                                 # <-- my code
>>         self.liststore.append(['Print', gtk.STOCK_PRINT, 'Print File',
>> False])
>>
>>         self.treeview.append_column(self.tvcolumn)
>>
>>         # create a CellRenderers to render the data
>>         self.cellpb = gtk.CellRendererPixbuf()
>>         self.cell = gtk.CellRendererText()
>>
>>         # add the cells to the columns - 2 in the first
>>         self.tvcolumn.pack_start(self.cellpb, False)
>>         self.tvcolumn.pack_start(self.cell, True)
>>
>>         self.tvcolumn.set_attributes(self.cellpb, stock_id=1)
>>         self.tvcolumn.set_attributes(self.cell, text=0)
>>
>>     self.treeview.set_search_column(0)
>>         self.tvcolumn.set_sort_column_id(0)
>>         self.treeview.set_reorderable(True)
>>         self.window.add(self.treeview)
>>         self.window.show_all()
>>
>> def main():
>>     gtk.main()
>>
>> if __name__ == "__main__":
>>     tvcexample = TreeViewColumnExample()
>>     main()
>>
>> But it doesn't work.  How can I display the icon from file in TreeView?
>> And what is "stock"?  How can I put my icon in this "stock"?
>>
>> Thanks in advance,
>> Andrey
>>
>> _______________________________________________
>> pygtk mailing list   pygtk at daa.com.au
>> http://www.daa.com.au/mailman/listinfo/pygtk
>> Read the PyGTK FAQ: http://faq.pygtk.org/
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.daa.com.au/pipermail/pygtk/attachments/20081111/fb2ef00a/attachment.htm 


More information about the pygtk mailing list