#!/usr/bin/env python2.5
# The purpose of this test is to demonstrate the effects of various column
# property settings.

import gtk
import gobject

#CASE = 0 # Drag the right column header right.  You will increase the width of
         # the main window.  Why doesn't the third column get narrower?  Now drag
         # the right column header to the left.  The width of the third column
         # does not change, but the width of the second column does.  That
         # behavior is very strange.
CASE = 2 # This is the case that should have worked, but it is not possible to
         # get the width of the third column less than 80 even though the min
         # width is 20.

class ColumnWidth(object):
    def __init__(self):
        self.window = gtk.Window()
        self.window.connect("destroy", gtk.main_quit)

        liststore = gtk.ListStore(*(gobject.TYPE_STRING,) * 3)

        treeview = gtk.TreeView(liststore)
        treeview.set_headers_visible(True)

        for i in range(3):
            cell = gtk.CellRendererText()
            col = gtk.TreeViewColumn('%s' % i, cell, text=i)
            col.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
            col.set_fixed_width(80)
            col.set_min_width(20)
            col.set_max_width(-1)
            col.set_resizable(True)
            col.set_expand(False)
            treeview.append_column(col)
        col.set_resizable(False)
        if True: # set to False to explore the CASEs above
            # This is the code that worked.
            col.set_sizing(gtk.TREE_VIEW_COLUMN_AUTOSIZE)
        else:
            # It is not possible to get the desired behavior using set_expand.
            treeview.get_column(CASE).set_expand(True)

        self.vbox = gtk.VBox()
        self.vbox.pack_start(treeview, expand=True, fill=True)
        self.window.add(self.vbox)
        self.window.show_all()

        for i in range(10):
            liststore.append(["%d" % i] * 3)

    def run(self):
        self.window.show_all()
        gtk.main()

app = ColumnWidth()
app.run()