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

I want to sort Hlist Entrys by Drag&Drop. Knows anyone a solution for that? A function to drag a row and let it drop with a dropcommand where i can identify which row entry was draged and where this was dropped is enough. Or is this impossible?

Replies are listed 'Best First'.
Re: TK-Hlist -> Drag&Drop
by choroba (Cardinal) on Sep 11, 2013 at 13:45 UTC
    I have noticed the following in the documentation:
    Currently drag-and-drop functionality has not been implemented in Tix yet.
    I fear it means it is not possible.
    لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

      I fear it means it is not possible.

      I think it doesn't mean that -- I think it means you have to use bind+dragsiteSet/dragsiteClear/dropsiteSet/dropsiteClear to implement the move-this-list-item-over-here-logic

        So i have found a sample for a Listbox and modified it for a HList. But when i drop, the y coord is not correct...
        use strict; use warnings; use Tk; use Tk::DragDrop; use Tk::DropSite; use Tk::HList; my $mw = new MainWindow; my $hlist = $mw->Scrolled('HList', -scrollbars => "osoe")->pack(-side +=> "left", -expand => 1, -fill => 'both'); my $cnt = 0; foreach (sort keys %ENV) { $hlist->add($cnt); $hlist->itemCreate($cnt, 0, -text => $_); $cnt++; } my $token = $hlist->DragDrop(-event => '<B1-Motion>', -sitetypes => ['Local'], -startcommand => \&StartDrag); $hlist->DropSite(-droptypes => ['Local'], -dropcommand => [\&Drop, $hlist, $token]); MainLoop; sub StartDrag { my $w = $token->parent; my $e = $w->XEvent; my $idx = $w->nearest($e->y); print "Drag Y: " . $e->y . "\n"; print "Pos: $idx\n"; if (defined $idx) { $token->configure(-text => $w->itemCget($idx, 0, -text)); my($X, $Y) = ($e->X, $e->Y); $token->MoveToplevelWindow($X, $Y); $token->raise; $token->deiconify; $token->FindSite($X, $Y, $e); } } sub Drop { my $w = $token->parent; my $e = $w->XEvent; my $idx = $w->nearest($e->y); print "Drop Y: " . $e->y . "\n"; print "Pos: $idx\n"; }
        I hope so.. And searching a sample for this