Exemple #1
0
# functions we call. We're doing it directly here because we can, but it would
# not be difficult to use more upstream libraries (e.g. cairocffi and some
# pangocairocffi when it exists). This also allows us to drop pygtk entirely,
# since we are doing our own pango binding.
#
# [1]: https://groups.google.com/forum/#!topic/python-cffi/SPND0rRmazA
#
# This is not intended to be a complete cffi-based pango binding.


try:
    from libqtile._ffi_pango import ffi
except ImportError:
    raise ImportError("No module named libqtile._ffi_pango, be sure to run `./scripts/ffibuild`")

gobject = ffi.dlopen('libgobject-2.0.so.0')
pango = ffi.dlopen('libpango-1.0.so.0')
pangocairo = ffi.dlopen('libpangocairo-1.0.so.0')


def patch_cairo_context(cairo_t):
    def create_layout():
        return PangoLayout(cairo_t._pointer)
    cairo_t.create_layout = create_layout

    def show_layout(layout):
        pangocairo.pango_cairo_show_layout(cairo_t._pointer, layout._pointer)
    cairo_t.show_layout = show_layout

    return cairo_t
Exemple #2
0
import six

try:
    from libqtile._ffi_pango import ffi
except ImportError:
    # PyPy < 2.6 (cffi < 1) compatibility
    import cffi
    if cffi.__version_info__[0] == 0:
        from libqtile.ffi_build import pango_ffi as ffi
    else:
        raise ImportError(
            "No module named libqtile._ffi_pango, be sure to run `python ./libqtile/ffi_build.py`"
        )

gobject = ffi.dlopen('libgobject-2.0.so.0')
pango = ffi.dlopen('libpango-1.0.so.0')
pangocairo = ffi.dlopen('libpangocairo-1.0.so.0')


def CairoContext(cairo_t):
    def create_layout():
        return PangoLayout(cairo_t._pointer)

    cairo_t.create_layout = create_layout

    def show_layout(layout):
        pangocairo.pango_cairo_show_layout(cairo_t._pointer, layout._pointer)

    cairo_t.show_layout = show_layout