summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohan Dahlin <johan@gnome.org>2008-07-26 09:11:08 +0000
committerJohan Dahlin <johan@src.gnome.org>2008-07-26 09:11:08 +0000
commit59e8488b49d360992d8df5ca0664ba742411c933 (patch)
treeefd6663aea4774cc469617a3477996fc7960f396
parent7079b546e06dd77b61cd1ba4692a077a85b9e033 (diff)
downloadpygobject-59e8488b49d360992d8df5ca0664ba742411c933.tar.gz
pygobject-59e8488b49d360992d8df5ca0664ba742411c933.tar.xz
pygobject-59e8488b49d360992d8df5ca0664ba742411c933.zip
Move option over from gobject to glib.
2008-07-26 Johan Dahlin <johan@gnome.org> * glib/Makefile.am: * glib/glibmodule.c (pyglib_register_constants), (init_glib): * glib/option.py: * glib/pyglib.c (pyglib_init), (pyglib_option_group_transfer_group), (pyglib_option_group_new), (pyglib_option_context_new): * glib/pyglib.h: * glib/pygoptioncontext.c (pyg_option_context_parse), (pyg_option_context_set_main_group), (pyg_option_context_add_group), (pyglib_option_context_register_types): * glib/pygoptioncontext.h: * glib/pygoptiongroup.c (arg_func), (pyglib_option_group_register_types): * glib/pygoptiongroup.h: * gobject/Makefile.am: * gobject/__init__.py: * gobject/gobjectmodule.c (init_gobject): * gobject/option.py: * gobject/pygobject-private.h: * gobject/pygoptioncontext.c: * gobject/pygoptiongroup.c: Move option over from gobject to glib. svn path=/trunk/; revision=860
-rw-r--r--ChangeLog26
-rw-r--r--glib/Makefile.am29
-rw-r--r--glib/glibmodule.c33
-rw-r--r--glib/option.py (renamed from gobject/option.py)52
-rw-r--r--glib/pyglib.c99
-rw-r--r--glib/pyglib.h6
-rw-r--r--glib/pygoptioncontext.c (renamed from gobject/pygoptioncontext.c)39
-rw-r--r--glib/pygoptioncontext.h37
-rw-r--r--glib/pygoptiongroup.c (renamed from gobject/pygoptiongroup.c)60
-rw-r--r--glib/pygoptiongroup.h40
-rw-r--r--gobject/Makefile.am3
-rw-r--r--gobject/__init__.py12
-rw-r--r--gobject/gobjectmodule.c30
-rw-r--r--gobject/pygobject-private.h24
14 files changed, 311 insertions, 179 deletions
diff --git a/ChangeLog b/ChangeLog
index 86c04f9..5e01796 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,31 @@
2008-07-26 Johan Dahlin <johan@gnome.org>
+ * glib/Makefile.am:
+ * glib/glibmodule.c (pyglib_register_constants), (init_glib):
+ * glib/option.py:
+ * glib/pyglib.c (pyglib_init),
+ (pyglib_option_group_transfer_group), (pyglib_option_group_new),
+ (pyglib_option_context_new):
+ * glib/pyglib.h:
+ * glib/pygoptioncontext.c (pyg_option_context_parse),
+ (pyg_option_context_set_main_group),
+ (pyg_option_context_add_group),
+ (pyglib_option_context_register_types):
+ * glib/pygoptioncontext.h:
+ * glib/pygoptiongroup.c (arg_func),
+ (pyglib_option_group_register_types):
+ * glib/pygoptiongroup.h:
+ * gobject/Makefile.am:
+ * gobject/__init__.py:
+ * gobject/gobjectmodule.c (init_gobject):
+ * gobject/option.py:
+ * gobject/pygobject-private.h:
+ * gobject/pygoptioncontext.c:
+ * gobject/pygoptiongroup.c:
+ Move option over from gobject to glib.
+
+2008-07-26 Johan Dahlin <johan@gnome.org>
+
* tests/common.py:
* tests/test_conversion.py:
* tests/test_enum.py:
diff --git a/glib/Makefile.am b/glib/Makefile.am
index c2cbf47..e5be61f 100644
--- a/glib/Makefile.am
+++ b/glib/Makefile.am
@@ -10,7 +10,8 @@ pkgpyexecdir = $(pyexecdir)/gtk-2.0
pyglibdir = $(pkgpyexecdir)/glib
pyglib_PYTHON = \
- __init__.py
+ __init__.py \
+ option.py
pyglib_LTLIBRARIES = _glib.la
common_ldflags = -module -avoid-version
@@ -28,17 +29,21 @@ libpyglib_2_0_la_SOURCES = \
_glib_la_CFLAGS = $(GLIB_CFLAGS)
_glib_la_LDFLAGS = $(common_ldflags) -export-symbols-regex init_glib
_glib_la_LIBADD = $(GLIB_LIBS) libpyglib-2.0.la
-_glib_la_SOURCES = \
- glibmodule.c \
- pygiochannel.c \
- pygiochannel.h \
- pygmaincontext.c \
- pygmaincontext.h \
- pygmainloop.c \
- pygmainloop.h \
- pygsource.c \
- pygsource.h \
- pygspawn.c \
+_glib_la_SOURCES = \
+ glibmodule.c \
+ pygiochannel.c \
+ pygiochannel.h \
+ pygoptioncontext.c \
+ pygoptioncontext.h \
+ pygoptiongroup.c \
+ pygoptiongroup.h \
+ pygmaincontext.c \
+ pygmaincontext.h \
+ pygmainloop.c \
+ pygmainloop.h \
+ pygsource.c \
+ pygsource.h \
+ pygspawn.c \
pygspawn.h
if PLATFORM_WIN32
diff --git a/glib/glibmodule.c b/glib/glibmodule.c
index b4a5b09..dc7afca 100644
--- a/glib/glibmodule.c
+++ b/glib/glibmodule.c
@@ -32,6 +32,8 @@
#include "pygiochannel.h"
#include "pygmaincontext.h"
#include "pygmainloop.h"
+#include "pygoptioncontext.h"
+#include "pygoptiongroup.h"
#include "pygsource.h"
#include "pygspawn.h"
@@ -679,8 +681,35 @@ pyglib_register_constants(PyObject *m)
G_IO_FLAG_GET_MASK);
PyModule_AddIntConstant(m, "IO_FLAG_SET_MASK",
G_IO_FLAG_SET_MASK);
-
+
+ PyModule_AddIntConstant(m, "OPTION_FLAG_HIDDEN",
+ G_OPTION_FLAG_HIDDEN);
+ PyModule_AddIntConstant(m, "OPTION_FLAG_IN_MAIN",
+ G_OPTION_FLAG_IN_MAIN);
+ PyModule_AddIntConstant(m, "OPTION_FLAG_REVERSE",
+ G_OPTION_FLAG_REVERSE);
+ PyModule_AddIntConstant(m, "OPTION_FLAG_NO_ARG",
+ G_OPTION_FLAG_NO_ARG);
+ PyModule_AddIntConstant(m, "OPTION_FLAG_FILENAME",
+ G_OPTION_FLAG_FILENAME);
+ PyModule_AddIntConstant(m, "OPTION_FLAG_OPTIONAL_ARG",
+ G_OPTION_FLAG_OPTIONAL_ARG);
+ PyModule_AddIntConstant(m, "OPTION_FLAG_NOALIAS",
+ G_OPTION_FLAG_NOALIAS);
+
+ PyModule_AddIntConstant(m, "OPTION_ERROR_UNKNOWN_OPTION",
+ G_OPTION_ERROR_UNKNOWN_OPTION);
+ PyModule_AddIntConstant(m, "OPTION_ERROR_BAD_VALUE",
+ G_OPTION_ERROR_BAD_VALUE);
+ PyModule_AddIntConstant(m, "OPTION_ERROR_FAILED",
+ G_OPTION_ERROR_FAILED);
+
+ PyModule_AddStringConstant(m, "OPTION_REMAINING",
+ G_OPTION_REMAINING);
+ PyModule_AddStringConstant(m, "OPTION_ERROR",
+ (char*) g_quark_to_string(G_OPTION_ERROR));
}
+
DL_EXPORT(void)
init_glib(void)
{
@@ -698,4 +727,6 @@ init_glib(void)
pyglib_maincontext_register_types(d);
pyglib_source_register_types(d);
pyglib_spawn_register_types(d);
+ pyglib_option_context_register_types(d);
+ pyglib_option_group_register_types(d);
}
diff --git a/gobject/option.py b/glib/option.py
index eee58d1..034b7b3 100644
--- a/gobject/option.py
+++ b/glib/option.py
@@ -2,7 +2,7 @@
# pygobject - Python bindings for the GObject library
# Copyright (C) 2006 Johannes Hoelzl
#
-# gobject/option.py: GOption command line parser
+# glib/option.py: GOption command line parser
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
@@ -26,7 +26,7 @@ objects. So it is possible to use the gtk, gnome_program and gstreamer command
line groups and contexts.
Use this interface instead of the raw wrappers of GOptionContext and
-GOptionGroup in gobject.
+GOptionGroup in glib.
"""
import sys
@@ -34,9 +34,7 @@ import optparse
from optparse import OptParseError, OptionError, OptionValueError, \
BadOptionError, OptionConflictError
-from glib import GError
-
-import _gobject as gobject
+import _glib
__all__ = [
"OptParseError",
@@ -84,7 +82,7 @@ class Option(optparse.Option):
'optional_arg',
]
- REMAINING = '--' + gobject.OPTION_REMAINING
+ REMAINING = '--' + _glib.OPTION_REMAINING
def __init__(self, *args, **kwargs):
optparse.Option.__init__(self, *args, **kwargs)
@@ -111,19 +109,19 @@ class Option(optparse.Option):
flags = 0
if self.hidden:
- self.flags |= gobject.OPTION_FLAG_HIDDEN
+ self.flags |= _glib.OPTION_FLAG_HIDDEN
if self.in_main:
- self.flags |= gobject.OPTION_FLAG_IN_MAIN
+ self.flags |= _glib.OPTION_FLAG_IN_MAIN
if self.takes_value():
if self.optional_arg:
- flags |= gobject.OPTION_FLAG_OPTIONAL_ARG
+ flags |= _glib.OPTION_FLAG_OPTIONAL_ARG
else:
- flags |= gobject.OPTION_FLAG_NO_ARG
+ flags |= _glib.OPTION_FLAG_NO_ARG
if self.type == 'filename':
- flags |= gobject.OPTION_FLAG_FILENAME
+ flags |= _glib.OPTION_FLAG_FILENAME
for (long_name, short_name) in zip(self._long_opts, self._short_opts):
yield (long_name[2:], short_name[1], flags, self.help, self.metavar)
@@ -185,13 +183,13 @@ class OptionGroup(optparse.OptionGroup):
try:
opt.process(option_name, option_value, self.values, parser)
except OptionValueError, error:
- gerror = GError(str(error))
- gerror.domain = gobject.OPTION_ERROR
- gerror.code = gobject.OPTION_ERROR_BAD_VALUE
+ gerror = _glib.GError(str(error))
+ gerror.domain = _glib.OPTION_ERROR
+ gerror.code = _glib.OPTION_ERROR_BAD_VALUE
gerror.message = str(error)
raise gerror
- group = gobject.OptionGroup(self.name, self.description,
+ group = _glib.OptionGroup(self.name, self.description,
self.help_description, callback)
if self.translation_domain:
group.set_translation_domain(self.translation_domain)
@@ -234,9 +232,9 @@ class OptionParser(optparse.OptionParser):
knwon, the option will be in the result list.
OptionParser.add_option_group() does not only accept OptionGroup instances
- but also gobject.OptionGroup, which is returned by gtk_get_option_group().
+ but also glib.OptionGroup, which is returned by gtk_get_option_group().
- Only gobject.option.OptionGroup and gobject.option.Option instances should
+ Only glib.option.OptionGroup and glib.option.Option instances should
be passed as groups and options.
For further help, see optparse.OptionParser.
@@ -264,12 +262,12 @@ class OptionParser(optparse.OptionParser):
parameter_string = self.usage + " - " + self.description
else:
parameter_string = self.usage
- context = gobject.OptionContext(parameter_string)
+ context = _glib.OptionContext(parameter_string)
context.set_help_enabled(self.help_enabled)
context.set_ignore_unknown_options(self.ignore_unknown_options)
for option_group in self.option_groups:
- if isinstance(option_group, gobject.OptionGroup):
+ if isinstance(option_group, _glib.OptionGroup):
g_group = option_group
else:
g_group = option_group.get_option_group(self)
@@ -282,7 +280,7 @@ class OptionParser(optparse.OptionParser):
opt = self._short_opt[option_name]
opt.process(option_name, option_value, values, self)
- main_group = gobject.OptionGroup(None, None, None, callback)
+ main_group = _glib.OptionGroup(None, None, None, callback)
main_entries = []
for option in self.option_list:
main_entries.extend(option._to_goptionentries())
@@ -302,7 +300,7 @@ class OptionParser(optparse.OptionParser):
args[0].parser = self
if args[0].parser is not self:
raise ValueError("invalid OptionGroup (wrong parser)")
- if isinstance(args[0], gobject.OptionGroup):
+ if isinstance(args[0], _glib.OptionGroup):
self.option_groups.append(args[0])
return
optparse.OptionParser.add_option_group(self, *args, **kwargs)
@@ -316,7 +314,7 @@ class OptionParser(optparse.OptionParser):
def _process_args(self, largs, rargs, values):
context = self._to_goptioncontext(values)
-
+
# _process_args() returns the remaining parameters in rargs.
# The prepended program name is used to all g_set_prgname()
# The program name is cut away so it doesn't appear in the result.
@@ -327,14 +325,14 @@ class OptionParser(optparse.OptionParser):
try:
options, args = optparse.OptionParser.parse_args(
self, args, values)
- except GError, error:
- if error.domain != gobject.OPTION_ERROR:
+ except _glib.GError, error:
+ if error.domain != _glib.OPTION_ERROR:
raise
- if error.code == gobject.OPTION_ERROR_BAD_VALUE:
+ if error.code == _glib.OPTION_ERROR_BAD_VALUE:
raise OptionValueError(error.message)
- elif error.code == gobject.OPTION_ERROR_UNKNOWN_OPTION:
+ elif error.code == _glib.OPTION_ERROR_UNKNOWN_OPTION:
raise BadOptionError(error.message)
- elif error.code == gobject.OPTION_ERROR_FAILED:
+ elif error.code == _glib.OPTION_ERROR_FAILED:
raise OptParseError(error.message)
else:
raise
diff --git a/glib/pyglib.c b/glib/pyglib.c
index 6fbc5bb..f101ec1 100644
--- a/glib/pyglib.c
+++ b/glib/pyglib.c
@@ -28,6 +28,8 @@
#include "pyglib.h"
#include "pyglib-private.h"
#include "pygmaincontext.h"
+#include "pygoptioncontext.h"
+#include "pygoptiongroup.h"
static struct _PyGLib_Functions *_PyGLib_API;
static int pyglib_thread_state_tls_key;
@@ -35,6 +37,12 @@ static int pyglib_thread_state_tls_key;
static PyTypeObject *_PyGMainContext_Type;
#define PyGMainContext_Type (*_PyGMainContext_Type)
+static PyTypeObject *_PyGOptionGroup_Type;
+#define PyGOptionGroup_Type (*_PyGOptionGroup_Type)
+
+static PyTypeObject *_PyGOptionContext_Type;
+#define PyGOptionContext_Type (*_PyGOptionContext_Type)
+
void
pyglib_init(void)
{
@@ -69,6 +77,8 @@ pyglib_init(void)
}
_PyGMainContext_Type = (PyTypeObject*)PyObject_GetAttrString(glib, "MainContext");
+ _PyGOptionGroup_Type = (PyTypeObject*)PyObject_GetAttrString(glib, "OptionGroup");
+ _PyGOptionContext_Type = (PyTypeObject*)PyObject_GetAttrString(glib, "OptionContext");
}
void
@@ -340,6 +350,92 @@ pyglib_main_context_new(GMainContext *context)
}
/**
+ * pyg_option_group_transfer_group:
+ * @group: a GOptionGroup wrapper
+ *
+ * This is used to transfer the GOptionGroup to a GOptionContext. After this
+ * is called, the calle must handle the release of the GOptionGroup.
+ *
+ * When #NULL is returned, the GOptionGroup was already transfered.
+ *
+ * Returns: Either #NULL or the wrapped GOptionGroup.
+ */
+GOptionGroup *
+pyglib_option_group_transfer_group(PyObject *obj)
+{
+ PyGOptionGroup *self = (PyGOptionGroup*)obj;
+
+ if (self->is_in_context)
+ return NULL;
+
+ self->is_in_context = TRUE;
+
+ /* Here we increase the reference count of the PyGOptionGroup, because now
+ * the GOptionContext holds an reference to us (it is the userdata passed
+ * to g_option_group_new().
+ *
+ * The GOptionGroup is freed with the GOptionContext.
+ *
+ * We set it here because if we would do this in the init method we would
+ * hold two references and the PyGOptionGroup would never be freed.
+ */
+ Py_INCREF(self);
+
+ return self->group;
+}
+
+/**
+ * pyglib_option_group_new:
+ * @group: a GOptionGroup
+ *
+ * The returned GOptionGroup can't be used to set any hooks, translation domains
+ * or add entries. It's only intend is, to use for GOptionContext.add_group().
+ *
+ * Returns: the GOptionGroup wrapper.
+ */
+PyObject *
+pyglib_option_group_new (GOptionGroup *group)
+{
+ PyGOptionGroup *self;
+
+ self = (PyGOptionGroup *)PyObject_NEW(PyGOptionGroup,
+ &PyGOptionGroup_Type);
+ if (self == NULL)
+ return NULL;
+
+ self->group = group;
+ self->other_owner = TRUE;
+ self->is_in_context = FALSE;
+
+ return (PyObject *)self;
+}
+
+/**
+ * pyglib_option_context_new:
+ * @context: a GOptionContext
+ *
+ * Returns: A new GOptionContext wrapper.
+ */
+PyObject *
+pyglib_option_context_new (GOptionContext *context)
+{
+ PyGOptionContext *self;
+
+ self = (PyGOptionContext *)PyObject_NEW(PyGOptionContext,
+ &PyGOptionContext_Type);
+ if (self == NULL)
+ return NULL;
+
+ self->context = context;
+ self->main_group = NULL;
+
+ return (PyObject *)self;
+}
+
+
+/****** Private *****/
+
+/**
* _pyglib_destroy_notify:
* @user_data: a PyObject pointer.
*
@@ -359,8 +455,6 @@ _pyglib_destroy_notify(gpointer user_data)
pyglib_gil_state_release(state);
}
-/****** Private *****/
-
gboolean
_pyglib_handler_marshal(gpointer user_data)
{
@@ -388,3 +482,4 @@ _pyglib_handler_marshal(gpointer user_data)
return res;
}
+
diff --git a/glib/pyglib.h b/glib/pyglib.h
index 4b28089..dcc8f8a 100644
--- a/glib/pyglib.h
+++ b/glib/pyglib.h
@@ -38,11 +38,14 @@ gboolean pyglib_enable_threads(void);
gboolean pyglib_error_check(GError **error);
gboolean pyglib_gerror_exception_check(GError **error);
gboolean pyglib_threads_enabled(void);
-PyObject *pyglib_main_context_new(GMainContext *context);
+PyObject * pyglib_main_context_new(GMainContext *context);
void pyglib_set_thread_block_funcs(PyGLibThreadBlockFunc block_threads_func,
PyGLibThreadBlockFunc unblock_threads_func);
void pyglib_block_threads(void);
void pyglib_unblock_threads(void);
+PyObject * pyglib_option_context_new(GOptionContext *context);
+PyObject * pyglib_option_group_new(GOptionGroup *group);
+GOptionGroup * pyglib_option_group_transfer_group(PyObject *self);
#define pyglib_begin_allow_threads \
G_STMT_START { \
@@ -55,6 +58,7 @@ void pyglib_unblock_threads(void);
PyEval_RestoreThread(_save); \
} G_STMT_END
+
G_END_DECLS
#endif /* __PYGLIB_H__ */
diff --git a/gobject/pygoptioncontext.c b/glib/pygoptioncontext.c
index 177b171..2baf36d 100644
--- a/gobject/pygoptioncontext.c
+++ b/glib/pygoptioncontext.c
@@ -24,7 +24,9 @@
# include <config.h>
#endif
-#include "pygobject-private.h"
+#include <pyglib.h>
+#include "pyglib-private.h"
+#include "pygoptioncontext.h"
static int
pyg_option_context_init(PyGOptionContext *self,
@@ -104,17 +106,17 @@ pyg_option_context_parse(PyGOptionContext *self,
g_assert(argv_length <= G_MAXINT);
argv_length_int = argv_length;
- pyg_begin_allow_threads;
+ pyglib_begin_allow_threads;
result = g_option_context_parse(self->context, &argv_length_int, &argv_content,
&error);
- pyg_end_allow_threads;
+ pyglib_end_allow_threads;
argv_length = argv_length_int;
if (!result)
{
g_strfreev(argv_content);
g_strfreev(original);
- pyg_error_check(&error);
+ pyglib_error_check(&error);
return NULL;
}
@@ -184,16 +186,19 @@ pyg_option_context_set_main_group(PyGOptionContext *self,
static char *kwlist[] = { "group", NULL };
GOptionGroup *g_group;
PyObject *group;
+
if (! PyArg_ParseTupleAndKeywords(args, kwargs,
"O:GOptionContext.set_main_group",
kwlist, &group))
return NULL;
+
if (PyObject_IsInstance(group, (PyObject*) &PyGOptionGroup_Type) != 1) {
PyErr_SetString(PyExc_TypeError,
"GOptionContext.set_main_group expects a GOptionGroup.");
return NULL;
}
- g_group = pyg_option_group_transfer_group((PyGOptionGroup*) group);
+
+ g_group = pyglib_option_group_transfer_group((PyGOptionGroup*) group);
if (g_group == NULL)
{
PyErr_SetString(PyExc_RuntimeError, "Group is already in a OptionContext.");
@@ -237,7 +242,7 @@ pyg_option_context_add_group(PyGOptionContext *self,
"GOptionContext.add_group expects a GOptionGroup.");
return NULL;
}
- g_group = pyg_option_group_transfer_group((PyGOptionGroup*) group);
+ g_group = pyglib_option_group_transfer_group((PyGOptionGroup*) group);
if (g_group == NULL)
{
PyErr_SetString(PyExc_RuntimeError,
@@ -313,24 +318,8 @@ PyTypeObject PyGOptionContext_Type = {
(initproc)pyg_option_context_init,
};
-/**
- * pyg_option_context_new:
- * @context: a GOptionContext
- *
- * Returns: A new GOptionContext wrapper.
- */
-PyObject *
-pyg_option_context_new (GOptionContext *context)
+void
+pyglib_option_context_register_types(PyObject *d)
{
- PyGOptionContext *self;
-
- self = (PyGOptionContext *)PyObject_NEW(PyGOptionContext,
- &PyGOptionContext_Type);
- if (self == NULL)
- return NULL;
-
- self->context = context;
- self->main_group = NULL;
-
- return (PyObject *)self;
+ PYGLIB_REGISTER_TYPE(d, PyGOptionContext_Type, "OptionContext");
}
diff --git a/glib/pygoptioncontext.h b/glib/pygoptioncontext.h
new file mode 100644
index 0000000..118d664
--- /dev/null
+++ b/glib/pygoptioncontext.h
@@ -0,0 +1,37 @@
+/* -*- Mode: C; c-basic-offset: 4 -*-
+ * pyglib - Python bindings for GLib toolkit.
+ * Copyright (C) 1998-2003 James Henstridge
+ * 2004-2008 Johan Dahlin
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser 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
+ */
+
+#ifndef __PYG_OPTIONCONTEXT_H__
+#define __PYG_OPTIONCONTEXT_H__
+
+#include "pygoptiongroup.h"
+
+extern PyTypeObject PyGOptionContext_Type;
+
+typedef struct {
+ PyObject_HEAD
+ PyGOptionGroup *main_group;
+ GOptionContext *context;
+} PyGOptionContext;
+
+void pyglib_option_context_register_types(PyObject *d);
+
+#endif /* __PYG_OPTIONCONTEXT_H__ */
diff --git a/gobject/pygoptiongroup.c b/glib/pygoptiongroup.c
index 770a497..cb1d62f 100644
--- a/gobject/pygoptiongroup.c
+++ b/glib/pygoptiongroup.c
@@ -25,8 +25,8 @@
#endif
#include <pyglib.h>
-#include "pygobject-private.h"
-#include "pygobject.h"
+#include "pyglib-private.h"
+#include "pygoptiongroup.h"
static gboolean
check_if_owned(PyGOptionGroup *self)
@@ -129,7 +129,7 @@ arg_func(const gchar *option_name,
}
else
{
- no_error = pyg_gerror_exception_check(error) != -1;
+ no_error = pyglib_gerror_exception_check(error) != -1;
pyglib_gil_state_release(state);
return no_error;
}
@@ -295,59 +295,11 @@ PyTypeObject PyGOptionGroup_Type = {
(initproc)pyg_option_group_init,
};
-/**
- * pyg_option_group_transfer_group:
- * @group: a GOptionGroup wrapper
- *
- * This is used to transfer the GOptionGroup to a GOptionContext. After this
- * is called, the calle must handle the release of the GOptionGroup.
- *
- * When #NULL is returned, the GOptionGroup was already transfered.
- *
- * Returns: Either #NULL or the wrapped GOptionGroup.
- */
-GOptionGroup *
-pyg_option_group_transfer_group(PyGOptionGroup *self)
+void
+pyglib_option_group_register_types(PyObject *d)
{
- if (self->is_in_context) return NULL;
- self->is_in_context = TRUE;
-
- /* Here we increase the reference count of the PyGOptionGroup, because now
- * the GOptionContext holds an reference to us (it is the userdata passed
- * to g_option_group_new().
- *
- * The GOptionGroup is freed with the GOptionContext.
- *
- * We set it here because if we would do this in the init method we would
- * hold two references and the PyGOptionGroup would never be freed.
- */
- Py_INCREF(self);
-
- return self->group;
+ PYGLIB_REGISTER_TYPE(d, PyGOptionGroup_Type, "OptionGroup");
}
-/**
- * pyg_option_group_new:
- * @group: a GOptionGroup
- *
- * The returned GOptionGroup can't be used to set any hooks, translation domains
- * or add entries. It's only intend is, to use for GOptionContext.add_group().
- *
- * Returns: the GOptionGroup wrapper.
- */
-PyObject *
-pyg_option_group_new (GOptionGroup *group)
-{
- PyGOptionGroup *self;
- self = (PyGOptionGroup *)PyObject_NEW(PyGOptionGroup,
- &PyGOptionGroup_Type);
- if (self == NULL)
- return NULL;
- self->group = group;
- self->other_owner = TRUE;
- self->is_in_context = FALSE;
-
- return (PyObject *)self;
-}
diff --git a/glib/pygoptiongroup.h b/glib/pygoptiongroup.h
new file mode 100644
index 0000000..bba8b94
--- /dev/null
+++ b/glib/pygoptiongroup.h
@@ -0,0 +1,40 @@
+/* -*- Mode: C; c-basic-offset: 4 -*-
+ * pyglib - Python bindings for GLib toolkit.
+ * Copyright (C) 1998-2003 James Henstridge
+ * 2004-2008 Johan Dahlin
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser 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
+ */
+
+#ifndef __PYG_OPTIONGROUP_H__
+#define __PYG_OPTIONGROUP_H__
+
+extern PyTypeObject PyGOptionGroup_Type;
+
+typedef struct {
+ PyObject_HEAD
+ GOptionGroup *group;
+ gboolean other_owner, is_in_context;
+ PyObject *callback;
+ GSList *strings; /* all strings added with the entries, are freed on
+ GOptionGroup.destroy() */
+} PyGOptionGroup;
+
+void pyglib_option_group_register_types(PyObject *d);
+
+#endif /* __PYG_OPTIONGROUP_H__ */
+
+
diff --git a/gobject/Makefile.am b/gobject/Makefile.am
index 4a58f3a..44c3741 100644
--- a/gobject/Makefile.am
+++ b/gobject/Makefile.am
@@ -10,7 +10,6 @@ pkgpyexecdir = $(pyexecdir)/gtk-2.0
pygobjectdir = $(pkgpyexecdir)/gobject
pygobject_PYTHON = \
__init__.py \
- option.py \
propertyhelper.py
pygobject_LTLIBRARIES = _gobject.la
nodist_pygobject_PYTHON = constants.py
@@ -54,8 +53,6 @@ _gobject_la_SOURCES = \
pygparamspec.c \
pygpointer.c \
pygtype.c \
- pygoptioncontext.c \
- pygoptiongroup.c
_gobject_la_DEPENDENCIES = constants.py
if HAVE_LIBFFI
diff --git a/gobject/__init__.py b/gobject/__init__.py
index 04b9a31..cf8be3f 100644
--- a/gobject/__init__.py
+++ b/gobject/__init__.py
@@ -20,6 +20,7 @@
# USA
# this can go when things are a little further along
+
try:
import ltihooks
ltihooks # pyflakes
@@ -27,13 +28,15 @@ try:
except ImportError:
pass
+import sys
+
from glib import spawn_async, idle_add, timeout_add, timeout_add_seconds, \
io_add_watch, source_remove, child_watch_add, markup_escape_text, \
get_current_time, filename_display_name, filename_display_basename, \
filename_from_utf8, get_application_name, set_application_name, \
get_prgname, set_prgname, main_depth, Pid, GError, glib_version, \
MainLoop, MainContext, main_context_default, IOChannel, Source, Idle, \
- Timeout, PollFD
+ Timeout, PollFD, OptionGroup, OptionContext, option
from glib import SPAWN_LEAVE_DESCRIPTORS_OPEN, SPAWN_DO_NOT_REAP_CHILD, \
SPAWN_SEARCH_PATH, SPAWN_STDOUT_TO_DEV_NULL, SPAWN_STDERR_TO_DEV_NULL, \
SPAWN_CHILD_INHERITS_STDIN, SPAWN_FILE_AND_ARGV_ZERO, PRIORITY_HIGH, \
@@ -42,7 +45,11 @@ from glib import SPAWN_LEAVE_DESCRIPTORS_OPEN, SPAWN_DO_NOT_REAP_CHILD, \
IO_STATUS_ERROR, IO_STATUS_NORMAL, IO_STATUS_EOF, IO_STATUS_AGAIN, \
IO_FLAG_APPEND, IO_FLAG_NONBLOCK, IO_FLAG_IS_READABLE, \
IO_FLAG_IS_WRITEABLE, IO_FLAG_IS_SEEKABLE, IO_FLAG_MASK, \
- IO_FLAG_GET_MASK, IO_FLAG_SET_MASK
+ IO_FLAG_GET_MASK, IO_FLAG_SET_MASK, OPTION_FLAG_HIDDEN, \
+ OPTION_FLAG_IN_MAIN, OPTION_FLAG_REVERSE, OPTION_FLAG_NO_ARG, \
+ OPTION_FLAG_FILENAME, OPTION_FLAG_OPTIONAL_ARG, OPTION_FLAG_NOALIAS, \
+ OPTION_ERROR_UNKNOWN_OPTION, OPTION_ERROR_BAD_VALUE, \
+ OPTION_ERROR_FAILED, OPTION_REMAINING, OPTION_ERROR
from gobject.constants import *
from _gobject import *
@@ -50,6 +57,7 @@ _PyGObject_API = _gobject._PyGObject_API
from propertyhelper import property
+sys.modules['gobject.option'] = option
class GObjectMeta(type):
"Metaclass for automatically registering GObject classes"
diff --git a/gobject/gobjectmodule.c b/gobject/gobjectmodule.c
index 81b8892..201381a 100644
--- a/gobject/gobjectmodule.c
+++ b/gobject/gobjectmodule.c
@@ -2656,7 +2656,7 @@ struct _PyGObject_Functions pygobject_api_functions = {
pyg_type_register_custom_callback,
pyg_gerror_exception_check,
- pyg_option_group_new
+ pyglib_option_group_new
};
@@ -2753,9 +2753,6 @@ init_gobject(void)
PyType_Ready(&PyGObjectWeakRef_Type);
PyDict_SetItemString(d, "GObjectWeakRef", (PyObject *) &PyGObjectWeakRef_Type);
- REGISTER_TYPE(d, PyGOptionContext_Type, "OptionContext");
- REGISTER_TYPE(d, PyGOptionGroup_Type, "OptionGroup");
-
/* pygobject version */
tuple = Py_BuildValue ("(iii)",
PYGOBJECT_MAJOR_VERSION,
@@ -2795,31 +2792,6 @@ init_gobject(void)
PyModule_AddIntConstant(m, "PARAM_LAX_VALIDATION", G_PARAM_LAX_VALIDATION);
PyModule_AddIntConstant(m, "PARAM_READWRITE", G_PARAM_READWRITE);
- PyModule_AddIntConstant(m, "OPTION_FLAG_HIDDEN",
- G_OPTION_FLAG_HIDDEN);
- PyModule_AddIntConstant(m, "OPTION_FLAG_IN_MAIN",
- G_OPTION_FLAG_IN_MAIN);
- PyModule_AddIntConstant(m, "OPTION_FLAG_REVERSE",
- G_OPTION_FLAG_REVERSE);
- PyModule_AddIntConstant(m, "OPTION_FLAG_NO_ARG",
- G_OPTION_FLAG_NO_ARG);
- PyModule_AddIntConstant(m, "OPTION_FLAG_FILENAME",
- G_OPTION_FLAG_FILENAME);
- PyModule_AddIntConstant(m, "OPTION_FLAG_OPTIONAL_ARG",
- G_OPTION_FLAG_OPTIONAL_ARG);
- PyModule_AddIntConstant(m, "OPTION_FLAG_NOALIAS)",
- G_OPTION_FLAG_NOALIAS);
- PyModule_AddIntConstant(m, "OPTION_ERROR_UNKNOWN_OPTION",
- G_OPTION_ERROR_UNKNOWN_OPTION);
- PyModule_AddIntConstant(m, "OPTION_ERROR_BAD_VALUE",
- G_OPTION_ERROR_BAD_VALUE);
- PyModule_AddIntConstant(m, "OPTION_ERROR_FAILED",
- G_OPTION_ERROR_FAILED);
- PyModule_AddStringConstant(m, "OPTION_REMAINING",
- G_OPTION_REMAINING);
- PyModule_AddStringConstant(m, "OPTION_ERROR",
- (char*) g_quark_to_string(G_OPTION_ERROR));
-
/* The rest of the types are set in __init__.py */
PyModule_AddObject(m, "TYPE_INVALID", pyg_type_wrapper_new(G_TYPE_INVALID));
PyModule_AddObject(m, "TYPE_GSTRING", pyg_type_wrapper_new(G_TYPE_GSTRING));
diff --git a/gobject/pygobject-private.h b/gobject/pygobject-private.h
index 19582d9..34a7e97 100644
--- a/gobject/pygobject-private.h
+++ b/gobject/pygobject-private.h
@@ -222,29 +222,7 @@ extern PyObject * pyg_enum_from_gtype (GType gtype,
extern PyTypeObject PyGParamSpec_Type;
PyObject * pyg_param_spec_new (GParamSpec *pspec);
-/* pygoption.c */
-extern PyTypeObject PyGOptionContext_Type;
-extern PyTypeObject PyGOptionGroup_Type;
-
-typedef struct {
- PyObject_HEAD
- GOptionGroup *group;
- gboolean other_owner, is_in_context;
- PyObject *callback;
- GSList *strings; /* all strings added with the entries, are freed on
- GOptionGroup.destroy() */
-} PyGOptionGroup;
-
-typedef struct {
- PyObject_HEAD
- PyGOptionGroup *main_group;
- GOptionContext *context;
-} PyGOptionContext;
-
-PyObject * pyg_option_context_new (GOptionContext * context);
-PyObject * pyg_option_group_new (GOptionGroup * group);
-GOptionGroup *pyg_option_group_transfer_group(PyGOptionGroup *self);
-
+/* pygtype.c */
extern GHashTable *custom_type_registration;
void pyg_type_register_custom_callback(const gchar *type_name,
PyGTypeRegistrationFunction callback,