如果输入孩子,不应触发 PyGTK 离开通知事件 [英] PyGTK leave-notify-event shouldn't be triggered if enter children

查看:85
本文介绍了如果输入孩子,不应触发 PyGTK 离开通知事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请参阅此代码示例:

import gtk


class MenuBox(gtk.EventBox):
    def __init__(self):
        super(MenuBox, self).__init__()
        self.set_visible_window(False)
        self.connect('enter-notify-event', self._on_mouse_enter)
        self.connect('leave-notify-event', self._on_mouse_leave)

        btn = gtk.Button('x')
        btn.set_border_width(12)
        self.add(btn)

    def _on_mouse_enter(self, wid, event):
        print '_on_mouse_enter'

    def _on_mouse_leave(self, *args):
        print '_on_mouse_leave'


def main():
    win = gtk.Window()
    win.connect('destroy', gtk.main_quit)
    win.add(MenuBox())
    win.show_all()
    gtk.main()

if __name__ == '__main__':
    main()

如果我从父级到子级再返回,我希望不会触发进入和离开事件.我知道在这种特殊情况下,我可以使用 event.detail 过滤这些事件.但是如果没有边界,这不起作用.如果我移除边框,则根本不会触发事件.

I want that the enter and leave events are not triggered if I am going from parent to child and back. I know that in this particular case I can filter these events with event.detail. But this does not work if there is no border. If I remove the border the events aren't triggered at all.

在我的实际代码中,我有一个更复杂的小部件(基于 gtk.Fixed),它在开头有边框,但在结尾没有.因此,仅仅将事件转移到孩子身上也行不通.

In my real code I have a more complex widget (based on gtk.Fixed) which has border at the beginning but not at the end. So just moving the event to the child wouldn't do the trick either.

推荐答案

#        self.set_visible_window(False)
        self.connect('enter-notify-event', self._on_mouse_enter)
        self.connect('leave-notify-event', self._on_mouse_leave)

        btn = gtk.Button('x')
#        btn.set_border_width(12)

这是你需要的吗?

这篇关于如果输入孩子,不应触发 PyGTK 离开通知事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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