Re: Tk::DropSite question
- From: Ch Lamprecht <ch.l.ngre@xxxxxxxxx>
- Date: Mon, 05 Mar 2007 23:44:22 +0100
~greg wrote:
"Ch Lamprecht" > wrote ...
One way is setting up a timer:
But I was kinda hoping for something
that didn't depend on timing. :)
Following up on your suggestion,
I found, and then substituted, ->afterIdle()
for ->after().
And this works too.
So, would you agree that ->afterIdle() is better?
Or could there be some problem with it?
afterIdle will work as long as no update- method is called by any of the involved subs.
However, as I read the source of the module I found, that it provides a mechanism, to do what you need: You can pass a Callback to the -entercommand option. That will be called with either 0 or 1 as first arg to indicate the beginning/end of a group_drop. See example below.
(And see another post for a second solution)
use strict;
use warnings;
use Data::Dumper;
use Tk;
use Tk::DropSite qw(Win32);
my $Main = MainWindow->new;
my %SourceList;
my $SourceListBox = $Main->Scrolled("Listbox",
-scrollbars => "osoe",
)->pack(-fill => 'both',
);
$SourceListBox->DropSite( -entercommand => \&drop_state,
-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);
}
sub OnSourceDrop{
print "OnSourceDrop\n";
my($widget, $selection) = @_;
my $f = $widget->SelectionGet('-selection'=>$selection,'STRING');
return if ! defined $f; # is this really necessary?
SourceAdd($f);
}
MainLoop;
sub drop_state{
print 'group drop state: ',$_[0] ? 'started':'finished' , "\n";
}
--
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
- Re: Tk::DropSite question
- From: Ch Lamprecht
- Re: Tk::DropSite question
- From: ~greg
- Tk::DropSite question
- Prev by Date: Re: Perlib modules prob.
- Next by Date: Re: Tk::DropSite question
- Previous by thread: Re: Tk::DropSite question
- Next by thread: Re: Tk::DropSite question
- Index(es):
Relevant Pages
|
|