RE: Drag-n-Drop in Perl/Tkx

[email protected] ("Konovalov, Vadim (Vadim)** CTR **")
Newsgroups perl.tcltk
Message-ID <35BF8D9716175C43BB9D67CA60CC345E14C7F4F5@FRMRSSXCHMBSC2.dc-m.alcatel-lucent.com>
> Thank you again. I think we have discussed this before 
> haven't we. Can you write the smallest (complete) script to 
> show how to use tkdnd to do a simple drag and drop from say a 
> file on the desktop to a Tkx app listbox, which will show the 
> filename in the listbox?

here you go

> 
> Then, we reduce the problem to just one of installing tkdnd 
> and then packaging it with our applications. Assuming we are 
> all using something like ActiveState's PDK PerlApp program to 
> do the packaging, maybe we can come up with a nice simple solution.

first version, with more "Tcl" syntax, and I like this better;:

use strict;
use Tkx;

Tkx::eval(<<'EOS');
#the line below is just creating a widget - no "dnd" consideration
pack [entry .current_dir -textvariable ptclv_current_dir] -side left -fill x -expand 1
# and this actually makes DND work
package require tkdnd
tkdnd::drop_target register .current_dir *
bind .current_dir <<Drop:DND_Files>> {
   set ptclv_current_dir [lindex %D 0]
   puts "I have '$ptclv_current_dir'"
}
EOS

Tkx::MainLoop;



second version, with more Tkx syntax:

use strict;
use Tkx;

Tkx::package_require('tkdnd');

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

Tkx::tkdnd__drop___target_register($w_edit,'*');
Tkx::bind ($w_edit, '<<Drop:DND_Files>>', [ sub {
       $e = shift;
       print "I have '$e'\n";
}, Tkx::Ev("%D")]);

Tkx::MainLoop;

I've tested both version, they work.
If they are not working for you, this is probably due to lack of tkdnd package.

Regards,
Vadim.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.