「POE-Tkによるdestroyの使用を理解する方法」を投稿しました。私の製品コードのバグをテストケースに減らすために。しかし、テストケースの解決策は完全なプログラムでは機能していないようです。
プログラムは800行以上の長さなので、完全に投稿することを躊躇しています。ここで提供するスニペットは短すぎて役に立たない可能性があることを認識していますが、解決策を探す場所または提供できる追加情報のいずれかについて、何らかの方向性を得たいと考えています。
これが私のPOE-TkアプリのSession::Createセクションです。
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
ここで呼ばれます。
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は、トップレベルウィジェット$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 );
...
}
$ ih_but1を押すと、次のようになります。
C:\scripts\alias\resource>alias_poe_V-3_0_par.pl
追加ボタンが押されました
サブ検証と呼ばれる
!有効な入力
ih_mw
検証に存在します
ih_button_1
押された
ih_mw
に存在しませんih_button_1_press
したがって、$heap->{ih_mw}
ウィジェットは、「 」ih_button_1_press
が含まれていても、匿名サブルーチンには認識されていないようです。($kernel, $session, $heap) = @_[KERNEL, SESSION, HEAP];