问题
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:
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)).
来源:https://stackoverflow.com/questions/6133622/using-cairo-regions-in-python-with-gi-repository