没有 GTK 的 GDK 事件处理
我正在(用 python)编程 GDK,而不使用 GTK,只是作为 x11 抽象。这篇文章是我最后的机会。
我的问题是我不知道如何捕获 GDK 窗口的信号/事件或者它们的名称是什么。
当我这样做时:
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)
我得到:
unknown signal name: key_press_event
GTK 和 PYGTK 参考文献讨论了类、函数和常量,但没有讨论它们的相互关系,所以它们没有帮助。 与 glib 主循环有关吗?
我需要一些例子。有好的GDK教程或者源代码吗?任何用于捕获 GDK 信号的 glib.MainLoop 示例?
谢谢。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
可以使用gdk_event_handler_set来设置事件处理程序(这也是gtk使用的函数)。不知道你使用哪个 python 绑定,但我认为你可以轻松找到相应的 python 函数。 (在 gi 中,它只是 Gdk.Event.handler_set)
您可以在此处查看一个示例(还有一个非块示例)。虽然他们在C.
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.
您正在尝试连接到
key-press-event
,这是一个gtk.Widget
信号。gdk.Window
不继承自gtk.Widget
,因此它没有该信号。在 GTK 文档中,顶部附近标有“对象层次结构”的小部分告诉您这些类如何相互关联。确实不存在 GDK 教程这样的东西,因为如果没有 GTK,人们几乎不会使用它。我认为这样做也没有多大用处。也许您可以详细说明您想要实现的目标?
You're trying to connect to
key-press-event
, which is agtk.Widget
signal.gdk.Window
doesn't inherit fromgtk.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?