views:

179

answers:

1

I noticed when a Eventbox is added into a Layout some events are missed, this does not happend for example adding it to a Fixed (very similar widget), I tried to restore the event mask in this way with no sucess:

import pygtk
import gtk


def foo(widget, event):

    print event


pygtk.require('2.0')
window = gtk.Window(gtk.WINDOW_TOPLEVEL)
window.connect('destroy', lambda x: gtk.main_quit())

eventbox = gtk.EventBox()
eventbox.connect('button-press-event', foo)   # works
eventbox.connect('motion-notify-event', foo)  # fail
eventbox.set_events(
    gtk.gdk.BUTTON_MOTION_MASK|               # restoring missed masks
    gtk.gdk.BUTTON1_MOTION_MASK|
    gtk.gdk.BUTTON2_MOTION_MASK|
    gtk.gdk.BUTTON3_MOTION_MASK)

layout = gtk.Layout()
image = gtk.image_new_from_file('/home/me/picture.jpg')

layout.add(image)
eventbox.add(layout)
window.add(eventbox)

window.show_all()
gtk.main()

How should I restore the missed event/mask?

+1  A: 

The code you pasted works fine for me. When I press button 1 on the mouse and drag on the window, it generates and prints motion events to the terminal.

I've even removed the eventbox.set_events(...) call and it still works.

So what's the problem?

nosklo
ok, thanks for try it, I will try to reboot the PC or test it in a newer GTK (I has 2.16.1) ... in what version are you?
mkotechno
@mkotechno: pygtk 2.16, gtk 2.18, glib 2.22, cairo 1.8.8, pygobject 2.18, python 2.6.4
nosklo
I tried with GTK 2.20 and works fine too, but for keep backward compatibility, what should I change in this code? or maybe is a GTK bug?
mkotechno