Perl GTK
Perl GTK
GUI Programming
with Perl / GTK
Anuradha Weeraman
[email protected]
http://www.linux.lk/~anu/
23 May 2006
Contents
●
Overview
●
GUI Toolkits
●
Hello World
●
Layout
●
C > Perl
●
GUI Builders
●
CPAN
Overview
●
What's a widget?
●
What's a GUI?
●
What's a GUI toolkit?
●
What's GTK?
●
What's GTKPerl?
●
How is GUI programming different?
GUI Toolkits
●
Athena Widget Library
●
OSF Motif
●
Xforms
●
FLTK
●
the GIMP Toolkit
●
Qt Toolkit
●
LessTif
Hello World
#!/usr/bin/perl
$window = Gtk2::Window->new;
$window->add ($label);
$window->show_all;
Gtk2->main;
Hello World – Part 2
#!/usr/bin/perl
$window = Gtk2::Window->new;
$window->signal_connect(
destroy => sub { Gtk2->main_quit }
);
$window->add ($label);
$window->show_all;
Gtk2->main;
Hello World – Part 3
#!/usr/bin/perl
$window = Gtk2::Window->new;
$window->set_title("Hello");
$window->signal_connect(destroy => sub { Gtk2->main_quit });
$window->add ($button);
$window->show_all;
Gtk2->main;
Hello World – Part 4
#!/usr/bin/perl
sub quit_program {
Gtk2->main_quit;
print "Program has stopped.\n";
}
$window = Gtk2::Window->new;
$window->set_title("Hello");
$window->signal_connect(destroy => \&quit_program);
$window->add ($button);
$window->show_all;
Gtk2->main;
Layout HBox
$window = Gtk2::Window->new;
$hbox = Gtk2::HBox->new;
$window->add ($hbox);
Layout VBox
$window = Gtk2::Window->new;
$vbox = Gtk2::VBox->new;
$window->add ($vbox);
C > Perl
●
Consistent naming
●
Onetoone mapping
●
Objectoriented
●
Transparently handles typecasting, reference
counting etc.
●
Exceptions allowed where Perl capabilities
afford a cleaner API – multiple return values,
string / array function parameters
Function Name Translation
g_ -> Glib
gtk_window_set_title
(GtkWindow *window, gchar string)
becomes
$window->set_title ($string)
Function Parameters
GList replaced by variable number of arguments:
gtk_window_set_icon_list (GtkWindow * window, GList * list)
$window->set_icon_list (@icons)
Same with the array moved to the end of the parameter list:
gtk_list_insert_items (GtkList *list, GList *items, gint position)
$list->insert_items ($position, @items)
Array parameter and integer with the size of that array, replaced by variable number
of arguments:
gtk_curve_set_vector (GtkCurve *curve, int veclen, gfloat vector[])
$curve->set_vector (@vector)
Same with the array moved to the end of parameter list:
gtk_item_factory_create_items (GtkItemFactory * ifactory,
guint n_entries, GtkItemFactoryEntry * entries,
gpointer callback_data)
$itemfactory->create_items ($callback_data, @entries)
Return Values
Download foomodule.tar.gz
$ tar zxvf foomodule.tar.gz
$ cd foomodule
$ perl Configure.PL
$ make
$ make test
# make install
OR
use CPAN.
CPAN
●
CPAN.org
●
Comprehensive Perl Archive Network
●
Mirrors all over the world
●
Command line shell
●
Bundled with standard Perl distribution
●
Intuitive module management
CPAN
perl MCPAN e shell
cpan> install Term::ReadKey
cpan> install Term::ReadLine
cpan> install Bundle::CPAN
cpan> h or ?
Thank You!
For more information, visit:
http://www.gtk.org
http://www.gtk2perl.sourceforge.net
You can download this presentation
from http://www.linux.lk/~anu