PyGTK leave-notify-event shouldn't be triggered if enter children

柔情痞子 提交于 2019-12-11 06:38:25

问题


Please see this code example:

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()

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.

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.


回答1:


#        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)

Is that what you need?



来源:https://stackoverflow.com/questions/13291055/pygtk-leave-notify-event-shouldnt-be-triggered-if-enter-children

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!