如何在Gtk3中获取DrawingArea窗口句柄? [英] How I can get DrawingArea window handle in Gtk3?
问题描述
我在CEF Python 3上获得了以下代码(链接)
I get this code on CEF Python 3 (link)
...
self.container = gtk.DrawingArea()
self.container.set_property('can-focus', True)
self.container.connect('size-allocate', self.OnSize)
self.container.show()
...
windowID = self.container.get_window().handle
windowInfo = cefpython.WindowInfo()
windowInfo.SetAsChild(windowID)
self.browser = cefpython.CreateBrowserSync(windowInfo,
browserSettings={},
navigateUrl=GetApplicationPath('example.html'))
...
此代码[ self.container.get_window()。handle ]不能与PyGI和GTK3一起使用。
This code [self.container.get_window().handle] don't work with PyGI and GTK3.
我试图将代码从GTK2移植到GTK3,该怎么办?
I trying port the code from GTK2 to GTK3, how I can do this?
已编辑:
经过一番搜索,我找到了使 get_window 工作的提示:我打电话给 self.container.realize() self.container.get_window()。但是我还没有Window Handle。
After some search, I found a tip to make get_window work: I call: self.container.realize() before self.container.get_window(). But I cant't get Window Handle yet.
我需要将CEF3窗口放在DrawingArea或任何元素中。我如何使用PyGI做到这一点?
I need put CEF3 window inside a DrawingArea or any element. How I can do this with PyGI?
编辑:
我的环境是:
Windows 7
Windows 7
Python 2.7和Python 3.2
Python 2.7 and Python 3.2
推荐答案
遗憾的是,python gobject自省似乎无法解决此问题,并使 gdk_win32_window_get_handle
可用(在很久以前就报告了gnome bugtracker中的一个错误)-Python GStreamer和Windows也非常需要它...
Sadly there seems to be no progress on the python gobject introspection to fix this and make gdk_win32_window_get_handle
available (reported a bug in the gnome bugtracker quite a while ago) - it is also quite needed for Python GStreamer and Windows ...
所以我遵循了totaam的建议并使用了ctypes访问gdk_win32_window_get_handle。因为我没有这个经验,所以永远把我拿走了-嗯,这真是个丑陋的骇客-但是在需要的时候......
So I followed the suggestion of totaam and used ctypes to access gdk_win32_window_get_handle. Took me forever since I had no experience with this - and well it is somehow quite an ugly hack - but well when needed...
这里是代码:
Here is the code:
Gdk.threads_enter()
#get the gdk window and the corresponding c gpointer
drawingareawnd = drawingarea.get_property("window")
#make sure to call ensure_native before e.g. on realize
if not drawingareawnd.has_native():
print("Your window is gonna freeze as soon as you move or resize it...")
ctypes.pythonapi.PyCapsule_GetPointer.restype = ctypes.c_void_p
ctypes.pythonapi.PyCapsule_GetPointer.argtypes = [ctypes.py_object]
drawingarea_gpointer = ctypes.pythonapi.PyCapsule_GetPointer(drawingareawnd.__gpointer__, None)
#get the win32 handle
gdkdll = ctypes.CDLL ("libgdk-3-0.dll")
hnd = gdkdll.gdk_win32_window_get_handle(drawingarea_gpointer)
#do what you want with it ... I pass it to a gstreamer videosink
Gdk.threads_leave()
这篇关于如何在Gtk3中获取DrawingArea窗口句柄?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!