Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problems with Perl T/k and widget

Status
Not open for further replies.

jpasquini

Programmer
Apr 20, 2006
44
US
Hi All,

I am a new Perl programmer who has been hired to work (among other things) with Perl T/k.
I have been trying to get Perl T/k loaded on my own laptop which is running Red Hat 8 Linux, and have managed to get it up and running. The only problem is 'widget' which gives important examples of GUI items and their code.

Although the rest of Perl T/k works, when I run widget I get the message:

Can't locate Tk/AddScrollbars.pm in @INC (@INC Contains..................................) at /usr/lib/perl5/5.8.0/Tk/Widget.pm line 270.

I have seen this error in lots of places in Google, but nowhere where the actual solution or fix to it is displayed. I am in a pretty good bind so I'd appreciate any advice! Thanks

jpasquini
 
oh lordd---

That's where I got it from (same site) Tk-804-027.tar.gz.
Thanks that makes sense though, it appears to be missing but I noticed on other working copies that I don't have permission to access here, they don't appear to even need this module at all.

I wish I could find a downloadable RPM for Red Hat but have not been able to find it anywhere on the net.
I might have to wait until I get access to the work system, and then learn under fire. But it hasn't killed me yet....

>>>>>
1st law of Contracting- Always know everything in advance of learning it.

 
Fantastic!

Mr. Brooks, remind me to promote you. Also, your raise and company vehicle is under review......



jpasquini

 
One solution


use Tk;
use Tk::Scrollbar;

Copy it on your perl script


# ##################################################################
# Package Scrollbar
# ##################################################################

package Tk::Frame;

sub AddScrollbars
{
# require Tk::Scrollbar; # changed


my ($cw,$w) = @_;
my $def = '';
my ($x,$y) = ('','');
my $s = 0;
my $c;
$cw->freeze_on_map;
foreach $c ($w->configure)
{
my $opt = $c->[0];
if ($opt eq '-yscrollcommand')
{
my $slice = Tk::Frame->new($cw,Name => 'ysbslice');
my $ysb = Tk::Scrollbar->new($slice,-orient => 'vertical', -command =>
[ 'yview', $w ]);
my $size = $ysb->cget('-width');
my $corner = Tk::Frame->new($slice,Name=>'corner','-relief' => 'raised',
'-width' => $size, '-height' => $size);
$ysb->pack(-side => 'left', -fill => 'y');
$cw->Advertise('yscrollbar' => $ysb);
$cw->Advertise('corner' => $corner);
$cw->Advertise('ysbslice' => $slice);
$corner->{'before'} = $ysb->PathName;
$slice->{'before'} = $w->PathName;
$y = 'w';
$s = 1;
}
elsif ($opt eq '-xscrollcommand')
{
my $xsb = Tk::Scrollbar->new($cw,-orient => 'horizontal', -command => [
'xview', $w ]);
$cw->Advertise('xscrollbar' => $xsb);
$xsb->{'before'} = $w->PathName;
$x = 's';
$s = 1;
}
}
if ($s)
{
$cw->Advertise('scrolled' => $w);
$cw->ConfigSpecs('-scrollbars' => ['METHOD','scrollbars','Scrollbars',$x.$y]);
}
}

# end of Tk::Frame::AddScrollbars

# copied from freeze_on_map.al
sub freeze_on_map
{
my ($w) = @_;
unless ($w->Tk::bind('Freeze','<Map>'))
{
$w->Tk::bind('Freeze','<Map>',['packPropagate' => 0])
}
$w->AddBindTag('Freeze');
}

# end of Tk::Frame::freeze_on_map

# copied from scrollbars.al
sub scrollbars
{
my ($cw,$opt) = @_;
my $var = \$cw->{'-scrollbars'};
if (@_ > 1)
{
my $old = $$var;
if (!defined $old || $old ne $opt)
{
$$var = $opt;
$cw->queuePack;
}
}
return $$var;
}

# end of Tk::Frame::scrollbars

# copied from queuePack.al
#line 194 "blib\lib\Tk\Frame.pm (autosplit into blib\lib\auto\Tk\Frame\queuePack.al)"
sub queuePack
{
my ($cw) = @_;
unless ($cw->{'pack_pending'})
{
$cw->{'pack_pending'} = 1;
$cw->afterIdle([$cw,'packscrollbars']);
}
}

# end of Tk::Frame::queuePack

# copied from packscrollbars.al
#line 265 "blib\lib\Tk\Frame.pm (autosplit into blib\lib\auto\Tk\Frame\packscrollbars.al)"
sub packscrollbars
{
my ($cw) = @_;
my $opt = $cw->cget('-scrollbars');
my $slice = $cw->Subwidget('ysbslice');
my $xsb = $cw->Subwidget('xscrollbar');
my $corner = $cw->Subwidget('corner');
my $w = $cw->Subwidget('scrolled');
my $xside = (($opt =~ /n/) ? 'top' : 'bottom');
my $havex = 0;
my $havey = 0;
$opt =~ s/r//;
$cw->{'pack_pending'} = 0;
if (defined $slice)
{
my $reqy;
my $ysb = $cw->Subwidget('yscrollbar');
if ($opt =~ /(o)?[we]/ && (($reqy = !defined($1)) || $ysb->Needed))
{
my $yside = (($opt =~ /w/) ? 'left' : 'right');
$slice->pack(-side => $yside, -fill => 'y',-before => $slice->{'before'});
$havey = 1;
if ($reqy)
{
$w->configure(-yscrollcommand => ['set', $ysb]);
}
else
{
$w->configure(-yscrollcommand => ['sbset', $cw, $ysb,
\$cw->{'packysb'}]);
}
}
else
{
$w->configure(-yscrollcommand => undef) unless $opt =~ s/[we]//;
$slice->packForget;
}
$cw->{'packysb'} = $havey;
}
if (defined $xsb)
{
my $reqx;
if ($opt =~ /(o)?[ns]/ && (($reqx = !defined($1)) || $xsb->Needed))
{
$xsb->pack(-side => $xside, -fill => 'x',-before => $xsb->{'before'});
$havex = 1;
if ($reqx)
{
$w->configure(-xscrollcommand => ['set', $xsb]);
}
else
{
$w->configure(-xscrollcommand => ['sbset', $cw, $xsb,
\$cw->{'packxsb'}]);
}
}
else
{
$w->configure(-xscrollcommand => undef) unless $opt =~ s/[ns]//;
$xsb->packForget;
}
$cw->{'packxsb'} = $havex;
}
if (defined $corner)
{
if ($havex && $havey && defined $corner->{'before'})
{
my $anchor = $opt;
$anchor =~ s/o//g;
$corner->configure(-height => $xsb->ReqHeight);
$corner->pack(-before => $corner->{'before'}, -side => $xside,
-anchor => $anchor, -fill => 'x');
}
else
{
$corner->packForget;
}
}
}

# end of Tk::Frame::packscrollbars


dmazzini
GSM System and Telecomm Consultant

 
dmazzini,

This is great....but from a Perl newcomer, where does this code go? Copy it on my Perl script, meaning create a file called AddScrollbars.pm with the above? Unfortunately the laptop running Perl can't access the internet, so I'll have to manually enter this code.
Not sure what you meant.....thanks

jpasquini
 
<<no apparent memo editing capability>> ERASE ERASE Unfortunately the laptop running Perl can't access the internet, and is secured so no files can be copied off of it, so I'll have to manually enter this code. I suspect you meant put it into the widget executable.
I know I certainly feel safer here knowing I'm not able to copy any files.....of course that's beside the point......
 
jpàsquini

Just copy it inside your script. (you can put it at the bottom)

and dont forget to put at the top of your script
use Tk;
use Tk::Scrollbar;

Cheers

dmazzini
GSM System and Telecomm Consultant

 
example yourscript.pl

Your modules here
use Tk;
use Tk::Scrollbar;

Your code here...


at then copy


# ##################################################################
# Package Scrollbar
# ##################################################################

package Tk::Frame;

sub AddScrollbars
{
# require Tk::Scrollbar; # changed


my ($cw,$w) = @_;
my $def = '';
my ($x,$y) = ('','');
my $s = 0;
my $c;
$cw->freeze_on_map;
foreach $c ($w->configure)
{
my $opt = $c->[0];
if ($opt eq '-yscrollcommand')
{
my $slice = Tk::Frame->new($cw,Name => 'ysbslice');
my $ysb = Tk::Scrollbar->new($slice,-orient => 'vertical', -command =>
[ 'yview', $w ]);
my $size = $ysb->cget('-width');
my $corner = Tk::Frame->new($slice,Name=>'corner','-relief' => 'raised',
'-width' => $size, '-height' => $size);
$ysb->pack(-side => 'left', -fill => 'y');
$cw->Advertise('yscrollbar' => $ysb);
$cw->Advertise('corner' => $corner);
$cw->Advertise('ysbslice' => $slice);
$corner->{'before'} = $ysb->PathName;
$slice->{'before'} = $w->PathName;
$y = 'w';
$s = 1;
}
elsif ($opt eq '-xscrollcommand')
{
my $xsb = Tk::Scrollbar->new($cw,-orient => 'horizontal', -command => [
'xview', $w ]);
$cw->Advertise('xscrollbar' => $xsb);
$xsb->{'before'} = $w->PathName;
$x = 's';
$s = 1;
}
}
if ($s)
{
$cw->Advertise('scrolled' => $w);
$cw->ConfigSpecs('-scrollbars' => ['METHOD','scrollbars','Scrollbars',$x.$y]);
}
}

# end of Tk::Frame::AddScrollbars

# copied from freeze_on_map.al
sub freeze_on_map
{
my ($w) = @_;
unless ($w->Tk::bind('Freeze','<Map>'))
{
$w->Tk::bind('Freeze','<Map>',['packPropagate' => 0])
}
$w->AddBindTag('Freeze');
}

# end of Tk::Frame::freeze_on_map

# copied from scrollbars.al
sub scrollbars
{
my ($cw,$opt) = @_;
my $var = \$cw->{'-scrollbars'};
if (@_ > 1)
{
my $old = $$var;
if (!defined $old || $old ne $opt)
{
$$var = $opt;
$cw->queuePack;
}
}
return $$var;
}

# end of Tk::Frame::scrollbars

# copied from queuePack.al
#line 194 "blib\lib\Tk\Frame.pm (autosplit into blib\lib\auto\Tk\Frame\queuePack.al)"
sub queuePack
{
my ($cw) = @_;
unless ($cw->{'pack_pending'})
{
$cw->{'pack_pending'} = 1;
$cw->afterIdle([$cw,'packscrollbars']);
}
}

# end of Tk::Frame::queuePack

# copied from packscrollbars.al
#line 265 "blib\lib\Tk\Frame.pm (autosplit into blib\lib\auto\Tk\Frame\packscrollbars.al)"
sub packscrollbars
{
my ($cw) = @_;
my $opt = $cw->cget('-scrollbars');
my $slice = $cw->Subwidget('ysbslice');
my $xsb = $cw->Subwidget('xscrollbar');
my $corner = $cw->Subwidget('corner');
my $w = $cw->Subwidget('scrolled');
my $xside = (($opt =~ /n/) ? 'top' : 'bottom');
my $havex = 0;
my $havey = 0;
$opt =~ s/r//;
$cw->{'pack_pending'} = 0;
if (defined $slice)
{
my $reqy;
my $ysb = $cw->Subwidget('yscrollbar');
if ($opt =~ /(o)?[we]/ && (($reqy = !defined($1)) || $ysb->Needed))
{
my $yside = (($opt =~ /w/) ? 'left' : 'right');
$slice->pack(-side => $yside, -fill => 'y',-before => $slice->{'before'});
$havey = 1;
if ($reqy)
{
$w->configure(-yscrollcommand => ['set', $ysb]);
}
else
{
$w->configure(-yscrollcommand => ['sbset', $cw, $ysb,
\$cw->{'packysb'}]);
}
}
else
{
$w->configure(-yscrollcommand => undef) unless $opt =~ s/[we]//;
$slice->packForget;
}
$cw->{'packysb'} = $havey;
}
if (defined $xsb)
{
my $reqx;
if ($opt =~ /(o)?[ns]/ && (($reqx = !defined($1)) || $xsb->Needed))
{
$xsb->pack(-side => $xside, -fill => 'x',-before => $xsb->{'before'});
$havex = 1;
if ($reqx)
{
$w->configure(-xscrollcommand => ['set', $xsb]);
}
else
{
$w->configure(-xscrollcommand => ['sbset', $cw, $xsb,
\$cw->{'packxsb'}]);
}
}
else
{
$w->configure(-xscrollcommand => undef) unless $opt =~ s/[ns]//;
$xsb->packForget;
}
$cw->{'packxsb'} = $havex;
}
if (defined $corner)
{
if ($havex && $havey && defined $corner->{'before'})
{
my $anchor = $opt;
$anchor =~ s/o//g;
$corner->configure(-height => $xsb->ReqHeight);
$corner->pack(-before => $corner->{'before'}, -side => $xside,
-anchor => $anchor, -fill => 'x');
}
else
{
$corner->packForget;
}
}
}

# end of Tk::Frame::packscrollbars

Everything inside your perl script



dmazzini
GSM System and Telecomm Consultant

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top