Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How I can get DrawingArea window handle in Gtk3?

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

    ...

This code [self.container.get_window().handle] don't work with PyGI and GTK3.

I trying port the code from GTK2 to GTK3, how I can do this?

Edited:


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.

I need put CEF3 window inside a DrawingArea or any element. How I can do this with PyGI?

Edited:


My environment is:

Windows 7

Python 2.7 and Python 3.2

like image 489
ePhillipe Avatar asked Apr 11 '14 19:04

ePhillipe


1 Answers

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 ...

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()
like image 138
Marwin Schmitt Avatar answered Oct 02 '22 00:10

Marwin Schmitt