#! /usr/bin/perl

use warnings;
use strict;

use Gtk2 '-init';
use Gtk2::GladeXML;

my $glade=Gtk2::GladeXML->new('gtk2_switch_hide.glade');

$glade->get_widget('window')->signal_connect('delete_event' => sub { Gtk2->main_quit; });
$glade->get_widget('toggle')->signal_connect('toggled' => \&toggled);

#our main event-loop
Gtk2->main();

sub toggled {
    my $button=shift;

    my ($to_show, $to_hide);
    if($button->get_active) {
        $to_show=$glade->get_widget('hbox2');
        $to_hide=$glade->get_widget('hbox1');
    } else {
        $to_show=$glade->get_widget('hbox1');
        $to_hide=$glade->get_widget('hbox2');
    }

    $to_show->show;
    $to_hide->hide;

    return 1;
}
