Re: radioitem



"Beast" == Beast  <beast i6x org> writes:

    Beast> muppet wrote:
    >> probably belongs in the FAQ:
    >> http://mail.gnome.org/archives/gtk-perl-list/2003-September/msg00081.html
    >> http://mail.gnome.org/archives/gtk-perl-list/2004-April/msg00115.html
    >> http://mail.gnome.org/archives/gtk-perl-list/2005-March/msg00039.html

    Beast> Thanks, but I still have a problem. It trigger action
    Beast> twice on every event, what could be the reason?

    Beast> use Gtk2::SimpleMenu;

    Beast> ...  children => [ 'Radio One' => { callback => sub {
    Beast> $self->radio_callback}, item_type => '<RadioItem>',
    Beast> groupid => 1 }, 'Radio Two' => { callback => sub {
    Beast> $self->radio_callback},, item_type => '<RadioItem>',
    Beast> groupid => 1 }, ...

    Beast> sub radio_callback { my $self = shift; if
    Beast> ($self->{menu}->get_widget('/Radio/Radio
    Beast> One')->get_active) { print "Radio One active\n";
    Beast>     }
    Beast> }

    Beast> When I select Radio One, it prints:

    Beast> Radio One active 

    Beast> Radio One active

As it should.

"Torsten" == Torsten Schoenfeld <kaffeetisch gmx de> writes:

    Torsten> That's normal since both buttons got toggled after
    Torsten> all.  In the callbacks, check $radio->get_active
    Torsten> ($radio is the first argument to the callbacks) to
    Torsten> find out if your button is on or off.

I can't explain it better.

But I may explain why your program reports 'Radio One active' two
times : you ask it two times if Radio One is active.

Try asking the state of Radio Two.

Or better, as  Torsten advised you : ask  to the widget receiving
the event in what state it is :

sub radio_callback
{
     my $self = shift;
     if ($self->get_active())
     {
        print "I am active\n";
     }
     else
     {
        print "I am not active\n";
     }
}

How to get the name of the widget is left as an exercise for the reader.

    Vincent



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