Re: which widget to use



On Sun, 2002-08-11 at 19:08, Jens Wilke wrote:
Hi,

i'd like to make place a widget on the right side of the header of a notebook 
(to insert a button to close a tab, like in mozilla) Is there any possibility 
to do that?

Thks, Jens


You can use a Gtk::HBox instead of a Gtk::Label for the tab label and
just pack the label and button into it. 

<code>
#!/usr/bin/perl

use strict;
use warnings;

use Gtk;

Gtk->init;

my $window   = Gtk::Window->new;
my $vbox     = Gtk::VBox->new;
my $add_tab  = Gtk::Button->new("Add tab");
my $notebook = Gtk::Notebook->new;

$window->set_usize(640,480);

$window->add($vbox);
$vbox->pack_start($add_tab,  0, 0, 0);
$vbox->pack_start($notebook, 1, 1, 0);

$window->show_all;

$window->signal_connect('destroy', sub { Gtk->main_quit });
{
        my $tab = 1;
        $add_tab->signal_connect(
                'clicked',
                sub {
                        make_tab($notebook, $tab++)
                }
        );
}

Gtk->main;

sub make_tab {
        my ($nb, $tablabel) = @_;
        my $child = Gtk::VBox->new;
        my $hbox  = Gtk::HBox->new;
        my $label = Gtk::Label->new($tablabel);
        my $close = Gtk::Button->new("X");

        $hbox->add($label);
        $hbox->add($close);

        $hbox->show_all;

        $close->signal_connect(
                'clicked',
                sub {
                        $nb->remove_page($nb->page_num($child));
                }
        );

        $nb->add($child);

        $nb->set_tab_label(
                $nb->get_nth_page($nb->page_num($child)),
                $hbox
        );

        $nb->show_all;
}
</code>
-- 
Today is Pungenday the 19th day of Bureaucracy in the YOLD 3168
Grudnuk demand sustenance!

Missile Address: 33:48:3.521N  84:23:34.786W




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