Re: treeview clearing
- From: zentara <zentara1 sbcglobal net>
- To: gtk-perl-list gnome org
- Subject: Re: treeview clearing
- Date: Tue, 21 Mar 2006 15:33:47 -0500
On Tue, 21 Mar 2006 17:48:40 +0100 (CET)
Szabó Géza <szgezu freemail hu> wrote:
and I just want to simply clear all the whole treeview.
I tried with $treestore->clear; but nothing happens.
How can this be fixed?
Your $treestore may be out of scope? Do you have warnings and
strict enabled? This works.
#! /usr/bin/perl -w
use strict;
use Gtk2 '-init';
use Glib qw/TRUE FALSE/;
my $window = Gtk2::Window->new('toplevel');
$window->signal_connect('delete_event' => sub { Gtk2->main_quit; });
$window->set_border_width(5);
$window->set_position('center_always');
my $vbox = &ret_vbox();
$window->add($vbox);
$window->show();
Gtk2->main();
sub ret_vbox {
my $vbox = Gtk2::VBox->new(FALSE,5);
my $sw = Gtk2::ScrolledWindow->new (undef, undef);
$sw->set_shadow_type ('etched-out');
$sw->set_policy ('automatic', 'automatic');
$sw->set_size_request (300, 300);
$sw->set_border_width(5);
my $tree_store = Gtk2::TreeStore->new(qw/Glib::String/);
foreach (1..30) {
my $parent_nr = $_;
my $iter = $tree_store->append(undef);
$tree_store->set ($iter,0 => "Parent $parent_nr");
foreach (1..3){
my $iter_child = $tree_store->append($iter);
$tree_store->set ($iter_child,0 => "Child $_ of Parent $parent_nr");
}
}
my $tree_view = Gtk2::TreeView->new($tree_store);
my $tree_column = Gtk2::TreeViewColumn->new();
$tree_column->set_title ("Click to sort");
my $renderer = Gtk2::CellRendererText->new;
$tree_column->pack_start ($renderer, FALSE);
$tree_column->add_attribute($renderer, text => 0);
$tree_view->append_column ($tree_column);
$sw->add($tree_view);
$vbox->pack_start($sw,TRUE,TRUE,0);
my $button = Gtk2::Button->new('Clear');
$vbox->pack_end( $button, FALSE, FALSE, 0 );
$button->signal_connect( clicked => sub{
$tree_store->clear;
} );
$vbox->show_all();
return $vbox;
}
__END__
--
I'm not really a human, but I play one on earth.
http://zentara.net/japh.html
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]