On Fri, May 04, 2007 at 04:37:01PM +0200, Gergely K. wrote:
pack_start label("close me")
}
end
What will this snippet do? Calling build on a Button?
This will add a HBox with an Image and a Label inside it to the button.
#build just calls instance_eval on the widget, and #method_missing
handles
the automagic widget creation.
I first made it only with Gtk.build, but then I realized that it works
for
widgets too by simply including the Builder::Proxy, so I just put it in.
Reading the comment it seems, that your scripts can do more things,
than the little example snippet. Can you post an example with
comments? It would be helpful.
I just wrote this yesterday late at night, so bear with me
I think I’ll try to convert some of my GTK programs to this syntax
and see how it works out.
I would prefer building with an own class like: Gtk::Builder, and than
you can write class names as usual (is this possible?).
Creating normal classes iside the block works as usual, though you have
to
call #build on every widget to do further nesting, and you won’t get the
automatic property-setting and signal-connecting, since you’d have to do
this in the widget constructor.
To me, the point of this whole thing was that I didn’t have to call
Gtk::*.new for every widget, and that I can quickly create a GUI without
all the usual filler.
Anyway, here’s an example using classes directly:
b = Gtk::Builder.new
b.build do
Gtk::Window.new.build {
b = Gtk::Button.new(‘click me’)
b.signal_connect(‘clicked’) { Gtk.main_quit }
add b
show_all
}
end
Gtk.main
As you see, this doesn’t give you a lot over the normal way, except
maybe
that the code structure equals the widget hierarchy.
I’m not really sure yet if this builder syntax will be efficient in more
complex programs, but it definitely was fun to write
Cheers,
Markus
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/