在 KDE Python 应用程序中处理键盘中断?
我正在开发 PyKDE4/PyQt4 应用程序 Autokey,我注意到当我向程序发送 CTRL 时+C,直到我通过 ie 与应用程序交互时才会处理键盘中断。单击菜单项或更改复选框。
lfaraone@stone:~$ /usr/bin/autokey
^C^C^C
Traceback (most recent call last):
File "/usr/lib/python2.6/dist-packages/autokey/ui/popupmenu.py", line 113, in on_triggered
def on_triggered(self):
KeyboardInterrupt
^C^C^C
Traceback (most recent call last):
File "/usr/lib/python2.6/dist-packages/autokey/ui/configwindow.py", line 423, in mousePressEvent
def mousePressEvent(self, event):
KeyboardInterrupt
尽管 /usr/bin/autokey 中有以下内容:
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys
from autokey.autokey import Application
a = Application()
try:
a.main()
except KeyboardInterrupt:
a.shutdown()
sys.exit(0)
为什么没有捕获 KeyboardInterrupt:
- 在 GUI 中采取操作时
- 当我发出它时,而不是当我下次通过初始 try/ except 子句
?使用 Python 2.6 运行 Ubuntu 9.04。
I'm working on a PyKDE4/PyQt4 application, Autokey, and I noticed that when I send the program a CTRL+C, the keyboard interrupt is not processed until I interact with the application, by ie. clicking on a menu item or changing a checkbox.
lfaraone@stone:~$ /usr/bin/autokey
^C^C^C
Traceback (most recent call last):
File "/usr/lib/python2.6/dist-packages/autokey/ui/popupmenu.py", line 113, in on_triggered
def on_triggered(self):
KeyboardInterrupt
^C^C^C
Traceback (most recent call last):
File "/usr/lib/python2.6/dist-packages/autokey/ui/configwindow.py", line 423, in mousePressEvent
def mousePressEvent(self, event):
KeyboardInterrupt
This is despite having the following in /usr/bin/autokey:
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys
from autokey.autokey import Application
a = Application()
try:
a.main()
except KeyboardInterrupt:
a.shutdown()
sys.exit(0)
Why isn't the KeyboardInterrupt caught:
- when I issue it, rather than when I next take an action in the GUI
- by the initial try/except clause?
Running Ubuntu 9.04 with Python 2.6.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试这样做:
在调用
a.main()
之前。更新: 请记住,Ctrl-C 可用于 GUI 应用程序中的复制。在Qt中最好使用Ctrl+\,这将导致事件循环终止并关闭应用程序。
Try doing this:
before invoking
a.main()
.Update: Remember, Ctrl-C can be used for Copy in GUI applications. It's better to use Ctrl+\ in Qt, which will cause the event loop to terminate and the application to close.