1.

How Do I Extend Pygtk (or The Art Of Wrapping)?

Answer»

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.

  • Use h2defs.py found in pyobject/codegen/ on all your _public_ headers for the library.

h2defs.py /usr/include/foo-1.0/*.h > foo.defs

2) foomodule.c

  • Use atkmodule.c as a template. Replace all instances of atk with foo.
  • You most probably won't use any constants (since they require additional work), so just comment out pyatk_add_constants (m, "ATK_");

3) foo.override

  • You can also use atkmodule.c as a template for the override file.
  • Remove the only function in there (atk_relation_new) and replace the atk headers with your own.
  • Don't forget to replace the modulename too.

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

  • Copy pygobjects configure and remove unnecessary stuff. Should be trivial. Don't forget to define a FOO_LIBS and FOO_CFLAGS

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.

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.



Discussion

No Comment Found