diff options
Diffstat (limited to 'glib/pygoptiongroup.c')
-rw-r--r-- | glib/pygoptiongroup.c | 97 |
1 files changed, 48 insertions, 49 deletions
diff --git a/glib/pygoptiongroup.c b/glib/pygoptiongroup.c index 2fdca54..5b61cb8 100644 --- a/glib/pygoptiongroup.c +++ b/glib/pygoptiongroup.c @@ -1,5 +1,5 @@ /* -*- Mode: C; c-basic-offset: 4 -*- - * pygtk- Python bindings for the GTK toolkit. + * pygobject - Python bindings for the GLib, GObject and GIO * Copyright (C) 2006 Johannes Hoelzl * * pygoptiongroup.c: GOptionContext and GOptionGroup wrapper @@ -53,36 +53,36 @@ destroy_g_group(PyGOptionGroup *self) g_slist_foreach(self->strings, (GFunc) g_free, NULL); g_slist_free(self->strings); self->strings = NULL; - + if (self->is_in_context) { Py_DECREF(self); } - + pyglib_gil_state_release(state); } static int pyg_option_group_init(PyGOptionGroup *self, PyObject *args, PyObject *kwargs) { - static char *kwlist[] = { "name", "description", "help_description", + static char *kwlist[] = { "name", "description", "help_description", "callback", NULL }; char *name, *description, *help_description; PyObject *callback; - + if (!PyArg_ParseTupleAndKeywords(args, kwargs, "zzzO:GOptionGroup.__init__", - kwlist, &name, &description, + kwlist, &name, &description, &help_description, &callback)) return -1; - + self->group = g_option_group_new(name, description, help_description, self, (GDestroyNotify) destroy_g_group); self->other_owner = FALSE; self->is_in_context = FALSE; - + Py_INCREF(callback); self->callback = callback; - + return 0; } @@ -100,7 +100,7 @@ pyg_option_group_dealloc(PyGOptionGroup *self) PyObject_Del(self); } -static gboolean +static gboolean arg_func(const gchar *option_name, const gchar *value, PyGOptionGroup *self, @@ -109,52 +109,46 @@ arg_func(const gchar *option_name, PyObject *ret; PyGILState_STATE state; gboolean no_error; - + state = pyglib_gil_state_ensure(); - + if (value == NULL) - { - ret = PyObject_CallFunction(self->callback, "sOO", + ret = PyObject_CallFunction(self->callback, "sOO", option_name, Py_None, self); - } else - { - ret = PyObject_CallFunction(self->callback, "ssO", + ret = PyObject_CallFunction(self->callback, "ssO", option_name, value, self); - } - + if (ret != NULL) { Py_DECREF(ret); - pyglib_gil_state_release(state); - return TRUE; - } - else - { - no_error = pyglib_gerror_exception_check(error) != -1; - pyglib_gil_state_release(state); - return no_error; - } + no_error = TRUE; + } else + no_error = pyglib_gerror_exception_check(error) != -1; + + pyglib_gil_state_release(state); + return no_error; } static PyObject * -pyg_option_group_add_entries(PyGOptionGroup *self, PyObject *args, +pyg_option_group_add_entries(PyGOptionGroup *self, PyObject *args, PyObject *kwargs) { static char *kwlist[] = { "entries", NULL }; gssize entry_count, pos; PyObject *entry_tuple, *list; GOptionEntry *entries; - - if (check_if_owned(self)) return NULL; - + + if (check_if_owned(self)) + return NULL; + if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O:GOptionGroup.add_entries", kwlist, &list)) return NULL; - + if (!PyList_Check(list)) { - PyErr_SetString(PyExc_TypeError, + PyErr_SetString(PyExc_TypeError, "GOptionGroup.add_entries expected a list of entries"); return NULL; } @@ -162,11 +156,11 @@ pyg_option_group_add_entries(PyGOptionGroup *self, PyObject *args, entry_count = PyList_Size(list); if (entry_count == -1) { - PyErr_SetString(PyExc_TypeError, + PyErr_SetString(PyExc_TypeError, "GOptionGroup.add_entries expected a list of entries"); return NULL; } - + entries = g_new0(GOptionEntry, entry_count + 1); for (pos = 0; pos < entry_count; pos++) { @@ -202,13 +196,13 @@ pyg_option_group_add_entries(PyGOptionGroup *self, PyObject *args, arg_description = g_strdup(arg_description); self->strings = g_slist_prepend(self->strings, arg_description); entries[pos].arg_description = arg_description; - + entries[pos].arg = G_OPTION_ARG_CALLBACK; entries[pos].arg_data = arg_func; } - + g_option_group_add_entries(self->group, entries); - + g_free(entries); Py_INCREF(Py_None); @@ -217,26 +211,31 @@ pyg_option_group_add_entries(PyGOptionGroup *self, PyObject *args, static PyObject * -pyg_option_group_set_translation_domain(PyGOptionGroup *self, - PyObject *args, +pyg_option_group_set_translation_domain(PyGOptionGroup *self, + PyObject *args, PyObject *kwargs) { static char *kwlist[] = { "domain", NULL }; char *domain; - if (check_if_owned(self)) return NULL; + + if (check_if_owned(self)) + return NULL; if (self->group == NULL) { - PyErr_SetString(PyExc_RuntimeError, + PyErr_SetString(PyExc_RuntimeError, "The corresponding GOptionGroup was already freed, " "probably through the release of GOptionContext"); return NULL; } - if (!PyArg_ParseTupleAndKeywords(args, kwargs, - "z:GOptionGroup.set_translate_domain", + + if (!PyArg_ParseTupleAndKeywords(args, kwargs, + "z:GOptionGroup.set_translate_domain", kwlist, &domain)) return NULL; + g_option_group_set_translation_domain(self->group, domain); + Py_INCREF(Py_None); return Py_None; } @@ -244,9 +243,12 @@ pyg_option_group_set_translation_domain(PyGOptionGroup *self, static int pyg_option_group_compare(PyGOptionGroup *self, PyGOptionGroup *group) { - if (self->group == group->group) return 0; + if (self->group == group->group) + return 0; + if (self->group > group->group) return 1; + return -1; } @@ -266,6 +268,3 @@ pyglib_option_group_register_types(PyObject *d) PyGOptionGroup_Type.tp_init = (initproc)pyg_option_group_init; PYGLIB_REGISTER_TYPE(d, PyGOptionGroup_Type, "OptionGroup"); } - - - |