Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Resizing gtk TreeView in HPaned problem

Tags:

python

pygtk

gtk

I have a treeview in the left side of an hpaned but when I try to move the bar to the left to make the treeview smaller than its automatic size instead of resizing the treeview it expands the entire program window to the right. Any ideas on how to fix this?

The relevant portions of the source are the following:

For the hpaned.

    self.vpan = gtk.VPaned()
    self.hpan = gtk.HPaned()
    self.vpan.show()
    self.hpan.show()

    self.vBox1.pack_end(self.hpan, True, True, 0)
    self.hpan.pack2(self.vpan,True, True)

And for the tree View.

    self.ftree = gtk.TreeStore(str,str,str)
    self.treefill(None, os.path.abspath(os.path.dirname(__file__)))

    self.tree = gtk.TreeView(self.ftree)
    self.tvcolumn = gtk.TreeViewColumn('Project')
    self.tree.append_column(self.tvcolumn)
    self.cellpb = gtk.CellRendererPixbuf()
    self.celltxt = gtk.CellRendererText()

    self.tvcolumn.pack_start(self.cellpb,False)
    self.tvcolumn.pack_start(self.celltxt,True)

    self.tvcolumn.set_attributes(self.cellpb, stock_id=0)
    self.tvcolumn.set_attributes(self.celltxt, text=1)
    self.tvcolumn.set_resizable(True)

    self.hpan.pack1(self.tree,True,True)
    self.tree.show()
like image 328
njvb Avatar asked Jan 21 '11 01:01

njvb


1 Answers

I was going to answer this question, and then I realized that my answer was a repeat of the user's answer. But, as he hasn't posted his resolution as an answer, I will anyway. (Below is what I would have posted if he hadn't figured it out.)

Expand and Fill seem to be causing a bit of a fight for space between the various objects in this box (as I'm assuming that all of your objects do this. I used to have the habit, too, but no problem.) In the PyGTK documentation, "Expand" is defined as

True if child is to be given extra space allocated to box. The extra space will be divided evenly between all children of box that use this option.

and "Fill" as:

True if space given to child by the expand option is actually allocated to child, rather than just padding it. This parameter has no effect if expand is set to False. A child is always allocated the full height of a gtk.HBox and the full width of a gtk.VBox. This option affects the other dimension.

So, essentially, the box is giving everything the same space...you give more to one, it gives it to the other, and the objects all take it and get bigger. The window then has to expand to compensate.

To fix this, set one or both of those options to "False". Setting "Expand" to "False" will also shut off "Fill", but only setting "Fill" to "False" will cause the box to give the extra space to "Fill-False" objects as padding instead.

like image 114
CodeMouse92 Avatar answered Oct 13 '22 00:10

CodeMouse92