logo       

simplelist and custom cell renderers: msg#00159

Subject: simplelist and custom cell renderers
Hello!

I'm building an application which displays a list, using SimpleList, of
modules, each row has the module name and a checkbox which tells whether
to use the module on that row. The catch is that I must use checkboxes
with the 'inconsistent' property to indicate modules that must be forced
due to dependencies.

So at first I created a new column type to display the checkbox with the
inconsistent state base on the data placed on the simplelist:

   Gtk2::SimpleList->add_column_type('checkbox3',
         type     => 'Glib::Scalar',
         renderer => 'MyCheckboxCellRenderer',
         attr     => sub {
              my ($treecol, $cell, $model, $iter, $col_num) = @_;

          my $val = $model->get ($iter, $col_num);
          $cell->set (inconsistent => ($val < 0), active => $val > 0);
      }
    );

Trouble is, now I couldn't toggle the checkboxes. So I headed off to
create a new cell renderer. I managed to make them togglable, but now I
can't figure out how to change the data back in the list. Actually, I
can't really toggle them properly since I'm using the hack of calling
$simplelist->get_selected_indices to find which row is selected, so I
can toggle only the row that I clicked previously.

There has to be a simpler way, but I can't figure out which of the rows
is being clicked on. How do I find that out?

Here's my code for the cell renderer:

package MyCheckboxCellRenderer;

use strict;

use Gtk2;

use Glib::Object::Subclass
   Gtk2::CellRendererToggle::,
   signals => { },
   properties => [ ];

sub ACTIVATE {
   my $self = shift;
   my ($cell, $event, $widget, $path, $background_area, $cell_area,
$flags) = @_;

   my $idx = ($event->get_selected_indices) [0];
   if ($event->{data}->[$idx]->[0] >= 0) { # toggle?
       $event->{data}->[$idx]->[0] = ($event->{data}->[$idx]->[0] + 1) % 2;
   }

   return 1;
}

Thanks in advance!

--
Cristóvão Dalla Costa
cbraga@xxxxxxxxxxxx


<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

Recently Viewed:
science.linguis...    culture.sf.lite...    video.mplayer.c...    yellowdog.gener...    ietf.rfc822/199...    emacs.help/2002...    redhat.release....    kernel.speakup/...    java.openejb.de...    debian.devel.gt...    xfree86.newbie/...    bug-tracking.ma...    pam/2003-05/msg...    games.devel.ope...    user-groups.lin...    music.pancham/2...    network.mq.deve...    web.html.genera...    arklinux.bugs/2...    linux.ecasound/...    qnx.openqnx.dev...    org.user-groups...    file-systems.sf...    trustix.contrib...   
Home | blog view | USPTO Patent Archive | advertise | OSDir is an inevitable website. super tiny logo

Free Magazines

Cisco News
Receive a free quarterly e-newsletter with exclusive articles on how Cisco IT uses its own products and solutions to enable the business.
subscribe

Systems Management News, the newspaper for IT systems administration and data center managers! Each issue of Systems Management News is chock-full of news and analysis to help you understand what's happening in your field.
subscribe

The Enterprise Newsweekly eWeek is the essential technology information source for builders of e-business.
subscribe

Oracle Magazine Oracle Magazine contains technology strategy articles, sample code, tips, Oracle and partner news, how to articles for developers and DBAs, and more. Oracle (NASDAQ: ORCL) is the world's largest enterprise software company.
subscribe

Total Telecom Total Telecom is "The Economist of the communications industry".
subscribe