Re: always scroll to the bottom line of a SimpleList




On Jul 20, 2006, at 6:29 PM, Dirk Koopman wrote:

This is not getting just a bit aggravating...

I presume that $cmdlist->scroll_to_cell( .. ) does what is required but
which signal should I connect to? I have tried: row-activated,
row-inserted.

This is for plain TreeView; for SimpleList it's pretty much the same.

#!/usr/bin/perl -w

use strict;
use Gtk2 -init;
use Glib ':constants';


my $window = Gtk2::Window->new;
$window->set_default_size (300, 400);

my $scroller = Gtk2::ScrolledWindow->new;
$window->add ($scroller);

my $treeview = Gtk2::TreeView->new (Gtk2::ListStore->new ('Glib::Int'));
$treeview->insert_column_with_attributes (-1, '', Gtk2::CellRendererText->new, text => 0);
$treeview->set_headers_visible (FALSE);
#
# We want to ensure that the rows we add are always visible; for example, if rows
# are appended to the model, we should scroll to the end.
# The most general approach is to assume that rows can be added to the model from # anywhere, and that you don't want to use a custom insert function to do it. # For that, we'll connect a signal to the model to update the view's scroll
# position every time a row is added.
#
$treeview->get_model->signal_connect (row_inserted => sub {
        my ($model, $path, $iter) = @_;
        $treeview->scroll_to_cell ($path);
});
$scroller->add ($treeview);

Glib::Timeout->add (500, sub {
        my $model = $treeview->get_model;
        $model->set ($model->append, 0, $model->iter_n_children (undef));
        TRUE;
});

$window->signal_connect (destroy => sub { Gtk2->main_quit });
$window->show_all;
Gtk2->main;



--
"Ghostbusters" is the best movie of this decade.
  -- Neal, circa 1996, referring to a movie released in 1984.




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