Thanks. That helped a little. But, the code you have doesn't seem to do anything about the drop site. The Tkx::DropSite_Register() call has a -dropcmd that simply prints "dropbuttonCmd", but that is never printed. I tried creating an entry widget and registering it as a drop site and was not able to get the -dropcmd or -dropovercmd commands to fire.

So, I'm still unable to do what I would like to do: drag a file from windows explorer onto a widget and have the widget know the name of the file that was dropped.

I took the code you had and modified it. I took out the comments that were from the original TCL BWidget code (for simplicity) and I specified subs for the various drag/drop commands. Also took out the extraneous topwindow. Also, when the -draginitcmd sub is called it must return 3 things (type of data, list of operations, and the data), so I added a return to my sub. The data part is then successfully passed to the -dragendcmd sub, but I'm not clear as far as what should be specified for the type and list of operations.

Seems close, but still doesn't work.

Dave

My version that does 'drag' but not 'drop':

#!/usr/bin/perl -- use strict; use warnings; use Tkx; my $text = "abc"; Main(@ARGV); exit(0); sub Main { local $Tkx::TRACE = 64; Tkx::package_require('tile'); Tkx::package_require('BWidget'); eval { Tkx::tile__setTheme('xpnative'); 1 } || eval { Tkx::ttk__setTheme('xpnative'); 1 }; drawGUI(); Tkx::MainLoop(); } sub drawGUI { our $t = Tkx::widget->new("."); $t->g_wm_title("BWidgets Demo for Drag 'n Drop enabled buttons."); $t = $t->new_ttk__frame( -name => '.f' ); $t->g_pack(qw '-fill both -expand true'); for my $i ( 1 .. 4 ) { my $m = (qw' 0 Drag and Drop Demo ')[$i]; my $bb = $t->new_ttk__button(-name => "$t.b$i", # auto-name + is .b .b2 .b3... -image => Tkx::Bitmap__get( (qw'0 + new file copy redo ')[$i] ), -text => "$i.) $m", -command => sub { print "$m\n"; } +); $bb->g_pack; } enableDnD( map { "$t.b$_" } 1 .. 4 ); $t->new_ttk__button(-text => "Exit Demo", -command => [ \&Tkx::destroy, '.' ])->g_pack(q +w '-padx 5 -pady 5'); my $entry = $t->new_ttk__entry(-width => 20, -textvariable => \$te +xt); Tkx::DropSite__register($entry, -dropcmd => \&dropcmdEntry, -dropovercmd => \&dropovercmdEntry, -droptypes => {"text", {"copy", "none"}}); $entry->g_pack(qw '-padx 5 -pady 5'); } sub enableDnD { for my $w (@_) { Tkx::DropSite__register($w, -dropcmd => \&dropButtonCmd); Tkx::DragSite__register($w, -dragevent => 1, -draginitcmd => \&dragInitCmd, -dragendcmd => \&dragEndCmd); } } sub dropButtonCmd { my @args = (@_); print "in dropButtonCmd\n"; for (my $i = 0; $i < scalar @args; $i++) { print "arg $i = '$args[$i]'\n" if defined $args[$i]; } return "abc"; } sub dragInitCmd { my @args = (@_); print "in dragInitCmd\n"; for (my $i = 0; $i < scalar @args; $i++) { print "arg $i = '$args[$i]'\n" if defined $args[$i]; } my $data = "\"Button " . $args[3] . "\""; return ("text", ("copy"), $data); } sub dragEndCmd { my @args = (@_); print "in dragEndCmd\n"; for (my $i = 0; $i < scalar @args; $i++) { print "arg $i = '$args[$i]'\n" if defined $args[$i]; } } sub dropcmdEntry { print "dropcmdEntry\n"; return "entry"; } sub dropovercmdEntry { print "dropovercmdEntry\n"; }

In reply to Re^6: Drag and Drop in Tkx by David S
in thread Drag and Drop in Tkx by David S

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.