Re: Gtk::GladeXML radiobutton grouping information loss

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('','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);
            "clicked", sub { $restoration->source($source); });



# 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

Walk softly, and carry a BFG-9000.
  -- unknown

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]