Re: Gtk::GladeXML radiobutton grouping information loss
- From: muppet <scott asofyet org>
- To: David Morel <dmorel intradot com>
- Cc: ML Perl-GTK <gtk-perl-list gnome org>
- Subject: Re: Gtk::GladeXML radiobutton grouping information loss
- Date: Mon, 4 Apr 2005 23:09:27 -0400
On Apr 4, 2005, at 10:31 AM, David Morel wrote:
I noticed the following code fails to keep radiobutton grouping
information, due to my constructing the UI in several passes with a few
get_widget->pack_end(get_widget) calls...
The result is confusing, with all radiobuttons selected instead of one
per group!
this typically happens because each radiobutton you create in this
manner is distinct from all the others --- they are not in the same
radio button group. i see the group listed in the XML, but...
The thing is, if I manually create an XML vbox and add() it to my
frame,
it works fine, but makes my code even more of a mess.
erm, i don't understand why you're using libglade to create single
widgets. is that just an artifact of your stripped-down pseudocode, or
is there some reason that you're doing this instead of just creating
widgets directly with API calls?
Gtk::GladeXML->new('test_window.glade','window_main' );
my $i = 1;
my $pos = tell DATA;
foreach my $source (@sources) {
seek DATA, $pos, 0;
my $xml_widget;
$xml_widget = join('', (<DATA>))
$xml_widget =~ s/##text##/$source/;
$xml_widget =~ s/##num##/$i/;
$xml_widget = Gtk::GladeXML->new_from_memory($xml_widget);
$xml_widget->get_widget(
"radiobutton_disk_restore_$i")->signal_connect(
"clicked", sub { $restoration->source($source); });
$window->get_widget('vbox_restore_disk_source')->pack_end_defaults(
$xml_widget->get_widget("radiobutton_disk_restore_$i"));
$i++;
}
__DATA__
<GTK-Interface>
<widget>
<class>GtkRadioButton</class>
<name>radiobutton_disk_restore_##num##</name>
<can_focus>True</can_focus>
<label>##text##</label>
<active>False</active>
<draw_indicator>True</draw_indicator>
<group>disk_restore_source</group>
</widget>
</GTK-Interface>
# this code should be the equivalent of the above.
my $group = undef;
foreach my $source (@sources) {
my $radio_button = Gtk2::RadioButton->new ($group, $source);
$group = $radio_button; # so the next one will be in this group
$radio_button->set_name ("radiobutton_disk_restore_$i");
$radio_button->signal_connect (toggled => sub {
my ($self) = @_;
# all of the RadioButtons in the group will be toggled, but
# only one will be active.
if ($self->get_active) {
$restoration->source ($source);
}
});
$window->get_widget ('vbox_restore_disk_source')->pack_end_defaults
($radio_button);
$i++;
}
--
Walk softly, and carry a BFG-9000.
-- unknown
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]