Maybe first recall that there are signals and events. Maybe somewhat over-simplifying, events are 'raw': They come, for example, a keyboard or a mouse. The topmost widget (considering the window being at the bottom) receives those events and decides if it is interesting in the event or not.
If the widget is interested in the event, like a button which is interested in the button-press-event and button-release-event, the widget then creates signals such as, in this case, the 'clicked', 'double-clicked' signals. Inside the event handler, the return value (True or False) determines if the event will propagate 'down' to the next widget ('under' the top one).
So, I suspect you can't easily monitor all events directly on the underlying window before they reach their target.
Maybe a solution for you would be to connect to the 'event-after' of the window. This gets called independently from the return value of the other handlers. Below is a small program where you can test the following:
A GtkGrid appears with a Label, a Button, and a SpinButton. The lower right cell is empty:
Click on the label and the events trickle down to the window, because Label doesn't capture any event
Click on the button, and the events (such as 'pressed') are captured by the handler, and signals such as 'clicked' are generated.
I connected to the 'event-after', and a button press anywhere is reported.
.
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# test_events.py
#
# Copyright 2017 John Coppens <john*at*jcoppens*dot*com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA.
#
#
from gi.repository import Gtk
class EventsTest(Gtk.Grid):
def __init__(self):
super(EventsTest, self).__init__()
btn = Gtk.Button("Top right")
btn.connect("clicked", lambda x: print("Button clicked"))
self.attach(Gtk.Label("Top left"), 0, 0, 1, 1)
self.attach(btn, 1, 0, 1, 1)
self.attach(Gtk.SpinButton(), 0, 1, 1, 1)
class MainWindow(Gtk.Window):
def __init__(self):
super(MainWindow, self).__init__()
self.connect("destroy", lambda x: Gtk.main_quit())
self.connect("button-press-event", self.on_button_pressed)
self.connect("event-after", self.on_event_after)
evtest = EventsTest()
self.add(evtest)
self.show_all()
def on_button_pressed(self, btn, event):
print("Main window button pressed")
return True
def on_event_after(self, wdg, event):
print("Event after")
def run(self):
Gtk.main()
def main(args):
mainwdw = MainWindow()
mainwdw.run()
return 0
if __name__ == '__main__':
import sys
sys.exit(main(sys.argv))