So, basicly, how can I pass the reference to the label I'm DRAGING? :)

I admit that this is confusing at first.  But when you think about it, it makes perfect sense.

What's happening is that you have 3 separate callbacks to hover_over_drop, so when you leave pane 1 to enter pane 2, you're now executing the callback on behalf of the second invokation of DropSite.

To get around this, you'll need to do 2 things.  First, create a global variable "$drag_obj" at the top of the program and assign it to zero.

my $drag_obj = 0;
Next, in the subroutine hover_over_drop(), the very first time that the subroutine is called, you assign $drag_obj to the label being dragged:
sub hover_over_drop { my ($label_obj, $b_entry, $x_pos) = @_; + $label_obj->configure(-bg => $b_entry == 1 ? 'gray' : 'lightgray') +; + if ($b_entry) { if (!$drag_obj) { print "First time: "; $drag_obj = $label_obj; } else { print " Next time: "; } printf "Dragging(%s) Callback for(%s)\n", $drag_obj->cget(-text), $label_obj->cget(-text); } }
Finally, you have to release the global variable $drag_obj when it's actually dropped.  This you can do in perform_drop():
sub perform_drop { my ($drop_site, $x_pos, $drop_obj) = @_; + $drag_obj or die "Whoops -- \$drag_obj undefined (shouldn't happen +!)\n"; printf "Drop label: %s\n", $drag_obj->cget(-text); $drag_obj = 0; }

I did a small amount of testing to verify that I couldn't drag the label from one column and have hover_over_drop() pick up the wrong label.  It seems to work reliably with my changes applied.

As for the resize issue, see if you can make some progress on that yourself, and let me know if you need more help if you get stuck.  It's not obvious to me why the resize anomaly is even occurring in the first place, but it clearly is.

One final suggestion -- when I "googled" for "perl/tk dropsite documentation", I found one link which said:

More information can be found in the DragDrop directory in the source +distribution of Perl/Tk. There are some sample scripts: local_test, m +otion_test and site_test. And if there are still open questions: use +the force, read the source!
If you haven't already done so, see if those sample scripts are helpful.

Good luck!


s''(q.S:$/9=(T1';s;(..)(..);$..=substr+crypt($1,$2),2,3;eg;print$..$/

In reply to Re^5: Drag & Drop Problem by liverpole
in thread Drag & Drop Problem by Ace128

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.