For Programmers: Free Programming Magazines  


Home > Archive > PerlTk > April 2006 > Hlist









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 Hlist
Johan Meskens CS3 jmcs3

2006-04-15, 10:00 pm

#This is perl, v5.8.7 built for i486-linux-gnu-thread-multi

hello
i am experiencing some trouble using the tk::hlist in an application
i thought i was doing something wrong
but using someone else's example script i experience the same problem
namely
, the browsecommand and command options don't deliver anything to the
shift in the subroutine

########################################
####
use warnings;
use strict;
use Tk;

use Tk::HList;
my $message = 'nothing yet ...';
my $mw = MainWindow->new;
$mw->title('Dialog');
my $label = $mw->Label(-textvariable => \$message);
my $exit = $mw->Button(-text => 'Exit',
-command => [$mw => 'destroy']);
my $hlist = $mw->Scrolled('HList',
-itemtype => 'text',
-separator => '/',
-selectmode => 'single',
-browsecmd => sub{ browse()},
-command => sub{ browse() }
);

my @dirs = qw(/ /home /home/joe /home/jane /usr
/usr/lib /usr/bin /usr/man /usr/include /usr/local
/usr/local/lib /usr/local/bin /usr/local/include
);
$hlist->add($_, -text => $_) for @dirs;
$exit->pack(-side => 'bottom');
$label->pack(-side => 'top');
$hlist->pack;
MainLoop;
sub browse {
my $choice = shift;
$message = "You chose '$choice'";
}


__END__

i get the error when i click or double click:
' Use of uninitialized value in concatenation (.) or string at ..

thanks
jmcs3



-++**==--++**==--++**==--++**==--++**==--++**==--++**==
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 majordomo@lists.stanford.edu

Kevin Michael Vail

2006-04-15, 10:00 pm

In article <1145147957.27268.8.camel@localhost.localdomain>,
Johan Meskens CS3 jmcs3 <johanmeskenscs3@chromaticspaceandworld.com>
wrote:

> i am experiencing some trouble using the tk::hlist in an application
> i thought i was doing something wrong
> but using someone else's example script i experience the same problem
> namely
> , the browsecommand and command options don't deliver anything to the
> shift in the subroutine


See below. The way you've got the commands defined, the subroutine
browse is called with no arguments. The proper way to do this is to
pass a reference to the browse subroutine. (Well, this is Perl, so
that's actually *a* proper way.)

> ########################################
####
> use warnings;
> use strict;
> use Tk;
>
> use Tk::HList;
> my $message = 'nothing yet ...';
> my $mw = MainWindow->new;
> $mw->title('Dialog');
> my $label = $mw->Label(-textvariable => \$message);
> my $exit = $mw->Button(-text => 'Exit',
> -command => [$mw => 'destroy']);
> my $hlist = $mw->Scrolled('HList',
> -itemtype => 'text',
> -separator => '/',
> -selectmode => 'single',
> -browsecmd => sub{ browse()},

================> -browsecmd => \&browse,
> -command => sub{ browse() }

================> -command => \&browse,
> );
>
> my @dirs = qw(/ /home /home/joe /home/jane /usr
> /usr/lib /usr/bin /usr/man /usr/include /usr/local
> /usr/local/lib /usr/local/bin /usr/local/include
> );
> $hlist->add($_, -text => $_) for @dirs;
> $exit->pack(-side => 'bottom');
> $label->pack(-side => 'top');
> $hlist->pack;
> MainLoop;
> sub browse {
> my $choice = shift;
> $message = "You chose '$choice'";
> }
>
>
> __END__

--
Kevin Michael Vail | Dogbert: That's circular reasoning.
kevin@vaildc.net _ | Dilbert: I prefer to think of it as no loose ends.

2006-04-15, 10:00 pm

--- Johan Meskens CS3 jmcs3
<johanmeskenscs3@chromaticspaceandworld.com> wrote:

> #This is perl, v5.8.7 built for
> i486-linux-gnu-thread-multi
>
> hello
> i am experiencing some trouble using the tk::hlist
> in an application
> i thought i was doing something wrong
> but using someone else's example script i experience
> the same problem
> namely
> , the browsecommand and command options don't
> deliver anything to the
> shift in the subroutine
>
> ########################################
####
> use warnings;
> use strict;
> use Tk;
>
> use Tk::HList;
> my $message = 'nothing yet ...';
> my $mw = MainWindow->new;
> $mw->title('Dialog');
> my $label = $mw->Label(-textvariable => \$message);
> my $exit = $mw->Button(-text => 'Exit',
> -command => [$mw =>
> 'destroy']);
> my $hlist = $mw->Scrolled('HList',
> -itemtype => 'text',
> -separator => '/',
> -selectmode => 'single',


Changing these lines worked for me. Not sure why it
didn't work the other way...

-browsecmd => sub { my $text = shift; $message="You
bro
wsed $text" },
-command => sub { my $text = shift; $message="You
chose
$text" }

Phil

> -browsecmd => sub{
> browse()},
> -command => sub{ browse() }
> );
>
> my @dirs = qw(/ /home /home/joe /home/jane /usr
> /usr/lib /usr/bin /usr/man
> /usr/include /usr/local
> /usr/local/lib /usr/local/bin
> /usr/local/include
> );
> $hlist->add($_, -text => $_) for @dirs;
> $exit->pack(-side => 'bottom');
> $label->pack(-side => 'top');
> $hlist->pack;
> MainLoop;
> sub browse {
> my $choice = shift;
> $message = "You chose '$choice'";
> }
>
>
> __END__
>
> i get the error when i click or double click:
> ' Use of uninitialized value in concatenation (.) or
> string at ..
>
> thanks
> jmcs3
>
>
>
>

-++**==--++**==--++**==--++**==--++**==--++**==--++**==
> 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
> majordomo@lists.stanford.edu
>



________________________________________
__________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
-++**==--++**==--++**==--++**==--++**==--++**==--++**==
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 majordomo@lists.stanford.edu

Marc Dashevsky

2006-04-15, 10:00 pm

At 08:39 PM 4/15/2006, Johan Meskens CS3 jmcs3 wrote:
>i am experiencing some trouble using the tk::hlist in an application
>i thought i was doing something wrong but using someone else's example
>script i experience the same problem namely, the browsecommand and command options don't deliver anything to the shift in the subroutine


You don't pass any arguments to browse(). Try the following edits:

>my $hlist;
>$hlist = $mw->Scrolled('HList',
> -itemtype => 'text',
> -separator => '/',
> -selectmode => 'single',
> -browsecmd => sub{ browse($hlist) },
> -command => sub{ browse($hlist) }
> );

..
..
..
>sub browse {
> my $choice = shift->selectionGet->[0];
> $message = "You chose '$choice'";
>}


-++**==--++**==--++**==--++**==--++**==--++**==--++**==
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 majordomo@lists.stanford.edu

Sponsored Links







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

Copyright 2008 codecomments.com