Question

I posted "How to undersand the POE-Tk use of destroy?" in an attempt to reduce the bug in my production code to a test case. But it seems that the solution to the test case is not working in the full program.

The program is 800+ lines long so I am hesitant to post it in full. I realize that the snippets I provide here may be too short to be of any use, but I hope to get some direction in either where to look for a solution or what additional information I can provide.

Here is the Session::Create section of my POE-Tk app.


POE::Session->create(
    inline_states => {
        _start      => \&ui_start,
        get_zone    => \&get_zone,
        ping        => \&ping,
        mk_disable  => \&mk_disable,
        mk_active   => \&mk_active,
        pop_up_add => \&pop_up_add,
        add_button_press => sub {
            my ($kernel, $session, $heap) = @_[KERNEL, SESSION, HEAP];
            print "\nadd button pressed\n\n";
            &validate;
        },
        ih_button_1_press => sub {
            my ($kernel, $session, $heap) = @_[KERNEL, SESSION, HEAP];
            print "\nih_button_1 pressed\n\n";
            if( Tk::Exists($heap->{ih_mw}) ) {
                print "\n\nih_mw exists in ih_button_1_press\n\n";
            } else {
                print "\n\nih_mw does not exist in ih_button_1_press\n\n";
            }
            1;
            $heap->{ih_mw}->destroy if Tk::Exists($heap->{ih_mw});
            &auth;
        },
        pop_up_del => \&pop_up_del,
        auth        => \&auth,
#       validate    => \&validate,
        auth_routine => \&auth_routine,
        raise_widget    => \&raise_widget,
        del_action  => \&del_action,
        over        => sub { exit; }
    }
);

add_button_press is called here;


sub pop_up_add {
    ...
    my $add_but_2 = $add_frm_2->Button( 
        -text => "Add Record",
        -command => $session->postback("add_button_press"),
        -font => "{Arial} 12 {bold}") -> pack(
            -anchor => 'c',
            -pady => 6,
        );
    ...
}

validate creates the Toplevel widget $heap->{ih_mw};


sub validate {
    ...
    if( ! $valid ) {
        print "\n! valid entered\n\n";
        $heap->{label_text} .= "Add record anyway?";
        my $lt_ref = \$heap->{label_text};
    ...
        my $heap->{ih_mw} = $heap->{add_mw}->Toplevel( -title => "ih_mw");
    ... 
        if( Tk::Exists($heap->{ih_mw}) ) {
            print "\n\nih_mw exists in validate\n\n";
        } else {
            print "\n\nih_mw does not exist in validate\n\n";
        }
    ...
        my $ih_but1 = $heap->{ih_mw}->Button( -text => "Add",
            -font => 'vfont',
            -command => $session->postback("ih_button_1_press"),
            )->pack( -pady => 5 );
    ...
}

Pressing $ih_but1 results in this;

C:\scripts\alias\resource>alias_poe_V-3_0_par.pl

add button pressed

sub validate called

! valid entered

ih_mw exists in validate

ih_button_1 pressed

ih_mw does not exist in ih_button_1_press

So the $heap->{ih_mw} widget seems to be unkown to the ih_button_1_press anonymous subroutine even with the inclusion of "($kernel, $session, $heap) = @_[KERNEL, SESSION, HEAP];"

Was it helpful?

Solution

Where does $heap in &validate come from? You don't pass it as a parameter. Could $heap in &validate and $heap in &in_button_1_press not be the same thing? Have you tried printing the stringy form of $heap to see if the addresses are the same in the two functions?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top