[pygtk] propogating events not handled by the grab window

Darren Hart darren at dvhart.com
Tue Oct 21 17:14:53 WST 2008


I've written a custom widget which pops up a
gtk.Window(gtk.WINDOW_POPUP) when the toggle button is pressed.  I'm
struggling with the owner_events argument to pointer_grab.  If I set
it to True, then my window will stay popped up if I click on active
areas of my main window (i/e/ widgets and not just dead space between
widgets).  If I set it to False, then it disappears as it should, but
if I click on any of the controls in the popup, nothing happens.  I
thought that by returning False from the popup_button_press handler,
that the event should be propogated to the child widgets... but
apparently not.

What can I do so that if I click anywhere outside the popup the
window, the popup window will close, and if I click inside the popup
window, the appropriate child widget will receive the event?  I've
pasted what I believe to be the relevant buts below:

    def _hide_popup(self):
        self._popup.hide()
        self._popup.grab_remove()
        self.set_active(False)

    def _show_popup(self):
        x, y = self.window.get_origin()
        x += self.get_allocation().x
        y += self.get_allocation().y + self.get_allocation().height
        self._popup.move(x, y)
        self._popup.show_all()
        # FIXME: would like second arg to be False, but then the event
doesn't get
        # handled if it lands on the popup window... weird...
        gdk.pointer_grab(self._popup.window, True,
                         gdk.BUTTON_PRESS_MASK | gdk.BUTTON_RELEASE_MASK)

    def _on_popup_button_press(self, popup, event):
        w, h = popup.get_size()
        x = event.x
        y = event.y
        if x < 0 or x > w or y < 0 or y > h:
            self._hide_popup()
            return True
        # FIXME: this doesn't seem to propogate the events...
        return False


Thanks for looking!

-- 
Darren Hart


More information about the pygtk mailing list