用python gtk键盘中断? [英] keyboard interrupt with with python gtk?

查看:181
本文介绍了用python gtk键盘中断?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以就像问题所说的,我试图让键盘中断在Gtk.main()进行时发生,但是,它似乎没有注意到键盘中断发生,直到函数完成。

因此,我试图在单独的线程中粘住Gtk.main(),并让主线程找到键盘中断,并终止线程,但后来发现如这篇文章中所述,Gtk不能很好地与线程一起使用



我想不出任何让键盘中断工作的方法。这是可能的吗?



我使用的是python3,并且希望我的程序最终能够跨平台。

解决方案

因为 https://bugzilla.gnome.org /show_bug.cgi?id=622084 使用pygobject编写的gtk应用程序在终端上使用 Ctrl + C 时不会自行关闭。



<你可以像这样安装一个Unix信号处理程序:

  if __name__ =='__main__':
导入信号
signal.signal(signal.SIGINT,signal.SIG_DFL)
your_application_main()


So just like the question says, I'm trying to let keyboard interrupts happens while Gtk.main() is in progress, however, it just doesn't seem to notice that the keyboard interrupt happens until after the function is done.

So I tried sticking Gtk.main() in a separate thread, and have the main thread find the keyboard interupts, and terminate the thread, but then found out that Gtk doesn't play nicely with threads as described in this article

I can't think of any other way to let keyboard interrupts work. Is this possible?

I'm using python3, and want my program to eventually be cross platform.

解决方案

because of https://bugzilla.gnome.org/show_bug.cgi?id=622084 gtk applications written using pygobject will not close themselves when using Ctrl + C on the terminal.

to work around it, you can install a Unix signal handler like this:

if __name__ == '__main__':
    import signal
    signal.signal(signal.SIGINT, signal.SIG_DFL)
    your_application_main()

这篇关于用python gtk键盘中断?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆