Gtk2的一些东西

今天到处查了一下有关main_loop(gtk2里就直接是Gtk2->main了)和main_iteration的区别

If you are in the main loop and have a function which needs some time to
execute, then it is a good idea to let the GUI update itself from time
to time. E.g. when you calculate something, and the calculation needs 20
seconds to finish, the app is blocked - you can't click anywhere to stop
it or so. If you stop your calculation every second and let the gui
handle the events, it's a lot better, because the app responds to the
user. The events_pending/main_iteration is for this.

原文:http://aspn.activestate.com/ASPN/Mail/Message/php-gtk-general/2084492

大概意思是当要执行需要很长时间的代码的时候,调用main就会让app挂起,而
main_iteration就是解决这个问题的。
这个正好在程序的主loop(不是ui的lopp)可以实现

但是我发现在调用
main_iteration的时候再调用main_quit的话会报错:
Gtk-CRITICAL **: file gtkmain.c: line 1231 (gtk_main_quit): assertion `main_loops != NULL' failed at Gui.pm line 34.

看到另外一个代码是怎样写的:
$window = Gtk2::Dialog->new("wget: $desc", undef, []);
$window->signal_connect( 'response' => &exit_gracefully );
$window->signal_connect( 'close' => &exit_gracefully );
$PID = open(IN, "$command $uri 2>&1 |") or die "Unable to open pipe: $!n";

# -- Exit on button press -------------------------------------
#
sub exit_gracefully {
print "Living to 0. Killing $PID...n";
kill TERM => $PID;
kill KILL => $PID if kill 0 => $PID;
wait;
print "...done.n";
$LIVING = 0;
Gtk2->main_quit;
exit;
}

还没看明白……
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值