9

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()
mac
  • 42,153
  • 26
  • 121
  • 131
njvb
  • 1,377
  • 3
  • 18
  • 36
  • Why should moving the separator to the right make a TreeView in the left pane smaller? This is confusing... – Sven Marnach Jan 21 '11 at 01:09
  • Its to the left, made the correction. – njvb Jan 21 '11 at 01:12
  • Issues like this are usually resolved by adjusting the packing parameters, maybe `.pack1(..., False, True)`. If this doesn't help, try calling `set_size_request(0, 0)` on the some widgets. – Sven Marnach Jan 21 '11 at 01:43
  • How about trying it with a GUI designer like Glade and taking a look at the spec it generates? – Apalala Jan 21 '11 at 02:16
  • 1
    It worked by changing it to self.hpan.pack1(self.tree,True,False) and calling the set_size_request(0) thanks – njvb Jan 21 '11 at 17:25
  • 2
    @user381261 - Answers should not be posted as comments, even if you are the OP. The idea is that your question (and its answer) are useful for everybody, not only for yourself, so answer should be easy to find. You should post your code as an answer and select that as "accepted answer". **This is not cheatig!**, it's considered best practice and prerequisite for the self-learner badge! :) – mac Jun 28 '11 at 22:28

1 Answers1

2

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.

CodeMouse92
  • 6,840
  • 14
  • 73
  • 130