Re: How do I get the value of a GtkOptionMenu using Glade-Perl?

ws wrote:

Hi again Wolfgang,

One way to do it is to connect a handler to the 'hide' signal of the
optionmenu's menu and then get_active to get the selected menu_item.

So, for example, you could copy/paste the run method from
into your file (same class) and you would have for a Gnome
project called Reference with optionmenu4

# ---------------------------------------------------

sub my_run {
    my ($class) = @_;
    # You can use the line below to load a test .mo file before it is
    # installed in the normal place (eg 
    #    /usr/local/share/locale//LC_MESSAGES/
#    $class->load_translations('Reference', 'test', undef, 
#        '/home/dermot/Devel/Glade-Perl/Example/Reference/ppo/');
    Gnome->init('Reference', '0.53');
    my $window = $class->new;

    $window->FORM->{'optionmenu4'}->get_menu->signal_connect( 'hide',
        "$class\::on_optionmenu4_hide", '', 'optionmenu4', 
        $window->INSTANCE );


} # End of sub run

sub on_optionmenu4_hide {
    my ($class, $data, $object, $instance, $event) = @_;
    my $me = __PACKAGE__."->on_optionmenu4_hide";
    # Get ref to hash of all widgets on our form
    my $form = $__PACKAGE__::all_forms->{$instance};

    my $selected_string = ($class->get_active->children)[0]->get;
    print "We have selected string $selected_string\n";
} # End of sub on_optionmenu4_hide

# ---------------------------------------------------

I will add this to the FAQ in the next version :)

regards, Dermot.

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