Using Cairo Regions in python with gi.repository

2019-06-18 14:40发布

I can't seem to get cairo regions working in within using the gintrospection.

For example

from gi.repository import cairo

 reg = cairo.Region()

will give me

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
MemoryError

and trying to get a region from Gdk.get_clip_region() will give me

    return info.invoke(*args)
TypeError: Couldn't find conversion for foreign struct 'cairo.Region'

What obvious thing am I missing? I can't find a way to iniatilize the library, and can't imagine you would need to for regions which seem like a simple struct. I don't know why gdk can't find the cairo types, and am not aware if I"m supposed to show it the way somehow.

1条回答
何必那么认真
2楼-- · 2019-06-18 15:32

Apparently you need to use the regular cairo bindings, even when you use introspection for everything else.

So just import cairo.

(I'm not sure why gi.repository.cairo exists...)

And the "Couldn't find conversion" error will go away when you have all the necessary libraries (e.g. on Ubuntu you need the python-gi-cairo package in addition to python-cairo (or the equivalent python3 packages)).

查看更多
登录 后发表回答