我怎么能在Gtk3里找到窗户把手?

2024-06-23 03:38:03 发布

您现在位置:Python中文网/ 问答频道 /正文

我在CEF python3(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_窗口().handle]不使用PyGI和GTK3。在

我试着把代码从GTK2移植到GTK3,我该怎么做?在

编辑时间:


经过一番搜索,我找到了一个让获取窗口工作的提示:我打电话:自我容器实现()之前self.container.get_窗口()。但我还拿不到窗户把手。在

我需要把CEF3窗口放在绘图区域或任何元素中。我怎么能和皮吉一起做这个?在

编辑时间:


我的环境是:

Windows 7系统

Python2.7和Python3.2


Tags: 代码self编辑gtkgetcontainer时间link
3条回答

必须首先导入GdkX11,以便get_xid()在返回的GdkX11Window上可用。在

from gi.repository import GdkX11

...

-windowID = self.container.get_window().handle
+windowID = self.container.get_window().get_xid()

遗憾的是,python gobject自省似乎没有任何进展来解决这个问题并使gdk_win32_window_get_handle可用(不久前在gnomebugtracker中报告了一个错误)-python GStreamer和Windows也非常需要它。。。在

所以我按照totaam的建议,使用ctypes访问gdk_win32_window_get_句柄。但我从来都不需要这样的经历。。。在

代码如下: 在

        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()

建议您使用.handle.get_xid()的答案适用于GTK2,但不适用于GTK3或MS-Windows,这是您问题的一部分。在

我做了大量的挖掘,发现GTK3中有一个函数可以实现您想要的功能:gdk_win32_window_get_handle,但遗憾的是,它在gi绑定中不可用。 你可以使用ctypes或Cython(这是我要做的)。在

相关问题 更多 >

    热门问题