Re: Tk::DropSite question
- From: Ch Lamprecht <ch.l.ngre@xxxxxxxxx>
- Date: Mon, 05 Mar 2007 00:04:28 +0100
~greg wrote:
I have reduced the following script,
but it's runnable. It's a way
to make a Tk listbox that accepts
a selection of files or folders
from Windows Explorer.
The drop handler (my "OnSourceDrop")
is apparently called individually
on each file or folder in a multiple selection.
And my question is,
is there any way to know when to call
a group-drop-handler,
to be called after all the individual
calls to OnSourceDrop() are finished
after a group drop?
One way is setting up a timer:
This one will trigger group_drop_handler 50ms after the last call to OnSourceDrop. Are groups with one element considered being groups in your case?
Otherwise you would have to add a counter...
{
use strict;
use warnings;
$|=1;
use Tk;
use Tk::DropSite qw(Win32);
my $Main = MainWindow->new
(
-title=>'DND'
);
my %SourceList;
my $SourceListBox = $Main->Scrolled
(
"Listbox",
-scrollbars => "osoe",
)->pack
(
-fill => 'x',
);
$SourceListBox->DropSite
(
-dropcommand => [\&OnSourceDrop,$SourceListBox],
-droptypes => 'Win32',
);
sub SourceAdd
{
my $f = shift; # file or folder
return if exists $SourceList{$f};
return if ! -e $f;
$SourceList{$f} = 1;
my $slash = -d $f ? '\\' : '';
$SourceListBox->insert('end', "$f$slash" );
$SourceListBox->yviewMoveto(1);
}
my $after_cb;
sub OnSourceDrop$widget->afterCancel($after_cb);
{
my($widget, $selection) = @_;
$after_cb = $widget->after(50,\&group_drop_handler);
my $f = $widget->SelectionGet('-selection'=>$selection,'STRING');}
return if ! defined $f; # is this really necessary?
SourceAdd($f);
}
MainLoop;
sub group_drop_handler{
print "group drop finished\n";
}
Christoph
--
use Tk;use Tk::GraphItems;$c=tkinit->Canvas->pack;push@i,Tk::GraphItems->
TextBox(text=>$_,canvas=>$c,x=>$x+=70,y=>100)for(Just=>another=>Perl=>Hacker);
Tk::GraphItems->Connector(source=>$i[$_],target=>$i[$_+1])for(0..2);
$c->repeat(30,sub{$_->move(0,4*cos($d+=3.16))for(@i)});MainLoop
.
- Follow-Ups:
- Re: Tk::DropSite question
- From: ~greg
- Re: Tk::DropSite question
- References:
- Tk::DropSite question
- From: ~greg
- Tk::DropSite question
- Prev by Date: Tk::DropSite question
- Next by Date: Re: Tk::DropSite question
- Previous by thread: Tk::DropSite question
- Next by thread: Re: Tk::DropSite question
- Index(es):
Relevant Pages
|
|