如何在Gtk3中获取DrawingArea窗口句柄?

ePh*_*ipe 5 python pygobject gtk3 chromium-embedded

我在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'))

    ...
Run Code Online (Sandbox Code Playgroud)

这段代码[ self.container.get_window()。handle ]不适用于PyGI和GTK3。

我尝试将代码从GTK2移植到GTK3,该怎么办?

编辑:


一些搜索后,我发现了一个尖,使get_window工作:我叫:self.container.realize()之前self.container.get_window() 。但是我还没有Window Handle。

我需要将CEF3窗口放在DrawingArea或任何元素内。如何使用PyGI做到这一点?

编辑:


我的环境是:

Windows 7的

Python 2.7和Python 3.2

小智 5

可悲的是,似乎无法在python gobject内省中解决此问题并使其gdk_win32_window_get_handle可用(很久以前就报告了gnome bugtracker中的一个错误)-Python GStreamer和Windows也相当需要它...

因此,我遵循了totaam的建议,并使用ctypes访问gdk_win32_window_get_handle。因为我没有这个经验,所以永远把我带走-嗯,这在某种程度上是一个丑陋的破解-但是在需要时很好...

这是代码:

        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()
Run Code Online (Sandbox Code Playgroud)


Tor*_*gen 0

您必须首先导入GdkX11forget_xid()才能在返回的GdkX11Window.

from gi.repository import GdkX11

...

-windowID = self.container.get_window().handle
+windowID = self.container.get_window().get_xid()
Run Code Online (Sandbox Code Playgroud)