Search code examples
pythonglibgdk

GDK events handling without GTK


I'm programming (in python) GDK without GTK, simply as a x11 abstraction. THIS POST IS MY LAST CHANCE.

My problem is that I don't know how capture the GDK window's signals/events or what are their names.

When I do:

window = gdk.Window(
            gdk.get_default_root_window(),
            width=400,
            height=200,
            window_type=gdk.WINDOW_CHILD,
            wclass=gdk.INPUT_OUTPUT,
            event_mask=gdk.KEY_PRESS_MASK | gdk.MOTION_NOTIFY | gdk.EXPOSURE_MASK)

window.connect("key_press_event", on_key)

I get:

unknown signal name: key_press_event

GTK and PYGTK references talk about classes, functions and constants but nothing about their interrelation so they don't help. Is it about glib main loop?

I need some examples. Any good GDK tutorial or source code? Any glib.MainLoop example for capturing GDK signals?

Thank you.


Solution

  • You can use gdk_event_handler_set to set the event handler (which is also the function used by gtk). Don't know which python binding u r using but I think you can easily find the corresponding python function. (In gi, it's simply Gdk.Event.handler_set)

    You can check here for an example (There is also a non-block example). Although they are in C.