[pygtk] [CellRenderer] - Put icons in the TreeView
Demidov Andrey
andrey.demidov at gmail.com
Mon Nov 10 16:22:17 WST 2008
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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.daa.com.au/pipermail/pygtk/attachments/20081110/d42a43c0/attachment.htm
More information about the pygtk
mailing list