Fwd: Re: Help with get_text() for Gtk3::Entry widget



First of all, thank you for your help.

I found a solution to this. it seems Gtk3+ does not like a hard coded nested signal_connect(). I do not know if "hard coded nested" describes the situation right, but i separated a subroutine which mapped to signal_connect outside the block. and it worked fine.

The following is the code.
#!/usr/bin/perl

use strict;
use warnings;

use Gtk3 -init;
 
sub test_get_text_calling {
    my ($button, $entries_ref) = @_;
    warn $$entries_ref->get_text();
}

# i separated this subroutine from signal_connect(), and worked fine.
sub enter_get_text_calling {
    my ($button, $entries_ref) = @_;
    warn $$entries_ref->get_text();
}

my $window = Gtk3::Window->new('toplevel');
$window->signal_connect(delete_event => sub { Gtk3->main_quit() });


no strict 'refs';

my (@hbox, @button);
my $count = 1;
my $grid = Gtk3::Grid->new();
my $add_button = Gtk3::Button->new_with_label("add");
$add_button->signal_connect( clicked => sub {
        $hbox[$count] = Gtk3::HBox->new();
        ${ "entry_" . $count } = Gtk3::Entry->new;
        ${ "entry_" . $count }->signal_connect(
            'changed' =>  \&enter_get_text_calling,
                          \${ "entry_" . $count });
        $button[$count] = Gtk3::Button->new('Call get_text()');
        $button[$count]->signal_connect('clicked',
                                \&test_get_text_calling,
                                \${ "entry_" . $count });
        $hbox[$count]->add(${ "entry_" . $count });
        $hbox[$count]->add($button[$count]);
        $grid->attach($hbox[$count],1,$count+1,2,1);
        $window->show_all();
        $count++;
    } # sub
); # signal_connect

    $grid->attach($add_button,1,1,1,1);
    $window->add($grid);
    $window->show_all();

use strict 'refs';

Gtk3->main();

Thank you thank you super very  mucho mucho much!!!

Yoshi

-------- Original Message --------
Subject: Re: Help with get_text() for Gtk3::Entry widget
Date: Mon, 14 Apr 2014 12:17:10 +0400
From: Yuri Myasoedov <ymyasoedov yandex ru>
To: gtk-perl-list gnome org <gtk-perl-list gnome org>


14.04.2014, 09:40, "tsuyoshi okita" <825864 gmail com>:
> This is my code snippet:

It's hard to say anything out of your snippet, because it's just a part of a whole code. Try to provide minimal and complete test case that will show the problem.

BTW, here is my test case, that works fine:

#!/usr/bin/perl
use warnings;
use strict;
use Gtk3 -init;
 
sub test_get_text_calling {
    my ($button, $entries_ref) = @_;
    warn $entries_ref->[0]->get_text();
}

my $window = Gtk3::Window->new('toplevel');
$window->signal_connect(delete_event => sub { Gtk3->main_quit() });

no strict 'refs';
my $row = 1;

# Test item
${ "entry_" . $row } = Gtk3::Entry->new;

# Test item
my @test_array = ( ${ "entry_" . $row } );

${ "entry_" . $row }->signal_connect(
    'changed' => sub {
        warn "You've entered: ", ${ "entry_" . $row }->get_text();
    }
);

my $hbox = Gtk3::HBox->new();
my $button = Gtk3::Button->new('Call get_text()');
$button->signal_connect('clicked',
                        \&test_get_text_calling,
                        \ test_array);
$hbox->add(${ "entry_" . $row });
$hbox->add($button);
$window->add($hbox);
$window->show_all();
use strict 'refs';

Gtk3->main();
_______________________________________________
gtk-perl-list mailing list
gtk-perl-list gnome org
https://mail.gnome.org/mailman/listinfo/gtk-perl-list




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