#!/usr/bin/perl -w
#----------------------------------------------------------------------
# hello-world.pl
#
# A simple exapmle of Gtk2/GladeXML
#
# Copyright (C) 2003 Bruce Alderson
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the
# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
# Boston, MA 02111-1307, USA.
#
#----------------------------------------------------------------------
use strict;
use warnings;
use Gtk2 '-init'; # auto-initializes Gtk2
use Gtk2::GladeXML;
my $glade;
my $window;
my $fortune;
# Some text to display in the label (notice the embedded pango-markup)
my @fortunes = (
"This is an example\nGtk2::GladeXML program.",
"Data-driven is good!",
"Blue text is fun!",
"Label-controls can handle simple1 markup2.",
"GladeXML is as simple as:\n\n\$glade = \nGtk2::GladeXML->new(\n\"hello-world.glade\");",
"42",
"A Glade-XML\nsample program\nby mx\@warpedvisions.org"
);
my $pos = -1;
# This example includes the Glade XML at the end of the script
# in the __DATA__ section.
# 'Load' glade-xml from DATA section
my $glade_data; {local $/ = undef; $glade_data = ;}
# Load the UI from xml definition
$glade = Gtk2::GladeXML->new_from_buffer($glade_data);
# Connect the signals
$glade->signal_autoconnect_from_package('main');
# Cache some controls in perl-variables
$window = $glade->get_widget('main');
$fortune = $glade->get_widget('fortune_label') or die;
# Start it up
Gtk2->main;
exit 0;
#----------------------------------------------------------------------
# Signal handlers, connected to signals we defined using glade-2
# Handle next-button click: show next message
sub on_next_button_clicked {
$pos++; $pos %= $#fortunes + 1;
$fortune->set_markup($fortunes[$pos]);
}
# Handle previous-button click: show prev message
sub on_back_button_clicked {
$pos--; $pos %= $#fortunes + 1;
$fortune->set_markup($fortunes[$pos]);
}
# Handles window-manager-quit: shuts down gtk2 lib
sub on_main_delete_event {Gtk2->main_quit;}
# Handles close-button quit
sub on_close_button_clicked {on_main_delete_event;}
#----------------------------------------------------------------------
# We can append the glade file here instead of loading from file
#----------------------------------------------------------------------
__DATA__
True
Gtk2::GladeXML-Power
GTK_WINDOW_TOPLEVEL
GTK_WIN_POS_NONE
False
True
False
True
False
0
300
225
True
True
<big><b>Hello World!</b></big>
True
True
GTK_JUSTIFY_CENTER
True
True
0.5
0.5
0
0
0
True
True
True
0
False
False
True
GTK_BUTTONBOX_DEFAULT_STYLE
0
True
True
True
gtk-go-back
True
GTK_RELIEF_NORMAL
True
True
True
gtk-close
True
GTK_RELIEF_NORMAL
True
True
True
gtk-go-forward
True
GTK_RELIEF_NORMAL
0
False
True