Cannot get window-handle of drawingarea natively on Mac OS and Windows
Submitted by da-mkay
Link to original bug (#762769)
Description
On X11-systems you can simply use the following code to get the window-handle of a drawingarea in python: drawing_area.get_property('window').get_xid()
However this does not work on Windows. Thus you have to access GDK through its C-API:
drawingarea_window = drawingarea.get_property('window')
ctypes.pythonapi.PyCapsule_GetPointer.restype = ctypes.c_void_p
ctypes.pythonapi.PyCapsule_GetPointer.argtypes = [ctypes.py_object]
drawingarea_gpointer = ctypes.pythonapi.PyCapsule_GetPointer(drawingarea_window.__gpointer__, None)
gdkdll = ctypes.CDLL ('libgdk-3-0.dll')
self._drawingarea_handle = gdkdll.gdk_win32_window_get_handle(drawingarea_gpointer)
I tried the same on Mac OS to call gdkdll.gdk_quartz_window_get_nswindow, but this leads only to a Segmentation fault.
It would be nice to have a method like get_xid() for Windows/Mac OS. Or at least a workaround to get the handle in Mac OS ;)
See also: http://stackoverflow.com/questions/35669176/get-the-window-handle-in-pygi-on-macos
Edited by Christoph Reiter