Hi,

I have built up an app using glade-2 and it loads and runs fine using
gtk.glade. One of my widgets is a TreeView using a ListStore and I'm
having a bit of trouble figuring out how to make all the columns
expand.

Google hasn't turned up a solution and the PyGTK FAQ Entry 13.19
gives a hint as such:

   Another thing to note is that renderers use the normal GTK packing
   mechanism. If you want one renderer to expand and take up any extra
   space (or `compete' for it if more than one cell has expand=TRUE),
   pack it with expand=TRUE, and vice-versa.

I not sure how to perform the packing of the column so I can set
expand to TRUE.

Here's what I've got so far:

class ListView:
    def __init__ (self, view, model, hdrs, renderers, sel_cb):
        self.view = view
        view.set_model (model)

        view.set_headers_visible (gtk.TRUE)
        for i in xrange (len (hdrs)):
            # Set text to i+2 to skip over the PYOBJECT in column 0 of
            # the model and the BOOLEAN in column 1.
            col = gtk.TreeViewColumn (hdrs[i], renderers[i],
                                      text=i+2, editable=1)
            renderers[i].set_property ('xalign', 0.50)
            renderers[i].set_property ('font-desc', font_fixed)
            col.set_resizable (gtk.TRUE)
            col.set_alignment (0.50)

            # This is obviously wrong.
            col.pack_start (renderers[i], expand=gtk.TRUE)

            view.append_column (col)

        view.show()

        sel = view.get_selection ()
        sel.set_mode ('single')
        sel.connect ('changed', sel_cb)

Elsewhere, I define the following and pass them to the ListView init
method:

        types     = [ gobject.TYPE_STRING ] * 10
        renderers = [ gtk.CellRendererText () ] * 10
        hdrs      = [ 'Address', 'Name',
                      'Bit 7', 'Bit 6', 'Bit 5', 'Bit 4',
                      'Bit 3', 'Bit 2', 'Bit 1', 'Bit 0' ]

And the view is instantiated with this:

    def setup_treeview (self, widget_name, types, hdrs, renderers, sel_cb):
        model = ListModel (*types)
        view  = self.wTree.get_widget (widget_name)
        view = ListView (view, model.store, hdrs, renderers, sel_cb)

The problem code is:

            # This is obviously wrong.
            col.pack_start (renderers[i], expand=gtk.TRUE)

which generates quite a few of these:

(gui.py:26663): Gtk-CRITICAL **: file gtktreeviewcolumn.c: line 1234
(gtk_tree_view_column_pack_start): assertion `!
gtk_tree_view_column_get_cell_info (tree_column, cell)' failed

>From reading the docs, I kinda think that my call to col.pack_start()
is not the right approach as it seems to expect a specific cell, not a
renderer instance.

Just in cases it's of interest, here's how I'm adding my data to the
list store model:

   def insert_row (self, data):
        """Also adds the python object, 'data' to the store in the first
        column. Set the value of the boolean to TRUE so we can edit the
        cells later.
        """
        iter = self.store.append ()
        args = [0, data, 1, gtk.TRUE]
        for i in range (len (data)):
            args.extend ([i+2, data[i]])
        self.store.set (iter, *args)

I'm using the current 2.2.x gtk+ libs.

Any insight into how to do this is appreciated.


Thanks.

Ted Roth
_______________________________________________
pygtk mailing list   [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/

Reply via email to