in reply to Perl Tk: Dropsite aggregation vs singles
I just compare the time... this will fail if someone is faster than 1 second or if the callbacks take longer than 1 second to complete... I tested it with 100 files. This is the only hack *cough, *cough... I could think of.#!/perl/bin/perl -w use Tk; use Tk::DropSite; use strict; use vars qw($top $drop @files $start_drop @null $lbox $btn ); $start_drop = time; $top = new MainWindow; $top->Label(-text => "The drop area:")->pack; $drop = $top->Scrolled('Listbox', -scrollbars => "osoe",-height, 3, -width, 30, )->pack(-fill, 'both', -expand, '1'); # Tell Tk that $drop should accept drops. # The allowed drag and drop types on Unix systems are "KDE", "XDND" an +d "SUN" # and on Windows systems the "Win32" dnd type. # When dropping occurs, execute the accept_drop callback. $drop->DropSite (-dropcommand => [\&accept_drop, $drop], -droptypes => ($^O eq 'MSWin32' ? 'Win32' : ['KDE', 'XDND', 'Sun']) ); $lbox = $top->Scrolled('Listbox', -scrollbars => "osoe", -height, 3, -width, 30, )->pack(-fill, 'both', -expand, '1'); $btn = $top->Button(-text, 'Show Files', -command, \&show_files)->pack +(); MainLoop; sub accept_drop { my($widget, $selection) = @_; my $filename; my $time = time-$start_drop; eval { if ($^O eq 'MSWin32') { $filename = $widget->SelectionGet(-selection => $selection, 'STRING'); } else { $filename = $widget->SelectionGet(-selection => $selection, 'FILE_NAME'); } }; if($time > 1){ @files= @null; } $drop->delete('0', 'end'); push @files, $filename; my $x = 0; foreach(@files){ $drop->insert($x, $_); $x++; } $start_drop = time; } sub show_files { $lbox->delete('0','end'); foreach(@files){ $lbox->insert('end', $_); } }
|
|---|