diff --git a/ChangeLog b/ChangeLog index ec353f8f10..609d90bf61 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,15 @@ +2007-11-05 Johan Dahlin + + * gstoptionmodule.c: + * Makefile.am: + * configure.ac: + Add a new module, gstoption which allows you to fetch the + GOptionGroup from gstreamer without initializing and parsing + the command line arguments. Requires PyGObject 2.15.0 + Fixes #425847 + + * examples/option-parser.py (main): Example + 2007-11-01 Johan Dahlin * gst/gst.override: diff --git a/Makefile.am b/Makefile.am index 95a70fa6db..9cd3ced7aa 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,12 +1,28 @@ SUBDIRS = codegen gst examples testsuite pkgconfig win32 = $(shell cat $(top_srcdir)/win32/MANIFEST) +common_cflags = $(PYGOBJECT_CFLAGS) $(GST_CFLAGS) $(GST_OPTION_CFLAGS) -fno-strict-aliasing +common_libadd = $(GST_LIBS) $(GST_OPTION_LIBS) +common_ldflags = -module -avoid-version debug: echo $(win32) ACLOCAL_AMFLAGS = -I common/m4 +pyexec_LTLIBRARIES = + +if HAVE_PYGOBJECT_2_16 +pyexec_LTLIBRARIES += gstoption.la +endif + +# GStreamer option bindings +gstoption_la_CFLAGS = $(common_cflags) +gstoption_la_LIBADD = $(common_libadd) +gstoption_la_LDFLAGS = $(common_ldflags) \ + -export-symbols-regex "^(initgstoption|_PyGObject_API).*" +gstoption_la_SOURCES = gstoptionmodule.c + EXTRA_DIST = \ gstltihooks.py \ pygst.py.in \ diff --git a/common b/common index 34d7d649b9..423e2ea96b 160000 --- a/common +++ b/common @@ -1 +1 @@ -Subproject commit 34d7d649b972ea4915611a6ed88f01613bf32777 +Subproject commit 423e2ea96b5f79281f4dd20d734bd968b3d95e89 diff --git a/configure.ac b/configure.ac index 9f053574f6..92dfeddf2a 100644 --- a/configure.ac +++ b/configure.ac @@ -323,6 +323,17 @@ PKG_CHECK_MODULES(PYGOBJECT_2_12, pygobject-2.0 >= 2.11.1, [Defined if we have a 2.12 series pygobject]) ], HAVE_PYGOBJECT_2_12="no") +dnl FIXME: check for a pygobject which exports pyg_option_group_new +PKG_CHECK_MODULES(PYGOBJECT_2_16, pygobject-2.0 >= 2.15.0, + [ + HAVE_PYGOBJECT_2_16="yes" + AC_MSG_RESULT([yes]) + AC_DEFINE_UNQUOTED(HAVE_PYGOBJECT_2_16, 1, + [Defined if we have a 2.16 series pygobject]) + ], HAVE_PYGOBJECT_2_16="no") + +AM_CONDITIONAL(HAVE_PYGOBJECT_2_16, test x$HAVE_PYGOBJECT_2_16 != xno) + dnl define an ERROR_CFLAGS Makefile variable AG_GST_SET_ERROR_CFLAGS($GST_CVS) diff --git a/examples/option-parser.py b/examples/option-parser.py new file mode 100644 index 0000000000..89e1a6460e --- /dev/null +++ b/examples/option-parser.py @@ -0,0 +1,43 @@ +#!/usr/bin/env python +# -*- Mode: Python -*- +# vi:si:et:sw=4:sts=4:ts=4 + +import sys + +import pygtk +pygtk.require('2.0') + +from gobject.option import OptionParser, OptionGroup +import pygst +pygst.require('0.10') + +import gstoption + +def main(args): + parser = OptionParser() + + group = OptionGroup('flumotion', 'Flumotion options', + option_list=[]) + group.add_option('-v', '--verbose', + action="store_true", dest="verbose", + help="be verbose") + group.add_option('', '--version', + action="store_true", dest="version", + default=False, + help="show version information") + parser.add_option_group(group) + + parser.add_option_group(gstoption.get_group()) + + options, args = parser.parse_args(args) + + if options.verbose: + print 'Verbose mode' + + import gst + + if options.version: + print sys.version, gst.version + +if __name__ == '__main__': + sys.exit(main(sys.argv)) diff --git a/gstoptionmodule.c b/gstoptionmodule.c new file mode 100644 index 0000000000..2e9009bfb4 --- /dev/null +++ b/gstoptionmodule.c @@ -0,0 +1,50 @@ +/* -*- Mode: C; ; c-file-style: "k&r"; c-basic-offset: 4 -*- */ +/* gst-python + * Copyright (C) 2007 Johan Dahlin + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + * + * Author: Johan Dahlin + */ + +#include +#include +#include + +static PyObject * +_wrap_gstoption_get_group (PyObject *self) +{ + GOptionGroup *option_group; + + option_group = gst_init_get_option_group(); + return pyg_option_group_new(option_group); +} + +static PyMethodDef pygstoption_functions[] = { + { "get_group", (PyCFunction)_wrap_gstoption_get_group, METH_NOARGS, NULL }, + { NULL, NULL, 0, NULL } +}; + +DL_EXPORT(void) +initgstoption (void) +{ + init_pygobject (); + + if (!g_thread_supported ()) + g_thread_init (NULL); + + Py_InitModule ("gstoption", pygstoption_functions); +}