#!/usr/bin/perl -w use Gtk; use strict; set_locale Gtk; init Gtk; my $false = 0; my $true = 1; my $window; my $button; my $table; my $notebook; my $frame; my $label; my $checkbutton; my $i; my $bufferf; my $bufferl; $window = new Gtk::Window( "toplevel" ); $window->signal_connect( "delete_event", sub { Gtk->exit( 0 ); } ); $window->border_width( 10 ); $table = new Gtk::Table( 3, 6, $false ); $window->add( $table ); # Create a new notebook, place the position of the tabs $notebook = new Gtk::Notebook(); $notebook->set_tab_pos( 'top' ); $table->attach_defaults( $notebook, 0, 6, 0, 1 ); $notebook->show(); # Let's append a bunch of pages to the notebook for ( $i = 0; $i < 5; $i++ ) { $bufferf = "Append Frame " . ( $i + 1 ); $bufferl = "Page " . ( $i + 1 ); $frame = new Gtk::Frame( $bufferf ); $frame->border_width( 10 ); $frame->set_usize( 100, 75 ); $frame->show(); $label = new Gtk::Label( $bufferf ); $frame->add( $label ); $label->show(); $label = new Gtk::Label( $bufferl ); $notebook->append_page( $frame, $label ); } # Now let's add a page to a specific spot $checkbutton = new Gtk::CheckButton( "Check me please!" ); $checkbutton->set_usize( 100, 75 ); $checkbutton->show(); $label = new Gtk::Label( "Add Page" ); $notebook->insert_page( $checkbutton, $label, 2 ); # Now finally let's prepend pages to the notebook for ( $i = 0; $i < 5; $i++ ) { $bufferf = "Prepend Frame " . ( $i + 1 ); $bufferl = "Page " . ( $i + 1 ); $frame = new Gtk::Frame( $bufferf ); $frame->border_width( 10 ); $frame->set_usize( 100, 75 ); $frame->show(); $label = new Gtk::Label( $bufferf ); $frame->add( $label ); $label->show(); $label = new Gtk::Label( $bufferl ); $notebook->prepend_page( $frame, $label ); } # Set what page to start at (page 4) $notebook->set_page( 3 ); # Create a bunch of buttons $button = new Gtk::Button( "Close" ); $button->signal_connect( "clicked", sub { Gtk->exit( 0 ); } ); $table->attach_defaults( $button, 0, 1, 1, 2 ); $button->show(); $button = new Gtk::Button( "Next Page" ); $button->signal_connect( "clicked", sub { $notebook->next_page(); } ); $table->attach_defaults( $button, 1, 2, 1, 2 ); $button->show(); $button = new Gtk::Button( "Prev Page" ); $button->signal_connect( "clicked", sub { $notebook->prev_page(); } ); $table->attach_defaults( $button, 2, 3, 1, 2 ); $button->show(); $button = new Gtk::Button( "Tab Position" ); $button->signal_connect( "clicked", \&rotate_book, $notebook ); $table->attach_defaults( $button, 3, 4, 1, 2 ); $button->show(); $button = new Gtk::Button( "Tabs/Border On/Off" ); $button->signal_connect( "clicked", \&tabsborder_book, $notebook ); $table->attach_defaults( $button, 4, 5, 1, 2 ); $button->show(); $button = new Gtk::Button( "Remove Page" ); $button->signal_connect( "clicked", \&remove_book, $notebook ); $table->attach_defaults( $button, 5, 6, 1, 2 ); $button->show(); $table->show(); $window->show(); main Gtk; exit( 0 ); ### Subroutines # This function rotates the position of the tabs sub rotate_book { my ( $button, $notebook ) = @_; my %rotate = ( top => 'right', right => 'bottom', bottom => 'left', left => 'top' ); $notebook->set_tab_pos( $rotate{ $notebook->tab_pos } ); } # Add/Remove the page tabs and the borders sub tabsborder_book { my ( $button, $notebook ) = @_; my $tval = $false; my $bval = $false; if ( $notebook->show_tabs == 0 ) { $tval = $true; } if ( $notebook->show_border == 0 ) { $bval = $true; } $notebook->set_show_tabs( $tval ); $notebook->set_show_border( $bval ); } # Remove a page from the notebook sub remove_book { my ( $button, $notebook ) = @_; my $page; $page = $notebook->get_current_page(); $notebook->remove_page( $page ); # Need to refresh the widget -- This forces the widget to redraw itself. $notebook->draw( undef ); } # END EXAMPLE PROGRAM