Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Cairo Regions in python with gi.repository

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.

like image 248
Nikhil Avatar asked May 26 '11 04:05

Nikhil


1 Answers

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

like image 85
adw Avatar answered Oct 01 '22 01:10

adw