The following is a Perl/Tk script that accepts drag and drop from an
external program.  In this case it will simply change the entry widget's
text to be the filename:

<code>
use strict;
use Tk;
use Tk::DropSite;
use Tk::Pane;

my $textVariable = "drag here";

my $mw = MainWindow->new;
my $frame = $mw->Frame()->pack(-side => 'top', -expand => 1, -fill =>
'x');
$frame->Label(-text => "My Label",
              -anchor => 'w',
              -width => 10)->pack(-ipady => 1,
                                  -side => 'left');
my $entry = $frame->Entry(-textvariable => \$textVariable,
                          -width => 40)->pack(-side => 'left');
$frame->DropSite(-dropcommand => [\&AcceptDrop, $frame],
                 -droptypes => ('Win32'));

MainLoop;


sub AcceptDrop
{
    my ($widget, $selection) = @_;
    my $filename;

    $filename = $widget->SelectionGet(-selection => $selection,
'STRING');
    $textVariable = $filename;
}
</code>

Like I said, it is very simple.  This is what I want to be able to do in
Tkx.  Based on what you, Jeff and Laurence have posted, I have the
following, which works.  Thank you everyone very much!  Since I am stuck
using Perl 5.8.8 for other reasons, I made a directory where I put the
tkdnd files.

<code>
use strict;
use Tkx;

Tkx::lappend('::auto_path', 'D:/dss/perl/tk/tkx/lib');  # should be a
path everyone has
Tkx::package_require('tkdnd');

my $textVar = "drag here";

my $mw = Tkx::widget->new(".");
my $entry = $mw->new_entry(-name => ".current_dir", -textvariable =>
\$textVar);
$entry->g_pack(qw '-fill both -expand true');

Tkx::tkdnd__drop___target_register($entry,'*');
Tkx::bind ($entry, '<<Drop:DND_Files>>',  [ sub { AcceptDrop(shift); },
Tkx::Ev("%D")]);

Tkx::MainLoop;

sub AcceptDrop
{
    $textVar = shift;
    print "in AcceptDrop with '$textVar'\n";
}
</code>

Dave

-----Original Message-----
From: Konovalov, Vadim (Vadim)** CTR **
[mailto:vadim.konova...@alcatel-lucent.com] 
Sent: Monday, February 22, 2010 4:11 PM
To: Swingle David-QWHM86; Jeff Hobbs
Cc: tcltk@perl.org
Subject: RE: Drag-n-Drop in Perl/Tkx

> So, is there any solution to getting Drag and Drop to work in 
> Perl/Tkx, in Windows, with Perl 5.8.8?  Is there a way to interface to

> Perl/Tk from Tkx?  Drag and Drop in Perl/Tk is simple and I can do 
> that, but I'd

To the best of my knowledge, Perl/Tk does not allow extra-application
drag-n-drop.
Maybe I am wrong and not aware of something obvious 

for example I see on my system
D:\perl584\site\lib\Tk\DragDrop\Win32Site.pm
and also I see
http://cpansearch.perl.org/src/SREZIC/Tk-804.028/dnd_demo in Tk
distribution, but this seemingly deals with DND inside the same
application, correct me if I am wrong.

> like to be able to use Tkx.  I can't require all the engineers to 
> download and install other packages, so I need a solution that uses 
> 5.8.8.  Or, is there a way to embed a package in my script, so that 
> only I have to download it, but it is part of my script?

IMO - yes, there are several ways to do that - you can put "tkdnd" files
around and make your app to reach them, and also you can modify "tkkit"
dll in a way that Jeff explained.

Best regards,
Vadim.

Reply via email to