[pygtk] Check if end of a TextView is visible

Greenpickle orangepickle12 at googlemail.com
Mon Sep 7 04:18:37 WST 2009


I have a TextView in a ScrolledWindow, and a process writes output to
it; every time a line is written, it scrolls to the end using
TextView.scroll_to_iter.  However, this means it's hard to scroll up to
view earlier output.

What I want to do is check if the last line is visible before printing a
line, then print the line, then scroll to the end only if the last line
was visible before:

textbuffer = textview.get_buffer()
scroll = [if end is visible]
textbuffer.insert(textbuffer.get_end_iter(), output + '\n')
if scroll:
textview.scroll_to_iter(textbuffer.get_end_iter(), .0)

 - So that it's possible to view stuff earlier on without being scrolled
back to the end all the time, but you can return to auto-scrolling by
scrolling back to the end manually.  I haven't been able found any
functions for TextViews/TextIters/TextMarks in any reference that would
do this.



More information about the pygtk mailing list