FAQ Index - Search - Recent Changes - Everything - Add entry

<< Previous Entry | FAQ Entry 1.11 | Next Entry >>

1.11. How do I extend PyGTK (or the art of wrapping)

In order to make a new wrapper for PyGObject/PyGTK, you can use this FAQ as a guideline or checklist. Don't miss out FAQ 6.3 which has a link to an online article, additionally.

Let's call the library "foo" (how original)

1) foo.defs.

   h2defs.py /usr/include/foo-1.0/*.h > foo.defs
2) foomodule.c

3) foo.override

4) Makefile.am

  AUTOMAKE_OPTIONS=1.5

  INCLUDES = $(PYTHON_INCLUDES) $(FOO_CFLAGS)

  # foo module
  pyexec_LTLIBRARIES = foomodule.la
  foomodule_la_LDFLAGS = -module -avoid-version -export-symbols-regex initfoo
  foomodule_la_LIBADD = $(FOO_LIBS)
  foomodule_la_SOURCES = foomodule.c
  nodist_foomodule_la_SOURCES = foo.c
  foo.c: foo.defs foo.override
  CLEANFILES = foo.c
  EXTRA_DIST = foo.override

  .defs.c:
        (cd $(srcdir)\
         && $(PYTHON) codegen/codegen.py \
            --override $*.override \
            --prefix py$* $*.defs) > gen-$*.c \
        && cp gen-$*.c $*.c \
        && rm -f gen-$*.c

 ---
 Should be enough for you to get started
5) configure.in

  PKG_CHECK_MODULES(FOO, foo >= 1.2,,)
  AC_SUBST(FOO_CFLAGS)
  AC_SUBST(FOO_LIBS)
Finally, copy autogen.sh and hopefully you'll have most functions wrapped.

Eventually you'll have to wrap a few functions by hand, functions that the code generator cannot handle. Mostly functions with inout params (**) and GSList/GList parameters.

PyGTK FAQ Wizard | PyGTK Homepage | Feedback to faq at pygtk.org