Re: Display control with Gtk2 and Glade2
- From: "Matthew Braid" <ptkperl mdb id au>
- To: gtk-perl-list gnome org
- Subject: Re: Display control with Gtk2 and Glade2
- Date: Sat, 2 Sep 2006 17:11:18 +1000
> Glade is not good for repetitive items - it doesn't know how to generate
> a loop - that was one of my concerns.
Hi,
Glade can be used for loops if you do the actual looping yourself. I've got several glade files that contain a main window and a 'helper' window - the helper never gets created, but the tables/vboxes/hboxes/whatevers inside it have identifying names and I just do something like:
# Note - freehand code. Probably won't run properly :)
# Build the main window
my $mainglade = Gtk2::GladeXML->new('path/to/file', 'MAIN_WINDOW_NAME');
# Name a container in glade-2 something you can get
my $container = $mainglade->get_widget('LOOP_VBOX');
my @subglades;
for my $i (1..$n) {
# Make sure glade only builds the container, not its window
my $subglade = Gtk2::GladeXML->new('path/to/file', 'WIDGET_NAME');
push @subglades, $subglade; # for later access
# Add this repetition into the container
$container->pack_start($subglade->get_widget('WIDGET_NAME'));
}
Now you've got a vertical list of repetitive glade objects that you only needed to build (in glade 2) once. To access individual widgets inside the looped part all you need to do is:
$subglades[$i]->get_widget($name);
MB
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]