SimpleList: connecting a signal to a CellRendererToggle



Hello,

First of all, I'm nto an experienced Perl programmer. I just learned the
basics of Perl-Gtk2 some days ago. I had no problems making what I
wanted (thanks to the tutorial), but I'm having some trouble with SimpleList.

Here's the deal: I have three columns of ticking boxes. When clicking on
a tick in the first column, it should untick the 2nd column and tick the
3rd one (it's an example; in reality, the behaviour should be à la radio
button, but I would prefer to have ticking boxes). My idea was then to
create a column type and connect a signal to the column.

Here's the code:

Gtk2::SimpleList->add_column_type(
                                  'mybool',
                                  type     => 'Glib::Boolean',      
                                  renderer => 'Gtk2::CellRendererToggle',
                                  attr     => 
                                  sub {
                                     my ($column, $cell, $model, $iter, $nb_col) = @_;
                                     
                                     my $renderer = $column->get_cell_renderers;
                                     $renderer->set('activatable' => 1);

                                     $renderer->signal_connect(toggled => sub {
                                        my ($renderer, $row, $col) = @_;
                                        my $iter = $model->iter_nth_child(undef, $row);
                                        my $val = $model->get($iter, $col);

                                        $model->set($iter, $col, !$val);
                                        $model->set($iter, $col+1, 0);
                                        $model->set($iter, $col+2, 1);
                                        print("$row - $col\n");
                                        print("Valeur: " . $model->get($iter, $nb_col) . "\n");
                                     }, $nb_col);
                                  }
                                  );

There are 2 problems with it: 

- clicking on a tick box in the first column do untick and tick the
other columns, but the clicked tick box doesn't look like ticked (it
stays empty).
- for an unknow reason, clicking only once outputs a lot of information
(as stated in the two print lines at the end of the code). Worse, the
last print gives me a "Valeur: 0" whereas it should be 1 !

I'm using Perl-Gtk2 1.021, Perl 5.8.3, libgtk-2.2.

Thanks in advance for any solution you'll be able to give.

-- 
GrÃgory SCHMITT <mailto:gregory schmitt free fr>
ãããççç




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