diff options
author | Johan Dahlin <johan@gnome.org> | 2008-07-26 09:11:08 +0000 |
---|---|---|
committer | Johan Dahlin <johan@src.gnome.org> | 2008-07-26 09:11:08 +0000 |
commit | 59e8488b49d360992d8df5ca0664ba742411c933 (patch) | |
tree | efd6663aea4774cc469617a3477996fc7960f396 /glib/pyglib.c | |
parent | 7079b546e06dd77b61cd1ba4692a077a85b9e033 (diff) | |
download | pygobject-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
Diffstat (limited to 'glib/pyglib.c')
-rw-r--r-- | glib/pyglib.c | 99 |
1 files changed, 97 insertions, 2 deletions
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; } + |