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

Hi Monks,

currently i'm working on a pTk-application which i will use for sorting pictures by hand. Some experiments with hlist worked quite good with single-selections. But i want a really ergonomic behavior as f. i. in KDE's konqueror or in ms-explorer.

I would like to select one or more eventually disjointed items (=thumbnails) as i can do already in a Listbox with -selectmode => "extended". Then i want to grip this selection, drag it and drop it onto another entry in the same Listbox/HList-entry. The selection should then be moved before this destination entry.

My problem is that a new ButtonPress-1-event destroys the former selection. In the documentation i couldn't find anything which avoids this behavior.

example which illustrates the problem

use strict; use Tk; my $main = MainWindow->new; my $box = $main->Listbox(-relief => 'sunken', -width => -1, # Shrink to fit -selectmode => "extended", -height => 5, -setgrid => 1); my @items = qw(One Two Three Four Five Six Seven Eight Nine Ten Eleven Twelve); foreach (@items) { $box->insert('end', $_); } my $scroll = $main->Scrollbar(-command => ['yview', $box]); $box->configure(-yscrollcommand => ['set', $scroll]); $box->pack(-side => 'left', -fill => 'both', -expand => 1); $scroll->pack(-side => 'right', -fill => 'y'); MainLoop;
Any hints or suggestions ?

(btw. PMs is really very cool)

Replies are listed 'Best First'.
Re: move extended selections within TK::HList or Tk::Listbox
by paulbort (Hermit) on May 22, 2003 at 15:15 UTC
    I don't know a lot of Tk, but If it works the way I think internally, a ButtonPress event is the result of a Button Down and a Button Up.

    To keep the selection and do a drag, you need to just be looking for the ButtonDown event. By the time you get to the ButtonUp event, it's too late.
    --
    Spring: Forces, Coiled Again!
Re: move extended selections within TK::HList or Tk::Listbox
by JamesNC (Chaplain) on May 22, 2003 at 13:30 UTC
    -selectmode=> 'multiple' I think does what you want... JamesNC
Re: move extended selections within TK::HList or Tk::Listbox
by bobn (Chaplain) on May 22, 2003 at 13:27 UTC
    Your code seems to work fine on my system. Have you tried shift-click (hold shift key while clicking left mouse) or ctrl-click (hold shift key while clicking left mouse) when making the end or second selection? From page 152 of "Mastering Perl/Tk", this is what "extended" allows.

    Bob Niederman, http://bob-n.com

    Update: Ooops ctrl-click s/b "(hold ctrl key while clicking left mouse)
      perhaps i didn't make clear what i want.

      The problem is NOT to do a multiselection. This works. But after it's is made i want to grip precise that selection for dragging it inside the same HList/Listbox. That doesn't work like it does f.i. in ms-explorer.

      The ButtonPress-1-event on the already highlighted selection destroys the existing selection. That's the problem.

        From what I can see (a lot;)) that is not a feature of either module. If you want to add such a feature, you will have to handle everything yourself (listening for events, deciding if to hilight, what to hilight, what to move where... see Tk::bind, Tk::bindtags)


        MJD says you can't just make shit up and expect the computer to know what you mean, retardo!
        I run a Win32 PPM repository for perl 5.6x+5.8x. I take requests.
        ** The Third rule of perl club is a statement of fact: pod is sexy.