user504806
user504806

Reputation:

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.

Upvotes: 3

Views: 1353

Answers (2)

yuyichao
yuyichao

Reputation: 776

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.

Upvotes: 1

ptomato
ptomato

Reputation: 57854

You're trying to connect to key-press-event, which is a gtk.Widget signal. gdk.Window doesn't inherit from gtk.Widget, so it doesn't have that signal.

In the GTK documentation, the little sections near the top labeled "Object Hierarchy" tell you how the classes relate together. There isn't really such thing as a GDK tutorial since one hardly ever uses it without GTK. I don't think it's very useful to do so either. Perhaps you can elaborate on what you are trying to achieve?

Upvotes: 1

Related Questions