[pygtk] Scroll Region on Screen
Robert Schroll
rschroll at gmail.com
Tue Nov 9 10:08:37 WST 2010
On 11/06/2010 05:45 PM, Robert Schroll wrote:
> I have a TextBuffer in a TextView. I want to scroll the TextView so that
> two TextMarks, A and B, are both visible. If the TextView cannot fit
> both on screen together, I wish that A and as much of the text between A
> and B be visible. I think I should be able to accomplish this with:
> TextView.scroll_mark_onscreen(B)
> TextView.scroll_mark_onscreen(A)
> But this usually doesn't work. Instead, it acts as if only the second
> scroll_mark_onscreen had been called: A is onscreen, but B may not be.
> (The one time it seems to work is when I call this code twice without
> changing the contents of the TextBuffer in between.) There's not a
> problem with TextMark B: if I comment out the last line, B gets scrolled
> on screen just like I want. And if I invert the order of the statements,
> I get the opposite behavior.
>
> Can anyone provide some insight into what's going wrong, or offer a
> different solution for getting both marks on screen?
I'm gathering that scroll_mark_onscreen() doesn't actually do the
scrolling - it must set a callback to do the scrolling once the TextView
is ready for it. So I guess that the second call of
scroll_mark_onscreen must clobber the callback from the first. I've
found that I can get it to work by postponing the second call in an idle
callback:
TextView.scroll_mark_onscreen(B)
glib.idle_add(lambda: TextView.scroll_mark_onscreen(A))
Unfortunately, this (a) can produce a "bounce" as the view scrolls first
one way then the other and (b) is a rather ugly looking mess. Is there
a better solution?
Thanks,
Robert
More information about the pygtk
mailing list