Re: Gtk2::TreeSelection (C example)

On ons, 2002-10-30 at 23:37, Jens Luedicke wrote:

I wrote a little example in C to illustrate
the GtkTreeSelection. It just prints out "selection"
if a change happens. 

      select = gtk_tree_view_get_selection (GTK_TREE_VIEW (treeview));
      g_signal_connect (G_OBJECT (select), "changed", G_CALLBACK (tree_selection_changed_cb), NULL);

Currently it is not possible to connect a signal to an Gtk2::TreeSelection

It is actually... You can indeed connect to the "changed" signal.
However, it wont do you much good, as the methods to get the selected
row(s) hasn't been implemented.

Attached is my own test script for the TreeView/TreeSelection stuff.



use warnings;
use strict;

use Gtk2;
use Gtk2::Window;
use Gtk2::ListStore;
use Gtk2::TreeView;
use Gtk2::TreeViewColumn;
use Gtk2::CellRendererText;

Gtk2->init(\ ARGV);

$|= 1;

my $s= Gtk2::GType->STRING;
my $model = Gtk2::ListStore->new(Gtk2::GType->STRING, Gtk2::GType->STRING);
my $iter = Gtk2::TreeIter->new;

for(1..10) {

        # this works now - Göran rocks
        $model->set($iter, [0 => $_, 1 => "Item #$_"]);

my $window = Gtk2::Window->new('toplevel');
$window->signal_connect("destroy", sub { Gtk2->quit }, undef);

my $tree_view = Gtk2::TreeView->new;

# And now this works too - Martin rocks also :-)
my $selection= $tree_view->get_selection();
print "selection mode: " . ($selection->get_mode()||"undef") . "\n";
$selection->signal_connect("changed", \&changed_handler, undef);

my $cell = Gtk2::CellRendererText->new;
my $column = Gtk2::TreeViewColumn->new_with_attributes("No", $cell, 'text' => 0);
my $column1 = Gtk2::TreeViewColumn->new_with_attributes("Text", $cell, 'text' => 1);



sub changed_handler {
        my($selection)= @_;

        # this should get the selected rows - but thats not done yet
        print "selection changed\n";

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