Re: pTk Scrolled Text problem

Todd Littlefield <[email protected]>
Newsgroups gmane.comp.lang.perl.tk
Message-ID <[email protected]>
Here is a script that will show the problem...  When it starts up it
will consume 100% cpu due to the scrollbar attempting to redraw...
Watch the thumb bounce up and down in the scroll region.

Thanks again for any help...

On Tue, 2005-12-13 at 17:46 +0000, [email protected] wrote:
> Hello,
> 
> I've been struggling with a problem with the perl/Tk Text widget for
> a while now.  We create a scrolled text widget that has the scrollbars
> as optional (osoe).  If the contents of the widget extend vertically past the
> border of the widget, there is no problem.  The scrollbar appears and
> functions correctly.
> 
> If on the other hand, it extends past the borders vertically and in some
> spots horizontally, then as it scrolls the x-scrollbar appears and disappears
> as it is needed.  No problem here either.
> 
> The problem seems to be when the first line above or below the currently
> viewed text is wider than the visible region, the hide/show scrollbar code
> seems to cause an oscillation...  i.e.  the horizontal scrollbar keeps appearing
> and disappearing.  This continues until the app is killed...  This happens
> when scrolling or selecting text.
> 
> A similar problem to what is going on is easy to reproduce.  Create a text
> widget and add some text.  Have one line off screen that needs the horizontal
> scrollbar.  Have just enough lines after it so that it will be just off the screen
> if you scroll all the way down.
> 
> Now scroll all the way down.  Notice that it keeps jumping up and down as
> you try to view the last lines....  The problem goes away if you make the window
> wide enough to not need the x-scrollbar...
> 
> (I'll put together a sample if need be...)
> 
> This has happened on RedHat 9 Linux with the latest Tk code as well as with
> ActiveState perl and the Tk it is shipped with...
> 
> Any ideas?  
> 
> Thanks in advance...
> 
> - Todd
> -++**==--++**==--++**==--++**==--++**==--++**==--++**==
> This message was posted through the Stanford campus mailing list
> server.  If you wish to unsubscribe from this mailing list, send the
> message body of "unsubscribe ptk" to [email protected]
-- 

                                                        - Todd
Tk_scrolled_text_problem.pl (application/x-perl, 1.8 KB)
#!/usr/bin/perl

# set up modules to be used
use strict;

# UI modules
use Tk;
use Tk::Button;
use Tk::Dialog;
use Tk::HList;
use Tk::ItemStyle;

use Tk::LabFrame;
use Tk::Menu;
use Tk::Optionmenu;
use Tk::Text;

use Tk::LabEntry;

# subroutine declarations, needed by strict setting
use subs qw( CreateMainUI );


# global variables
use vars qw( %widgets );

# Create the main window object... all others are created from this...
$widgets{'MW'} = MainWindow->new( );
$widgets{'MW'}->title( "Scrolled Text Problem" );

my $top  = int( ($widgets{'MW'}->screenheight - 600 ) / 2 );
my $left = int( ($widgets{'MW'}->screenwidth - 800 ) / 2 );


# set the initial size and position of the window...
$widgets{'MW'}->geometry( "800x600+$left+$top" );

# setup the UI
&CreateMainUI( );

# main event loop for the application
MainLoop;





###############################################################################
#
# Create the main UI (the bulk of the work is done here...
#
###############################################################################
sub CreateMainUI
{
    
    $widgets{'commandText'} = $widgets{'MW'}->Scrolled( 'Text',
        -scrollbars => 'osoe',
        -height     => 10,
        -width      => 40,
        -wrap       => 'none',
        )->pack( -side => 'top', -anchor => 'nw',  );

    #
    # insert some lines of text...
    #
    for ( my $i = 0; $i < 10; $i ++)
    {
        $widgets{'commandText'}->insert( 'end',  "1234567890123456789012345678901234567890\n" );
    }


    $widgets{'commandText'}->insert( 'end',  "12345678901234567890123456789012345678901234567890123456789012345678901234567890\n" );

    for ( my $i = 0; $i < 10; $i ++)
    {
        $widgets{'commandText'}->insert( 'end',  "1234567890123456789012345678901234567890\n" );
    }
}
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.