For Programmers: Free Programming Magazines  


Home > Archive > PerlTk > November 2004 > Preserving view while item being scrolled is growing









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Preserving view while item being scrolled is growing
Tony P

2004-11-17, 3:58 pm

I have a need to view a log file that is constantly growing in length.
Data is being viewed in a Scrolled Text widget (Scrolled("Text")).

When I first start, I populate the Text widget with everything in the
file, and then effectively 'tail' it, adjusting srollbar using yview so
that user sees end of log file (i.e. bottom of text widget). This works.

But what is a way to preserve the view when the user manually scrolls up
to view an earlier part of the text? It is rather annoying to have yview
send him back to the bottom when new data is appended.

Mucho TIA,
TP

thundergnat

2004-11-17, 3:58 pm

Tony P wrote:
> I have a need to view a log file that is constantly growing in length.
> Data is being viewed in a Scrolled Text widget (Scrolled("Text")).
>
> When I first start, I populate the Text widget with everything in the
> file, and then effectively 'tail' it, adjusting srollbar using yview so
> that user sees end of log file (i.e. bottom of text widget). This works.
>
> But what is a way to preserve the view when the user manually scrolls up
> to view an earlier part of the text? It is rather annoying to have yview
> send him back to the bottom when new data is appended.
>
> Mucho TIA,
> TP
>


Sounds like you are trying to do two mutually exclusive things.

If I was doing somthing similar, I would track the location of
the cursor versus the end of the file. If the cursor ('insert'
mark) is within 80 lines of the end, scroll the display on append,
if not, don't. Depending on how much and how fast data is added
to the file you may want to make it 20 or 200 or whatever.

If you want to examine the file, scroll up a page or two and
set the cursor. To go back to following the tail, scroll to the
end and set the cursor.

Insert some code in the tail routine similar to:

my $scrollthreshold = 80;
my ($endline, $endcol) = split/\./, $text->index('end');
my ($cursorline,$cursorcol) = split/\./, $text->index('insert');
$text->see('end') if (($endline - $cursorline) < $scrollthreshold);
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com