Problem: Single Scrollbar Running 2 Text Widgets 
Author Message
 Problem: Single Scrollbar Running 2 Text Widgets

Quote:
>I can run the attached program, and by moving the scrollbar
>ever so slightly with my mouse, I can get the lines to be
>mismatched (see attached screen grab gif).

Not an answer, I just wanted to say that I can get it to do
the same thing. Usually it behaves correctly (keeping the
lines aligned left and right). But certain positions of the
list with a slight vertical movement of the scrollbar can
cause the disjoint behavior.

This is on ActivePerl Build 631 with Tk 800.023 .

--
Mike Arms

-++**==--++**==--++**==--++**==--++**==--++**==--++**==
This message was posted through the Stanford campus mailing list
server.  If you wish to unsubscribe from this mailing list, send the



Sun, 27 Mar 2005 02:20:17 GMT  
 Problem: Single Scrollbar Running 2 Text Widgets

Quote:
> Folks-

> I can run the attached program, and by moving the scrollbar
> ever so slightly with my mouse, I can get the lines to be
> mismatched (see attached screen grab gif).

> I would expect this should not to be able to happen.

> Can anyone see what I am doing wrong?

Below is a snippet from tkrevdiff. I had similar problems, I had also
some problems with endless recursions. Maybe the code could be
simpler, but it works for me.

Regards,
        Slaven

my $scrsrc; # scroll source
use constant SCRSRC_SB  => 0;
use constant SCRSRC_OLD => 1;
use constant SCRSRC_NEW => 2;

$sb->configure(-command => sub {
                   #warn "A1 $scrsrc";
                   if (!defined $scrsrc) {
                       $scrsrc = SCRSRC_SB;
                       $sb->afterIdle(sub { undef $scrsrc });
                   }
                   if ($scrsrc == SCRSRC_SB) {

                   }
                   #warn "Z1 $scrsrc";
               });
$txt{'old'}->configure(-yscrollcommand => sub {
                           #warn "A2 $scrsrc";
                           if (!defined $scrsrc) {
                               $scrsrc = SCRSRC_OLD;
                               $txt{'old'}->after(50,sub { undef $scrsrc });
                           }
                           if ($scrsrc == SCRSRC_OLD) {

                               $txt{'new'}->yviewMoveto(($txt{'old'}->yview)[0])
;
                               #XXX set_log_active('old');
                           }
                           #warn "Z2 $scrsrc";
                       });
$txt{'new'}->configure(-yscrollcommand => sub {
                           #warn "A3 $scrsrc";
                           if (!defined $scrsrc) {
                               $scrsrc = SCRSRC_NEW;
                               $txt{'new'}->after(50,sub { undef $scrsrc });
                           }
                           if ($scrsrc == SCRSRC_NEW) {

                               $txt{'old'}->yviewMoveto(($txt{'new'}->yview)[0])
;
                               # XXX set_log_active('new');
                           }
                           #warn "Z3 $scrsrc";
                       });

--

    tkruler - Perl/Tk program for measuring screen distances
    http://ptktools.sourceforge.net/#tkruler
-++**==--++**==--++**==--++**==--++**==--++**==--++**==
This message was posted through the Stanford campus mailing list
server.  If you wish to unsubscribe from this mailing list, send the



Sun, 27 Mar 2005 05:05:27 GMT  
 Problem: Single Scrollbar Running 2 Text Widgets
This is a multi-part message in MIME format.
--------------40C60C0BA00C1BB7228819E3
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

Folks-

Many thanks to Slaven for showing me the solution to this problem!

The attached test program is my version of Slaven's solution. Please
test it out and see if it actually does work for you. It seems to
work for me.

Basically, what happens is that the 2 windows get out-of-sync with
regards to what each thinks is the top-left pixel is in the view. I'm
guessing this is because of rounding errors when doing the scrolling
math (there are only 15 decimal places). I have data showing this,
but didn't go to the source to figure it out.

Slaven's solution was to have widget A set widget B's position, or
vice-versa. My solution is to simply pick a master widget, and always
have it force the slave to its position. Either way should work.

Please point out any flaws in the reasoning here, I think I'm right,
but am not sure. Isn't this written down anywhere? If not, where
should it go?

Thanks

-Craig

Quote:


> > Folks-

> > I can run the attached program, and by moving the scrollbar
> > ever so slightly with my mouse, I can get the lines to be
> > mismatched (see attached screen grab gif).

> > I would expect this should not to be able to happen.

> > Can anyone see what I am doing wrong?

> Below is a snippet from tkrevdiff. I had similar problems, I had also
> some problems with endless recursions. Maybe the code could be
> simpler, but it works for me.

> Regards,
>         Slaven

--------------40C60C0BA00C1BB7228819E3
Content-Type: text/plain; charset=us-ascii;
 name="crap"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="crap"

#!/usr/sbin/perl

use strict;
use Tk;

# Create new text window...
my $top = MainWindow->new;

# Create top frame for everything up top...
my $tf = $top->Frame()->pack(-side => 'top', -fill => 'both', -expand => 'True');

# Create Right Text widget...
my $rtxt = $tf->Text( -width => 20, -wrap => 'none' )->
        pack(-side => 'right', -fill => 'both', -expand => 'True');

# Create Left Text Widget...
my $ltxt = $tf->Text( -width => 10, -wrap => 'none' )->
        pack(-side => 'left', -fill => 'y', -expand => 0);

# Create tags for alternating colors...
$ltxt->tag('configure', 'LIGHT', -background => 'lightgrey');
$ltxt->tag('configure', 'DARK', -background => 'grey');

$rtxt->tag('configure', 'LIGHT', -background => 'lightgrey');
$rtxt->tag('configure', 'DARK', -background => 'grey');

# Setup vertical scroll bar for both text windows...
my $yscroll = $tf->Scrollbar( -command =>
        sub {


                $rtxt->yviewMoveto($tmp[0]) }        # Scroll slave to master
)->pack(-fill => 'y', -side => 'left');

# Connect up Y scrollbar to text widgets...
$ltxt->configure( -yscrollcommand => [$yscroll => 'set'] );
$rtxt->configure( -yscrollcommand => [$yscroll => 'set'] );

my ( $i, $tag);

        if($i % 2) { $tag='LIGHT' } else { $tag='DARK' };
        $rtxt->insert('end', "This is line $i\n", $tag);
        $ltxt->insert('end', "$i\n", $tag);

Quote:
}

MainLoop();

--------------40C60C0BA00C1BB7228819E3--

-++**==--++**==--++**==--++**==--++**==--++**==--++**==
This message was posted through the Stanford campus mailing list
server.  If you wish to unsubscribe from this mailing list, send the



Mon, 28 Mar 2005 00:57:54 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Problems with Scrollbar and Text widget

2. Text widget and scrollbar

3. Blinking scrollbar in Scrolled Text widget

4. Getting a text widget to display within a single event

5. text scrollbar problem

6. Running another program on a text widget

7. Controlling multiple widgets with one scrollbar

8. scrolling multiple widgets with one scrollbar

9. referring widget from a scrollbar

10. Problem running demo/widget.

11. Selection in Text Widget problem

12. tagAdd and tagDelete problem using text widget

 

 
Powered by phpBB® Forum Software