Gtk2的一些东西

来源:互联网 发布:网络与信息安全学报 编辑:程序博客网 时间:2024/05/16 19:50
今天到处查了一下有关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;
}
还没看明白……
原创粉丝点击