Re: SimpleList scroll to end
- From: muppet <scott asofyet org>
- To: zentara <zentara1 sbcglobal net>
- Cc: gtk-perl-list gnome org
- Subject: Re: SimpleList scroll to end
- Date: Sat, 6 Jan 2007 17:35:57 -0500
On Jan 6, 2007, at 11:50 AM, zentara wrote:
I'm hitting a mental block today.
If i have a day when that doesn't happen, i get very worried. :-P
I wanted to add a SimpleList to a ScrolledWindow,
then auto scroll to the end.
Is this auto scroll on *any* appended rows, or particular insertions?
The best, and incidentally rather easy, way is to connect to the row-
inserted signal on the model and use scroll_to_cell() with the path
of the last row. Or just place the two lines of code needed to do it
at the place where you insert the rows -- which is what i did below.
#!/usr/bin/perl
use warnings;
use strict;
use Gtk2 qw/-init/;
use Gtk2::SimpleList;
my $count = 0;
my $win = Gtk2::Window->new;
$win->signal_connect( 'destroy' => sub{exit} );
$win->set_size_request(300,200);
I think you actually want set_default_size() here, not
set_size_request() --- set_default_size() allows the user to shrink
the window, if desired, while set_size_request() will not (normally).
$win->set_position('center');
my $sw = Gtk2::ScrolledWindow->new (undef, undef);
$sw->set_policy ('automatic', 'automatic');
my $ha1 = $sw->get_vadjustment;
my $list = Gtk2::SimpleList->new('test' => 'int',);
$sw->add($list);
$win->add($sw);
$win->show_all;
Glib::Timeout->add(500, \&update, $list);
Gtk2->main;
sub update{
my $list = shift;
push @{$list->{data}},rand $count++;
# bad hack
$list->scroll_to_point(0,1000);
Nuke that line, replace with this:
# find the path of the last row in the model.
my $path = Gtk2::TreePath->new_from_indices
(scalar (@{ $list->{data} }) - 1);
# the scalar-of-array is actually just a tie() wrapper for
# n_rows = $list->get_model->iter_n_children (undef);
# now scroll to that row. let all of the other parameters
# default, because we don't need them.
$list->scroll_to_cell ($path);
return 1;
}
__END__
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]