Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

multiple selection in a Perl/Tk HList

by Real Perl (Beadle)
on Apr 06, 2005 at 22:02 UTC ( [id://445457]=perlquestion: print w/replies, xml ) Need Help??

Real Perl has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks,

I would like to ask if it is possible to select multiple entries in a HList (table like) that are not next to each other. Of course, the next question is how?

Thanks in advance Monks!

Claire

20050407 Edit by castaway: Changed title from 'multiple selection in a HList'

Replies are listed 'Best First'.
Re: multiple selection in a Perl/Tk HList
by The Mad Hatter (Priest) on Apr 06, 2005 at 22:36 UTC
    I think Claire is talking about Tk::HList. I haven't used it, but shouldn't you be able to select one entry and then hold the control key and click another entry to select both? That's the way it works in most widgets.
Re: multiple selection in a Perl/Tk HList
by sh1tn (Priest) on Apr 06, 2005 at 22:24 UTC
    Hash keys do not appear in the same order you have created them.
    So "not next to each other" makes no sense.
    You may want to see perldoc -q sort.


Re: multiple selection in a Perl/Tk HList
by gam3 (Curate) on Apr 07, 2005 at 04:42 UTC
    It seems that it is possible.

    tixHList Says: "If the -selectmode is "extended", when the user drags the mouse pointer over the list entries, all the entries under the pointer will be highlighted. The user can also make disjointed selections using <Control-ButtonPress-1>."

    $mw->HList(-selectmode => 'extended', ...
    -- gam3
    A picture is worth a thousand words, but takes 200K.
Re: multiple selection in a Perl/Tk HList
by Util (Priest) on Apr 07, 2005 at 18:32 UTC

    -selectmode => 'multiple' only allows for contiguous selection, via click&drag or click&shift-click.

    -selectmode => 'extended' allows for all that, plus non-contiguous selection, via ctrl-click.

    Here is an example that will demonstrate the differences:

    #!/usr/bin/perl use strict; use warnings; use Tk; use Tk::HList; my $mw = MainWindow->new(); my $hlist = $mw->HList( -itemtype => 'text', # -selectmode => 'multiple', -selectmode => 'extended', -browsecmd => \&bc, ); my $text = $mw->Text(); my @words = qw( aback abaft abandon babble babies baboon cabal cabana cabaret ); $hlist->add($_, -text=>$_) foreach qw(a b c); foreach ( @words ) { my $first = substr($_, 0, 1); $hlist->add("$first.$_", -text=>$_); } $hlist->pack(-side => 'top', -fill => 'both', -expand => 1); $text ->pack(-side => 'bottom', -fill => 'both', -expand => 1); MainLoop; sub bc { my $sel = join "\n", $hlist->infoSelection(); $text->delete('1.0', 'end'); $text->insert('end', $sel); }

Re: multiple selection in a Perl/Tk HList
by tlm (Prior) on Apr 06, 2005 at 22:11 UTC

    Are you talking about a hash table? There is no proximity relationship among the keys of hash table, so "next to each other" would be undefined. You can use hash slices to select the values corresponding to multiple keys; e.g.

    @ids{qw( Ann Bert Chuck )}
    returns a list of the values in the hash %ids corresponding to Ann, Bert, and Chuck. Is this what you are looking for?

    the lowliest monk

Re: multiple selection in a Perl/Tk HList
by zentara (Archbishop) on Apr 07, 2005 at 11:34 UTC
    Make your selectmode:
    -selectmode => 'multiple',
    then holding the shift button down, while left clicking with the mouse, will select multiple entries.

    See Tk-POP3-previewer for an example.


    I'm not really a human, but I play one on earth. flash japh

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://445457]
Approved by tlm
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (3)
As of 2024-04-24 21:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found