Re: SimpleList drag and drop



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

For the attached code, at the dropped signal, the array is still in its
original order. Only when pressing the button (or redoing the drop) is
the new order displayed.

Maybe you could put a
Gtk2->main_iteration while Gtk2->events_pending;
in your callback?

Thanks for trying, but this doesn't make any difference.

The list gets reordered but not the underlying tied array.

Any other ideas?

I was diddling with this today. Check out the difference between
list1() and list().  The


#!/usr/bin/perl -w

use strict;
use Gtk2 -init;
use Gtk2::SimpleList;

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";
 list();
});

$vbox->add ($slist);

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

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

##############################################
sub list{
   Gtk2->main_iteration while Gtk2->events_pending;
  my @indices = $slist -> get_selected_indices;
  print "@indices\n";
  
  foreach my $i (@indices) {
                print $i . "\n"; # I'd rather print the actual data here.
                print "@{ $slist->{ data }[$i] }\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]