了解 POE-Tk 中的名称空间
我发布了“如何理解 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 ,会话,堆];
”
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];
"
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
&validate 中的 $heap 从哪里来? 您不将其作为参数传递。 &validate 中的 $heap 和 &in_button_1_press 中的 $heap 不是同一件事吗? 您是否尝试过打印 $heap 的字符串形式以查看两个函数中的地址是否相同?
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?