[pygtk] Check if end of a TextView is visible
René 'Necoro' Neumann
lists at necoro.eu
Mon Sep 7 04:42:24 WST 2009
Well - just a quick idea (not tested and correctly formulated):
visible = textview.get_visible_rect()
max_y_pos = visible.y + visible.height
last_line_pos = sum(textview.get_line_yrange(textbuffer.get_end_iter()))
if last_line_pos > max_y_pos:
print "Line not visible"
else:
print "Line visible"
Hint: This takes a line as being "visible" iff it is completely visible
- if it is enough to see parts of the last line, replace the "sum" by an
access to the first element of the tuple (get_line_yrange returns a (y,
height)-tuple)
Regards,
René
Greenpickle schrieb:
> 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.
>
> _______________________________________________
> pygtk mailing list pygtk at daa.com.au
> http://www.daa.com.au/mailman/listinfo/pygtk
> Read the PyGTK FAQ: http://faq.pygtk.org/
>
More information about the pygtk
mailing list