[pygtk] synchronizing HPaned widgets
John Finlay
finlay at moeraki.com
Fri Feb 6 07:24:59 WST 2009
Stephen Langer wrote:
> On Feb 5, 2009, at 3:15 PM, John Finlay wrote:
>
>
>> Stephen Langer wrote:
>>
>>> Hi --
>>>
>>> I'm hoping that someone can tell me if this is a bug or if I'm
>>> doing something wrong.
>>>
>>> I have two HPaned widgets whose separators I'd like to keep
>>> synchronized. Both Paneds are in the same VBox, so they have the
>>> same width.
>>>
>>> As described at http://faq.pygtk.org/index.py?req=show&file=faq19.013.htp
>>> , I connect to the 'notify' signal for each pane to find out when
>>> the separator has been moved. The callback function blocks the
>>> signal for the other pane, changes its position to match the
>>> first pane, and then unblocks the signal.
>>>
>>> The problem is that the signal doesn't seem to be blocked
>>> sometimes, so the program goes into an infinite loop. There are
>>> easy workarounds for this, but they're ugly and unsatisfying. In
>>> particular, the program loops when the panes are first shown if
>>> the contents of two diagonally opposite subpanes are larger than
>>> the contents of the other two.
>>>
>>> I've appended short program that illustrates the problem. Just
>>> starting the program will put it into an infinite loop. If you
>>> replace paneMoved by paneMoved_workaround, the problem goes away.
>>>
>>> Why doesn't blocking the signal work? Am I doing something wrong?
>>>
>>> I've run this test on OS X with python 2.5, gtk 2.14.7, and pygtk
>>> 2.12.1, and on Linux with python 2.4, gtk 2.8.20, and pygtk 2.8.6.
>>>
>>>
>>>
>
> [ code deleted ]
>
>
>> You have to allow the widgets to shrink - remove the "shrink=0" args
>> from the pack1() and pack2() calls.
>>
>> John
>>
>
> Thanks for the response, but what if I don't want the widgets to be
> able to shrink? Is that possible? Why isn't calling handler_block
> before calling set_position sufficient?
>
> -- Steve
>
Yes but you have to set the default size of the window as large or
larger than the required size of the largest pane. Your code doesn't set
the window size so it starts up with the minimum required size to fit
the paned widgets. Since the two separators can't line up because the
panes are different sizes and because the panes can't shrink the
set_position() calls fail and apparently trigger a resize calculation
which trys to set the position and so on. Your choices are allow
something to shrink or set a window size that will allow the separators
to line up initially.
Also you can add a detail to the "notify" signal connection that only
signals when the position is changed - use "notify::position" and you
can remove the gparamspec.name check in paneMoved().
John
More information about the pygtk
mailing list