gnubbs has asked for the wisdom of the Perl Monks concerning the following question:

Solution Found!See Bottom of post

After being gently guided (Formatting Gtk Pages) into using Gtk2 instead of Gtk, I have one more question for everyone.

Looking at Gtk2, I quickly hone in on Gtk2::SimpleList as something that could greatly easy my GUI design. It is nearly exactly what I was attempting to do in Gtk. Nice.

I quickly throw together the code to build my SimpleList:

$slist = Gtk2::SimpleList->new ( 'Enabled' => 'bool', 'Scanner' => 'text', 'Media' => 'text', 'Description' => 'text' ); @{$slist->{data}} = ( ['1','test','CDR','Long Description'], ['0','test 2','CDR'], ['0','test 3','CDR'], );

And I have my basic interface. Next, I have to setup a callback so that anytime the checkbox in a row changes state something happens. This is where things start to fall apart. I try:

$slist->signal_connect( 'row-activated', sub { printDebugWindow("Click +ed!") });

But this is only called when the row is double clicked, not when someone simply clicks on the checkbox. I have looked through the signals for SimpleList and I can't seem to find one that I am looking for. I am thinking that since this is just a tied array, there might be some way to access the underlying objects. But, I have not worked much with tied vars and can't seem to figure it out. I tried:

$slist->{data}[0][0]->signal_connect( 'toggled', sub { printDebugWindo +w("Clicked!") });

But that definately doesn't work. (For some reason I expected it wouldn't since I was pretty much just making up syntax at that point.) Well, I am at a loss at this point. I have read all the documentation that I could find on the Perl-Gtk2 page, the Gtk2 page, and in the pods but I am missing something.

Please, monks, light this path for me.

gnubbs

A solution

Since SimpleList is just an interface to TreeModel, I was able to accomplish what I needed by delving down into the TreeModel itself.

my $tree_model = $slist->get_model(); $tree_model->signal_connect( row_changed => sub { printDebugWindow("Cl +icked") });

This works because the SimpleLists in this GUI only have one editible field -- the bool checkbox. So, this signal is only emitted when someone toggles the checkbox. Thanks again for everyone's help, and please let me know if the path I have found is not a good one.

Replies are listed 'Best First'.
Re: Gtk2::SimpleList Checkboxes
by kvale (Monsignor) on Mar 15, 2005 at 17:53 UTC
    In your first signal connect example, that should be row_activated, not row-activated.

    -Mark

      Well on my system either of those actually work when called as it is in my example. If instead I want to call it as:
      $slist->signal_connect( row_activated => sub { printDebugWindow("Click +ed!") });
      then you are correct. Thanks. gnubbs
Re: Gtk2::SimpleList Checkboxes
by Anonymous Monk on Mar 30, 2005 at 02:44 UTC
    SimpleList is designed to give you a list very simply. My standard line is that for somethng like this, your usage is no longer Simple, and you'll want to use TreeView and ListStore directly. To hook into the change of the checkbutton, you need to connect to the "toggled" signal of the CellRendererToggle for the appropiate column. This is something you do as part of setting up editable cells. If you look at the source of SimpleList, you'll see in the setup that the CellRendererToggle's "toggle" signal is set up to modify the model when toggled. You'll need to fetch the cellrenderers for the column and connect your own signal handler. ... Or just create the view for yourself and you'll have the CellRenderer. This isn't really a perl issue at all, it's just a gtk+ thing.
      I am not sure that I buy your argument in this case. SimpleList takes care of a lot behind the scenes, so I am not sure I should throw it out just because I am doing something a little bit more complicated with it. I think the end result - using SimpleList to build the model and then delving into the TreeModel backend to do the hard stuff. As far as it not being a perl thing, well, I would argue that since I am using a Perl API that it is at least somewhat of a perl thing. At least enough of a perl thing to try out the sanity of perlmonks before the chaos of the mailing lists.