Re: SimpleList drag and drop- works :-)



On Thu, 21 Sep 2006 08:32:57 +0200
"Ratcliffe, Jeffrey (Peters)" <Jeffrey Ratcliffe External eads com> wrote:

The list gets reordered but not the underlying tied array.

Any other ideas?

Doh!!!  Sorry my previous 2 posts were complete BS.
I got confused as to what was happening, and I hope
you forgive me if I sent you on the wrong track. I took a nap
and things seem clearer now. :-)

This works!!  
What I found is that the underlying array can't be changed
in the drop callback. The drop callback has to return first,
before any changes can occur. 
So what to do? I looked for the event-types
which occured right after the drop, and used a global flag.

Try this, I promise it works, but it may not be the optimum event
to look for.

#!/usr/bin/perl
use warnings;
use strict;
use Gtk2 -init;
use Gtk2::SimpleList;

my $drop = 0;  #global flag

my $win = Gtk2::Window->new;
$win->signal_connect (delete_event => sub { Gtk2->main_quit; });

my $vbox = Gtk2::VBox->new;
$win->add ($vbox);

my $slist = Gtk2::SimpleList->new ( 'Int' => 'int', 'Text' => 'text' );
@{$slist->{data}} = ( [1, 'text1'], [2, 'text2'], [3, 'text3'] );
$slist -> set_reorderable( 1 );

$slist -> signal_connect("drag_drop" => sub {
   warn "dropped!\n";
   $drop = 1;
   return 0;
});

$slist->signal_connect (event => sub {
   my ($item, $event) = @_;
   if( ($event->type eq 'focus-change') and ( $drop == 1) ) { 
            list();
            $drop = 0;
             };
   return 0;  
});

$vbox->add ($slist);

my $button = Gtk2::Button->new ( 'Print List' );
$vbox->add ($button);
$button -> signal_connect(clicked => sub {list();});

$win->show_all;
Gtk2->main;
###############################################
sub list {
 # print @{$slist->{data}},"\n"; 
   for (0..$#{$slist->{data}}) {
     warn $slist->{data}[$_][0]." ".$slist->{data}[$_][1]."\n";
   }
}





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



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]