NAME

Acme::Gtk2::Ex::Builder - Funny Gtk2 Interface Design Module

VERSION

version 0.002

SYNOPSIS

use strict;
use warnings;
use Gtk2 -init;
use Acme::Gtk2::Ex::Builder;

my $app = build {
    has Window => with {
        meta id           => 'window';
        set  title        => 'Awesome App';
        set  default_size => 200, 100;
        set  position     => 'center';
        on   delete_event => sub { Gtk2->main_quit; };

        has Button => with {
            set label  => 'Action';
            on clicked => sub { say 'Seoul Perl Mongers!' };
        };
    };
};

$app->widget('window')->show_all;
Gtk2->main;

METHODS

widget

Get widget by ID. You can find widget only you set id with meta function.

my $app = build {
    has Window => with {
        meta id => 'my-window';
    };
};

my $window = $app->widget('my-window');

FUNCTIONS

build

This function acts like ordinary "new" method. It is exported by default and returns Acme::Gtk2::Ex::Builder object. It can contains several has functions.

my $app = build {
    has Window;
    has Dialog;
    has FileChooser;
    has VBox;
};

has

This function creates the Gtk2 widget. In fact when you use this, <Gtk2::XXX-new()>> will be called. See Gtk2 and Gtk2 API reference.

Following code will call <Gtk2::Window-new()>>.

my $app = build {
    has Window;
};

If you need more children widgets, use with, then call has again and again.

my $app = build {
    has Window with => {
        has HBox => with {
            has Button;
            has Button;
            has Button;
        };
    };
};

If you have to use more parameters for constructor, then specify additional parameters after the has block. Following code create Gtk2::SimpleList with additional timestamp, nick and message parameter. See Gtk2 and Gtk2 API reference.

my $app = build {
    has SimpleList => with {
        meta id              => 'logviewer';
        set  headers_visible => FALSE;
        set  rules_hint      => TRUE;
    }, (
        timestamp => 'markup',
        nick      => 'markup',
        message   => 'markup',
    );
};

meta

This function sets additional information. Since it is not realted to Gtk2 functions, attributes, signal and properties, so save anything what you want or need.

Currently id and packing have some special meanings. id is used for widget method to find widget. packing is used for Gtk2::VBox and Gtk2::HBox.

my $app = build {
    has Window => with {
        meta id             => 'window';
        set  title          => 'Seoul.pm irc log viewer';
    };

    has HBox => with {
        meta id      => 'hbox';
        meta packing => TRUE, TRUE, 1, 'start';

        has ScrolledWindow => with {
            set policy => 'never', 'automatic';
        };
    };
};

on

This function connects signals for specified widget. Actually it is same as <$widget-signal_connect>>. See Gtk2 and Gtk2 API reference.

my $app = build {
    has Window => with {
        on   delete_event => sub { Gtk2->main_quit };
        has VBox => with {
            has ToggleButton => with {
                set  label   => "show/hide";
                on   toggled => \&toggled;
            };
            has Button => with {
                set  label   => 'Quit';
                on   clicked => sub { Gtk2->main_quit };
            };
        };
    };
};

set

This function sets properties for specified widget. Actually it is same as <$widget-set_xxx>>. See Gtk2 and Gtk2 API reference.

my $app = build {
    has Window => with {
        set  title        => 'Awesome App';
        set  default_size => 200, 100;
        set  position     => 'center';
    };
};

with

This function is used to set attributes, connect signal, add additional information or contain children widgets.

my $app = build {
    has Window => with {
        meta ...
        set  ...
        on   ...
        has  ...
    };
};

SEE ALSO

The idea of this module is stealed from http://advent.perl.kr/2010-12-24.html. I hope Gtk2::Ex::Builder will be released by the article's author someday. And before release this module colud be helpful for you who likes Gtk2 but too lazy to type all code by his/her own hand.

AUTHOR

Keedi Kim - 김도형 <keedi@cpan.org>

COPYRIGHT AND LICENSE

This software is copyright (c) 2011 by Keedi Kim.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.

1 POD Error

The following errors were encountered while parsing the POD:

Around line 351:

Non-ASCII character seen before =encoding in '김도형'. Assuming UTF-8