如何让gtk控制被处理,或者不被处理?
我正在使用 pygtk,并且有时想处理 control+c 来执行特殊的复制操作,但其他时候则让 gtk 处理它。例如,我想将一个对象放在剪贴板上(如果可用),或者只是让 control+c 在文本输入中以正常方式使用。
目前,我有一个与“c”关联的 ActionGroup,但即使我返回 False,它也总是会占用击键。如果我删除 ActionGroup,它始终在文本区域中起作用。如果我添加 ActionGroup,它总是会处理它,并且复制在文本区域中不起作用。
让 control+c 出现在菜单中,有时处理击键,但其他时候,让它落在文本小部件上的正确方式是什么?
I'm using pygtk, and would like to handle control+c sometimes to do a special copy action, but other times to let gtk handle it. For example, I'd like to put an object on my clipboard if it is available, or just let control+c be used in the normal fashion in a text entry.
Currently I have an ActionGroup associated with "c" but that always eats the keystroke, even if I return False. If I remove the ActionGroup, it always works in the text areas. If I add the ActionGroup, it always handles it, and copy doesn't work in the text areas.
What is the proper manner to have control+c appear in the menu, handle the keystroke sometimes, but other times, let it fall to a text widget?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不知道这是否是“正确”的方式,但我是这样做的。我将应用程序窗口作为用户数据参数传递给操作回调。然后我找出窗口中聚焦的小部件,然后将复制命令传递给该小部件(如果这样做有意义的话)(即聚焦的小部件是像您所说的文本条目)。如果这没有意义,那么我从窗口的“默认”文本视图进行复制。
(获取默认文本视图实际上是通过在我的应用程序类上调用
get_default_view()
方法来完成的,该应用程序类是GtkWindow
的子类;但我不想复杂化这里很重要。)I don't know if this is the "proper" way, but here is how I do it. I pass the application window as the user data parameter to the action callback. Then I find out which widget is focused in the window, and I pass the copy command on to that widget if that makes sense to do (i.e. the focused widget is a text entry like you say). If that doesn't make sense, then I copy from the window's 'default' text view.
(Obtaining the default text view is actually done by calling a
get_default_view()
method on my application class, which is a subclass ofGtkWindow
; but I didn't want to complicate matters here.)