Re: Auto Scrolling
- From: Brian <dol-sen telus net>
- To: gtk-app-devel-list <gtk-app-devel-list gnome org>
- Subject: Re: Auto Scrolling
- Date: Thu, 28 Oct 2004 16:49:47 -0700
On Thu, 2004-10-28 at 13:46 -0700, Leo Przybylski wrote:
Hello,
I'm trying to tail a file using a GtkTextView. Is that the right way I
should be going about it? Does anyone have examples or anything for an
autoscrolliing GtkTextView ???
Leo
Here is code I cut from my specialized terminal app in python. I hope
it is readable enough. It should if you know python at all.
#!/usr/bin/env python
# A constant that represents the maximum distance from the
# bottom of the slider for the slider to stick. Too small and
# you won't be able to make it stick when text is added rapidly
SLIDER_CLOSE_ENOUGH = 0.5 # of the page size
# a portion of the global init code
dprint("TERMINAL: get & connect to vadjustments")
#dprint(TABS[:-1])
for x in TABS[:-1]:
adj = self.term.scrolled_window[x].get_vadjustment()
self.term.vadjustment += [adj]
id = self.term.vadjustment[x].connect("value_changed",self.set_scroll)
self.term.vhandler_id += [id]
# create autoscroll end marks to seek to &
end_mark = self.term.buffer[x].create_mark(("end_mark"+str(x)),
self.term.buffer[x].get_end_iter(), False)
self.term.end_mark += [end_mark]
def set_scroll(self, vadjustment):
"""Sets autoscrolling on when moved to bottom of scrollbar"""
self.term.auto_scroll[self.term.current_tab] = ((vadjustment.upper - \
vadjustment.get_value()) - \
vadjustment.page_size < \
(SLIDER_CLOSE_ENOUGH * vadjustment.page_size))
return
def append(self, num, text, tagname = None):
""" Append text to a text buffer. Line numbering based on
the process window line count is automatically added.
BUT -- if multiple text buffers are going to be updated,
always update the process buffer LAST to guarantee the
line numbering is correct.
Optionally, text formatting can be applied as well
"""
line_number = self.term.buffer[TAB_PROCESS].get_line_count()
iter = self.term.buffer[num].get_end_iter()
lntext = '000000' + str(line_number) + ' '
self.term.buffer[num].insert_with_tags_by_name(iter, lntext[-7:] , 'linenumber')
if tagname == None:
self.term.buffer[num].insert(iter, text)
else:
self.term.buffer[num].insert_with_tags_by_name(iter, text, tagname)
if self.term.auto_scroll[num] and num == self.term.current_tab:
self.scroll_current_view()
--
Brian <dol-sen telus net>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]