Re: Notebook focus



Does this do what you wanted?  I think your problem came down to not declaring
the variables in the loop as my variables.  This is why you should always use
the strict pragma.  It forces you to decided where and how long your variables
should live.  By the way, why are you using tables?  Normally I wouldn't have
used any packing boxes for the Gtk::Notebook and a Gtk::VBox for the notebook page.


<code>
#!/usr/bin/perl

use strict;    #always use strict
use warnings;  #use warnings at least during development

use Gtk;

#constants are better than variables
use constant false => 0;
use constant true  => 1;

Gtk->init;

my $window = Gtk::Window->new("toplevel");
$window->signal_connect('delete_event', sub { Gtk->main_quit });

my $table = Gtk::Table->new(3, 6, false);
$window->add($table);

# Create a new notebook, place the position of the tabs
my $notebook = Gtk::Notebook->new;
$notebook->set_tab_pos('top');
$table->attach_defaults($notebook, 0, 6, 0, 3);

# Let's append a bunch of pages to the notebook
for my $i ( 0..4 ) {
        my $table = Gtk::Table->new(5, 6, false);
        my $start = Gtk::Button->new("START");
        my $text  = Gtk::Text->new;

        $table->attach($start, 0, 1, 0, 1, 'fill', 'shrink', 0, 0);
        $table->attach($text, 0, 6, 1, 5, 'fill', 'shrink', 0, 0);
        $notebook->append_page($table, Gtk::Label->new("tab $i"));

        $start->signal_connect(
                "clicked",
                sub {
                        #this is a closure so $text will live as long as this
                        #something references this anonymous subroutine
                        $text->insert(undef, undef, undef, "This is a test\n");
                }
        );

}

$window->show_all;

Gtk->main;
</code>



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