Re: SimpleList drag and drop



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?

Hi, I further refined my previous example, to the bare minimum
needed to make it work. Notice in the list() sub, all you need to do
is sort of "touch" the tied array to make it work.

I've seen this before in some tied variable systems, where you have to
read the tied variable at least once before it is updated.  Notice
the foreach loop thru the indices is needed, even though the {}
is empty, in the list() sub.

Maybe muppet knows what the real-deal is. :-)

#!/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 {
  print @{$slist->{data}},"\n"; 
   for (0..$#{$slist->{data}}) {
     warn $slist->{data}[$_][0]." ".$slist->{data}[$_][1]."\n";
   }
}

##############################################
sub list{
  my @indices = $slist -> get_selected_indices;
  foreach my $i (@indices) {}
}




-- 
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]