1Gtk2::Buildable(3)    User Contributed Perl Documentation   Gtk2::Buildable(3)
2
3
4

NAME

6       Gtk2::Buildable - Interface for objects that can be built by
7       Gtk2::Builder
8

SYNOPSIS

10         package Thing;
11         use Gtk2;
12         use Glib::Object::Subclass
13             Glib::Object::,
14
15             # Some signals and properties on the object...
16             signals => {
17                 exploderize => {},
18             },
19             properties => [
20                 Glib::ParamSpec->int ('force', 'Force',
21                                       'Explosive force, in megatons',
22                                       0, 1000000, 5, ['readable', 'writable']),
23             ],
24             ;
25
26         sub exploderize {
27             my $self = shift;
28             $self->signal_emit ('exploderize');
29         }
30
31         # We can accept all defaults for Buildable; see the description
32         # for details on custom XML.
33
34         package main;
35         use Gtk2 -init;
36         my $builder = Gtk2::Builder->new ();
37         $builder->add_from_string ('<interface>
38             <object class="Thing" id="thing1">
39                 <property name="force">50</property>
40                 <signal name="exploderize" handler="do_explode" />
41             </object>
42         </interface>');
43         $builder->connect_signals ();
44
45         my $thing = $builder->get_object ('thing1');
46
47         $thing->exploderize ();
48
49         sub do_explode {
50             my $thing = shift;
51             printf "boom * %d!\n", $thing->get ('force');
52         }
53
54         # This program prints "boom * 50!" on stdout.
55

HIERARCHY

57         Glib::Interface
58         +----Gtk2::Buildable
59

DESCRIPTION

61       The Gtk2::Buildable interface allows objects and widgets to have
62       "<child>" objects, special property settings, or extra custom tags in a
63       Gtk2::Builder UI description
64       (<http://library.gnome.org/devel/gtk/unstable/GtkBuilder.html#BUILDER-UI>).
65
66       The main user of the Gtk2::Buildable interface is Gtk2::Builder, so
67       there should be very little need for applications to call any of the
68       Gtk2::Buildable methods.  So this documentation deals with implementing
69       a buildable object.
70
71       Gtk2::Builder already supports plain Glib::Object or Gtk2::Widget with
72       "<object>" construction and "<property>" settings, so often the
73       "Gtk2::Buildable" interface is not needed.  The only thing to note is
74       that an object or widget implemented in Perl must be loaded before
75       building.
76

OVERRIDING BUILDABLE INTERFACE METHODS

78       The buildable interface can be added to a Perl code object or widget
79       subclass by putting "Gtk2::Buildable" in the interfaces list and
80       implementing the following methods.
81
82       In current Gtk2-Perl the custom tags code doesn't chain up to any
83       buildable interfaces in superclasses.  This means for instance if you
84       implement Gtk2::Buildable on a new widget subclass then you lose the
85       <accelerator> and <accessibility> tags normally available from
86       Gtk2::Widget.  This will likely change in the future, probably by
87       chaining up by default for unhandled tags, maybe with a way to ask
88       deliberately not to chain.
89
90       SET_NAME ($self, $name)
91           •   $name (string)
92
93           This method should store $name in $self somehow.  For example,
94           Gtk2::Widget maps this to the Gtk2::Widget's "name" property.  If
95           you don't implement this method, the name will be attached in
96           object data down in C code.  Implement this method if your object
97           has some notion of "name" and it makes sense to map the XML name
98           attribute to that.
99
100       string = GET_NAME ($self)
101           If you implement "SET_NAME", you need to implement this method to
102           retrieve that name.
103
104       ADD_CHILD ($self, $builder, $child, $type)
105           •   $builder (Gtk2::Builder)
106
107           •   $child (Glib::Object or undef)
108
109           •   $type (string)
110
111           "ADD_CHILD" will be called to add $child to $self.  $type can be
112           used to determine the kind of child.  For example, Gtk2::Container
113           implements this method to add a child widget to the container, and
114           Gtk2::Notebook uses $type to distinguish between "page-label" and
115           normal children.  The value of $type comes directly from the "type"
116           attribute of the XML "child" tag.
117
118       SET_BUILDABLE_PROPERTY ($self, $builder, $name, $value)
119           •   $builder (Gtk2::Builder)
120
121           •   $name (string)
122
123           •   $value (scalar)
124
125           This will be called to set the object property $name on $self,
126           directly from the "property" XML tag.  It is not normally necessary
127           to implement this method, as the fallback simply calls
128           "Glib::Object::set()".  Gtk2::Window implements this method to
129           delay showing itself (i.e., setting the "visible" property) until
130           the whole interface is created.  You can also use this to handle
131           properties that are not wired up through the Glib::Object property
132           system (though simply creating the property is easier).
133
134       parser or undef = CUSTOM_TAG_START ($self, $builder, $child, $tagname)
135           •   $builder (Gtk2::Builder)
136
137           •   $child (Glib::Object or undef)
138
139           •   $tagname (string)
140
141           When Gtk2::Builder encounters an unknown tag while parsing the
142           definition of $self, it will call "CUSTOM_TAG_START" to give your
143           code a chance to do something with it.  If $tagname was encountered
144           inside a "child" tag, the corresponding object will be passed in
145           $child; otherwise, $child will be "undef".
146
147           Your "CUSTOM_TAG_START" method should decide whether it supports
148           $tagname.  If not, return "undef".  If you do support it, return a
149           blessed perl object that implements three special methods to be
150           used to parse that tag.  (These methods are defined by GLib's
151           GMarkupParser, which is a simple SAX-style setup.)
152
153           START_ELEMENT ($self, $context, $element_name, $attributes)
154               •   $context (Gtk2::Buildable::ParseContext)
155
156               •   $element_name (string)
157
158               •   $attributes (hash reference) Dictionary of all attributes
159                   of this tag.
160
161           TEXT ($self, $context, $text)
162               •   $context (Gtk2::Buildable::ParseContext)
163
164               •   $text (string) The text contained in the tag.
165
166           END_ELEMENT ($self, $context, $element_name)
167               •   $context (Gtk2::Buildable::ParseContext)
168
169               •   $element_name (string)
170
171           Any blessed perl object that implements these methods is valid as a
172           parser.  (Ain't duck-typing great?)  Gtk2::Builder will hang on to
173           this object until the parsing is complete, and will pass it to
174           "CUSTOM_TAG_END" and "CUSTOM_FINISHED", so you shouldn't have to
175           worry about its lifetime.
176
177       CUSTOM_TAG_END ($self, $builder, $child, $tagname, $parser)
178           •   $builder (Gtk2::Builder)
179
180           •   $child (Glib::Object or undef)
181
182           •   $tagname (string)
183
184           •   $parser (some perl object) as returned from "CUSTOM_TAG_START"
185
186           This method will be called (if it exists) when the close tag for
187           $tagname is encountered.  $parser will be the object you returned
188           from "CUSTOM_TAG_START".  $child is the same object-or-undef as
189           passed to "CUSTOM_TAG_START".
190
191       CUSTOM_FINISHED ($self, $builder, $child, $tagname, $parser)
192           •   $builder (Gtk2::Builder)
193
194           •   $child (Glib::Object or undef)
195
196           •   $tagname (string)
197
198           •   $parser (some perl object) as returned from "CUSTOM_TAG_START"
199
200           This method will be called (if it exists) when the parser finishes
201           dealing with the custom tag $tagname.  $parser will be the object
202           you returned from "CUSTOM_TAG_START".  $child is the same object-
203           or-undef as passed to "CUSTOM_TAG_START".
204
205       PARSER_FINISHED ($self, $builder)
206           •   $builder (Gtk2::Builder)
207
208           If this method exists, it will be invoked when the builder finishes
209           parsing the description data.  This method is handy if you need to
210           defer any object initialization until all of the rest of the input
211           is parsed, most likely because you need to refer to an object that
212           is declared after $self or you need to perform special cleanup
213           actions.  It is not normally necessary to implement this method.
214
215       object or undef = GET_INTERNAL_CHILD ($self, $builder, $childname)
216           •   $builder (Gtk2::Builder)
217
218           •   $childname (string)
219
220           This will be called to fetch an internal child of $self.  Implement
221           this method if your buildable has internal children that need to be
222           accessed from a UI definition.  For example, Gtk2::Dialog
223           implements this to give access to its internal vbox child.
224
225           If $childname is unknown then return "undef".  (The builder will
226           then generally report a GError for the UI description referring to
227           an unknown child.)
228

SEE ALSO

230       Gtk2, Glib::Interface,
231       <http://library.gnome.org/devel/gtk/unstable/GtkBuilder.html#BUILDER-UI>,
232       Gtk2::Buildable::ParseContext
233
235       Copyright (C) 2003-2011 by the gtk2-perl team.
236
237       This software is licensed under the LGPL.  See Gtk2 for a full notice.
238
239
240
241perl v5.36.0                      2022-07-22                Gtk2::Buildable(3)
Impressum