Hari's Corner

Humour, comics, tech, law, software, reviews, essays, articles and HOWTOs intermingled with random philosophy now and then

Python Gtk HOWTO: cell rendering a Treeview created in Glade

Filed under: Tutorials and HOWTOs by Hari
Posted on Fri, May 21, 2010 at 14:11 IST (last updated: Tue, May 25, 2010 @ 08:25 IST)

In this series Next >
This is more for personal reference after struggling for half an hour with Python and Glade/GtkBuilder to figure out how to add a gtk.CellRenderer to a gtk.TreeViewColumn for a tree view that was created in Glade.

The steps are not obvious because most of the tutorials out there are for pure GTK code and assumes all the objects are created programmatically and not from the GtkBuilder XML file.

Simply the steps are:

# Get the TreeViewColumn object associated with the tree view - self.ui is a gtk.Builder object
# in this case the index is 0
col = self.ui.get_object ("tree_view").get_column (0)
# Create a text cell renderer
cell = gtk.CellRendererText ()
# Add the cell renderer to the TreeViewColumn
col.pack_start (cell)
# Attributes for the column - make it display text of column 0
# from the model
col.add_attribute (cell, "text", 0)

It's all a bit confusing and irritating to have to deal with all this and I personally think that GTK's treeview control is a royal pain in the rear for programmers, especially when used in conjunction with Glade.

Half the stuff is done in the Glade interface and the rest programmatically. This is a mess and should be a high priority for the GTK programmers to rectify: either improve Glade or simplify gtk.TreeView.

In this series

2 comment(s)

  1. You can add the cell renderer for the tree view in the Glade. We can add cell renderer for the GtkComboBox directly in the Glade. We can't edit it for the GtkTreeView directly. But we can copy the source code of the GtkComboBox's cell render to the GtkTreeView and the Glade recognized them.

    Comment by xingmin (visitor) on Sun, Aug 29, 2010 @ 06:46 IST #
  2. Thanks :) this was exactly what I was after. I agree this treeview is seriously annoying to deal with

    Comment by Nick (visitor) on Mon, May 7, 2012 @ 20:30 IST #

Comments closed

The blog owner has closed further commenting on this entry.