Re: Tk::DropSite question



~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
.



Relevant Pages

  • Re: Restrict Find&Repalce to Selected Text
    ... Greg Maxey/Word MVP ... >> Sub FRinSelectionOnly() ... >> Dim oRg As Range ... >> oRg.InRangeLoop ...
    (microsoft.public.word.vba.general)
  • Re: Tech Eval
    ... Greg Maxey/Word MVP ... > Private Sub TextBox1_Change ... > Private Sub CheckData() ... > Dim TestChar As String ...
    (microsoft.public.word.vba.userforms)
  • Re: find and replace text that is not in a table
    ... Thanks Greg. ... Sub TwoSpacesAfterSentence2() ... 'This should prevent most cases of improper double spacing ... As String, newSpace As String) ...
    (microsoft.public.word.vba.general)
  • Re: Prompt to Save When Closing
    ... Thanks, Greg. ... > Public Sub BatchToggleEmbedSmartTabs() ... >Dim PathToUse As String ...
    (microsoft.public.word.docmanagement)
  • RE: Sub too large
    ... Regards, ... "Greg Wilson" wrote: ... > Private Sub Worksheet_SelectionChange ... I have only completed the third column and have already ...
    (microsoft.public.excel.programming)