def cairo_context_from_gi(gicr):
#assert isinstance(gicr, GObject.GBoxed)
offset = sys.getsizeof(object()) # size of PyObject_HEAD
# Pull the "boxed" pointer off out and use it as a cairo_t*
cr_ptr = ctypes.c_void_p.from_address(id(gicr) + offset)
cr = pycairo_dll.PycairoContext_FromContext(cr_ptr, cairo.Context, None)
# Add a new ref because the pycairo context will attempt to manage this
cairo_dll.cairo_reference(cr_ptr)
return cr
评论列表
文章目录