perl Tk::DragDrop (comp.lang.perl.tk has not responded) 
Author Message
 perl Tk::DragDrop (comp.lang.perl.tk has not responded)

Yes, I know about comp.lang.perl.tk but I posted this a few days ago and
the only response I got was "yep, happens to me too".  Its still driving
me crazy.

-------

I'm going nuts with this one.

I'm on HPUX and using 5.004_04 (yes, yes, I know, but I get the same
result on 5.005) and my window manager is fvwm2.

Problem:

I have a toplevel with a text widget in it.  DragDrop works perfectly if
I keep the window the same size as it used to be.

HOWEVER!

If I resize the window (larger) while I drag the item to the
destination, it just will *not* drop in the new location, but what is
REALLY wierd is that it *will* drop in the space it WOULD HAVE BEEN IN
before I resized the window.  (In other words, if I drag the item to the
same coordinates the widget used to be at (relative to the top left
corner of the toplevel), it works fine.

IF!

I then switch to another desktop, when I switch back, it works fine.  I
overloaded Tk::DragDrop::Rect::Over to add some instrumentation code and
what is happening is that the call to $x = $site->X; is not reflecting
the new true X value until I switch desktops back and forth.

My neurons are leaking out of my ears.

Obviously, fvwm2 is doing *something* to the window when it commands it
to redraw that changes the X,Y values, BUT WHAT and how do I do the same
thing when the window gets resized?

My demo program is as follows.  To run it, invoke it and drag an
environment variable to the entry widget.  Make the window much bigger.
Drag a new environment variable to where the entry widget is NOW.  Note
how it does not work right.  Drag the environment variable to where the
entry widget USED TO BE.  Notice it works.

AARRGGGGHHHHHHH.

use Tk;
use Tk::DragDrop;
use Tk::DropSite;
use strict;
use vars qw($top $f $lb_src $lb_dest $dnd_token $top1 $f1);

$top = new MainWindow;

$top->Label(-text => "Drag items from the left listbox to the right one"
           )->pack;
$f = $top->Frame->pack;
$lb_src  = $f->Scrolled('Listbox', -scrollbars => "osoe",
-selectmode=>'extended')
  ->pack(-side => "left");

$top1 = new MainWindow;
my $text=$top1->Scrolled('Text')->pack(-side=>'top',-expand=>1,
-fill=>'both');
$f1 = $top1->Frame->pack;

$lb_dest = $f1->Scrolled('Entry', -scrollbars => "osoe")
  ->pack(-side => "left");

$lb_src->insert("end", sort keys %ENV);

# Define the source for drags.
# Drags are started while pressing the left mouse button and moving the
# mouse. Then the StartDrag callback is executed.
$dnd_token = $lb_src->DragDrop
  (-event     => '<B1-Motion>',
   -sitetypes => ['Local'],
   -startcommand => sub { StartDrag($dnd_token) },
  );
# Define the target for drops.
$lb_dest->DropSite
  (-droptypes     => ['Local'],
   -dropcommand   => [ \&Drop, $lb_dest, $dnd_token ],
  );

MainLoop;

sub StartDrag {

    my $w = $token->parent; # $w is the source listbox
    my $e = $w->XEvent;
    my $idx = $w->nearest($e->y); # get the listbox entry under cursor
    if (defined $idx) {
        # Configure the dnd token to show the listbox entry
        $token->configure(-text => $w->get($idx));
        # Show the token
        my($X, $Y) = ($e->X, $e->Y);
        $token->MoveToplevelWindow($X, $Y);
        $token->raise;
        $token->deiconify;
        $token->FindSite($X, $Y, $e);
    }

Quote:
}

# Accept a drop and insert a new item in the destination listbox.
sub Drop {

    $lb->insert("end", $dnd_source->cget(-text));
    #$lb->see("end");
Quote:
}



Wed, 10 Dec 2003 06:21:47 GMT  
 perl Tk::DragDrop (comp.lang.perl.tk has not responded)
While this has little or nothing to do with your problem, I'd like to
know why you use all global variables, not lexicals.  Also, if you used
warnings, you would realize that $text is only assigned to, and never
used again.  Also, your use of $f and $f1 seems odd... you only use the
immediately after they're assigned to, and never again.  I would have
written the program as follows:

#! perl -w
use Tk;
use Tk::DragDrop;
use Tk::DropSite;
use strict;

my $dnd_token;
WINDOW_1 : {
        my $top = MainWindow->new;
        $top->Label(-text =>
                "Drag items from the left listbox to the right one"
        )->pack;
        my $lb = $top->Frame->pack->Scrolled('Listbox',
                -scrollbars => "osoe", -selectmode => 'extended'
        )->pack(-side => "left");
        $lb->insert("end", sort keys %ENV);
        $dnd_token = $lb->DragDrop (
                -event  =>   '<B1-Motion>',
                -sitetypes =>        ['Local'],
                -startcommand => sub {
                my $token = $dnd_token;
                my $w = $token->parent; # $w is the source listbox
                my $e = $w->XEvent;
                my $idx = $w->nearest($e->y);
                # get the listbox entry under cursor
                return unless defined $idx;
                # Configure the dnd token to show the listbox entry
                $token->configure(-text => $w->get($idx));
                # Show the token
                my($X, $Y) = ($e->X, $e->Y);
                $token->MoveToplevelWindow($X, $Y);
                $token->raise;
                $token->deiconify;
                $token->FindSite($X, $Y, $e);
        } );

Quote:
} # end WINDOW_1 block.

WINDOW_2 : {
        my $top = MainWindow->new;
        $top->Scrolled('Text')->pack(
                -side=>'top', -expand=>1, -fill=>'both');
        my $lb = $top->Frame->pack->Scrolled('Entry',
                -scrollbars => "osoe")->pack(-side => "left");
        $lb->DropSite (
                -droptypes     => ['Local'],
                -dropcommand   => [ sub {
                $_[0]->insert("end", $_[1]->cget(-text));
        }, $lb, $dnd_token ] );

Quote:
} # end WINDOW_2 block.

MainLoop;
__END__

Note that this code is untested.

--
The longer a man is wrong, the surer he is that he's right.



Wed, 10 Dec 2003 14:07:37 GMT  
 perl Tk::DragDrop (comp.lang.perl.tk has not responded)

Quote:

> While this has little or nothing to do with your problem, I'd like to
> know why you use all global variables, not lexicals.  Also, if you used
> warnings, you would realize that $text is only assigned to, and never
> used again.  Also, your use of $f and $f1 seems odd... you only use the
> immediately after they're assigned to, and never again.  I would have
> written the program as follows:

While your criticism of a piece of example code I got off the web
(because the documentation of the DragDrop module is virtually
non-existent) that I hacked up just to provide a short example that
reproduces the problem (thus solving a justified critism often heard in
this group of the lack of posted source code) is accurate and I agree
with all of your points, I would like to ask one question:

Do you have any suggestions that actually relate to the post?

Quote:

> #! perl -w
> use Tk;
> use Tk::DragDrop;
> use Tk::DropSite;
> use strict;

> my $dnd_token;
> WINDOW_1 : {
>         my $top = MainWindow->new;
>         $top->Label(-text =>
>                 "Drag items from the left listbox to the right one"
>         )->pack;
>         my $lb = $top->Frame->pack->Scrolled('Listbox',
>                 -scrollbars => "osoe", -selectmode => 'extended'
>         )->pack(-side => "left");
>         $lb->insert("end", sort keys %ENV);
>         $dnd_token = $lb->DragDrop (
>                 -event  =>      '<B1-Motion>',
>                 -sitetypes =>   ['Local'],
>                 -startcommand => sub {
>                 my $token = $dnd_token;
>                 my $w = $token->parent; # $w is the source listbox
>                 my $e = $w->XEvent;
>                 my $idx = $w->nearest($e->y);
>                 # get the listbox entry under cursor
>                 return unless defined $idx;
>                 # Configure the dnd token to show the listbox entry
>                 $token->configure(-text => $w->get($idx));
>                 # Show the token
>                 my($X, $Y) = ($e->X, $e->Y);
>                 $token->MoveToplevelWindow($X, $Y);
>                 $token->raise;
>                 $token->deiconify;
>                 $token->FindSite($X, $Y, $e);
>         } );
> } # end WINDOW_1 block.
> WINDOW_2 : {
>         my $top = MainWindow->new;
>         $top->Scrolled('Text')->pack(
>                 -side=>'top', -expand=>1, -fill=>'both');
>         my $lb = $top->Frame->pack->Scrolled('Entry',
>                 -scrollbars => "osoe")->pack(-side => "left");
>         $lb->DropSite (
>                 -droptypes     => ['Local'],
>                 -dropcommand   => [ sub {
>                 $_[0]->insert("end", $_[1]->cget(-text));
>         }, $lb, $dnd_token ] );
> } # end WINDOW_2 block.

> MainLoop;
> __END__

> Note that this code is untested.

> --
> The longer a man is wrong, the surer he is that he's right.



Sat, 13 Dec 2003 00:50:47 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. RFD - comp.lang.perl.db, comp.lang.perl.network, comp.lang.perl.regex

2. Welcome to comp.lang.perl.tk

3. 2nd CFV: comp.lang.perl.tk

4. CFV: comp.lang.perl.tk

5. RFD: comp.lang.perl.tk

6. comp.lang.perl.tk FAQ part5 of 5

7. comp.lang.perl.tk FAQ part4 of 5

8. comp.lang.perl.tk FAQ part3 of 5

9. comp.lang.perl.tk FAQ part2 of 5

10. comp.lang.perl.tk FAQ part1 of 5

11. comp.lang.perl.tk FAQ part0 of 5

12. comp.lang.perl.tk FAQ part4 of 5

 

 
Powered by phpBB® Forum Software