Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

Drag & Drop in a HList
Hi Folks,

has anyone a little code snippet, that demonstrates how i can move a HList
Entry per Drag & Drop in another HList ??

Thanks
Pit


Report this thread to moderator Post Follow-up to this message
Old Post
Pit
11-19-04 01:58 PM


Re: Drag & Drop in a HList
On Fri, 19 Nov 2004 05:14:57 -0500, "Pit" <pharrendorf@am-soft.de>
wrote:

>Hi Folks,
>
>has anyone a little code snippet, that demonstrates how i can move a HList
>Entry per Drag & Drop in another HList ??
>
>Thanks
>Pit

Here is an example I have working, adapted from an example I
saw on groups.google.

#!/usr/bin/perl -w
use Tk;
use Tk::DragDrop;
use Tk::DropSite;
use Tk::HList;
use strict;
use vars qw($top $f $lb_src $lb_dest $dnd_token $drag_entry);

$top = new MainWindow;

$top->Label( -text => "Drag items from the left HList to the right one"
)->pack;
$f      = $top->Frame->pack;

$lb_src = $f->Scrolled(
'HList',
-scrollbars => "osoe",
-selectmode => 'dragdrop'
)->pack( -side => "left" );

$lb_dest = $f->Scrolled(
'HList',
-scrollbars => "osoe",
-selectmode => 'dragdrop'
)->pack( -side => "left" );

my $i = 0;
foreach ( sort keys %ENV ) {
$lb_src->add( $i++, -text => $_ );
}

# 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 ($token) = @_;
my $w       = $token->parent;    # $w is the source hlist
my $e       = $w->XEvent;
$drag_entry = $w->nearest( $e->y );    # get the hlist entry under
cursor
if ( defined $drag_entry ) {

# Configure the dnd token to show the hlist entry
$token->configure( -text => $w->entrycget( $drag_entry, '-text'
) );

# Show the token
my ( $X, $Y ) = ( $e->X, $e->Y );
$token->MoveToplevelWindow( $X, $Y );
$token->raise;
$token->deiconify;
$token->FindSite( $X, $Y, $e );
}
}

# Accept a drop and insert a new item in the destination hlist and
delete
# the item from the source hlist
sub Drop {
my ( $lb, $dnd_source ) = @_;
$lb->add( $drag_entry, -text => $dnd_source->cget( -text ) );
$lb_src->delete( "entry", $drag_entry );
$lb->see($drag_entry);
}

__END__


--
I'm not really a human, but I play one on earth.
http://zentara.net/japh.html

Report this thread to moderator Post Follow-up to this message
Old Post
zentara
11-19-04 08:58 PM


Re: Drag & Drop in a HList
Thanks,

it works fine

Pit


Report this thread to moderator Post Follow-up to this message
Old Post
Pit
11-22-04 02:02 PM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

PerlTk archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 06:33 AM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.