Debian Codegraph @

docs/guide/cairo_integration.rst

raw
1 =================
2 Cairo Integration
3 =================
4
5 Despite `cairo <https://cairographics.org/>`__ not being a GObject based
6 library, PyGObject provides special cairo integration through `pycairo
7 <https://pycairo.readthedocs.io>`__. Functions returning and taking cairo data
8 types get automatically converted to pycairo objects and vice versa.
9
10 Some distros ship the PyGObject cairo support in a separate package. If you've
11 followed the instructions on ":ref:`gettingstarted`" you should have everything
12 installed.
13
14 If your application requires the cairo integration you can use
15 :func:`gi.require_foreign`:
16
17 .. code:: python
18
19 try:
20 gi.require_foreign("cairo")
21 except ImportError:
22 print("No pycairo integration :(")
23
24 Note that PyGObject currently does not support `cairocffi
25 <https://pypi.org/pypi/cairocffi>`__, only pycairo.
26
27
28 Demo
29 ----
30
31 The following example shows a :obj:`Gtk.Window` with a custom drawing in Python
32 using pycairo.
33
34 .. figure:: images/cairo_integration.png
35 :scale: 75%
36 :align: center
37
38 .. literalinclude:: code/cairo-demo.py
39 :linenos: