Re: always scroll to the bottom line of a SimpleList

On Jul 20, 2006, at 6:50 PM, muppet wrote:

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
which signal should I connect to? I have tried: row-activated,

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

Very similar, as a matter of fact --- the row-inserted callback only changes with the name of the treeview variable.

#!/usr/bin/perl -w

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

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

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

my $slist = Gtk2::SimpleList->new ('' => 'int');
$slist->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.
$slist->get_model->signal_connect (row_inserted => sub {
        my ($model, $path, $iter) = @_;
        $slist->scroll_to_cell ($path);
$scroller->add ($slist);

Glib::Timeout->add (500, sub {
        push @{ $slist->{data} }, scalar @{ $slist->{data} };

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

She's obviously your child. She looks like you, she talks a lot, and most of it is gibberish.
  -- Elysse, to me, of Zella.

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