diff options
-rw-r--r-- | ChangeLog | 13 | ||||
-rw-r--r-- | glib/glibmodule.c | 2 | ||||
-rw-r--r-- | glib/pygoptioncontext.c | 87 | ||||
-rw-r--r-- | glib/pygoptiongroup.c | 97 |
4 files changed, 112 insertions, 87 deletions
@@ -1,3 +1,16 @@ +2008-08-02 Johan Dahlin <johan@gnome.org> + + * glib/glibmodule.c (pyglib_set_prgname): + * glib/pygoptioncontext.c (pyg_option_context_init), + (pyg_option_context_set_help_enabled), + (pyg_option_context_set_ignore_unknown_options), + (pyg_option_context_set_main_group), + (pyg_option_context_add_group): + * glib/pygoptiongroup.c (arg_func), (pyg_option_group_add_entries), + (pyg_option_group_set_translation_domain), + (pyg_option_group_compare), (pyglib_option_group_register_types): + Fix compilation warnings, clean up style and indentation. + 2008-08-02 Gian Mario Tagliaretti <gianmt@gnome.org> Bug 545959 – Wrap GFile.append_to_async diff --git a/glib/glibmodule.c b/glib/glibmodule.c index 446be87..4d5aa42 100644 --- a/glib/glibmodule.c +++ b/glib/glibmodule.c @@ -516,7 +516,7 @@ pyglib_set_prgname(PyObject *self, PyObject *arg) { if (!PyString_Check(arg)) { PyErr_Format(PyExc_TypeError, - "first argument must be a string, not %r", + "first argument must be a string, not '%s'", PyString_AS_STRING(PyObject_Repr(arg))); return NULL; } diff --git a/glib/pygoptioncontext.c b/glib/pygoptioncontext.c index a180565..cf82744 100644 --- a/glib/pygoptioncontext.c +++ b/glib/pygoptioncontext.c @@ -31,15 +31,16 @@ PYGLIB_DEFINE_TYPE("glib.OptionContext", PyGOptionContext_Type, PyGOptionContext) static int -pyg_option_context_init(PyGOptionContext *self, +pyg_option_context_init(PyGOptionContext *self, PyObject *args, PyObject *kwargs) { char *parameter_string; + if (!PyArg_ParseTuple(args, "s:glib.GOptionContext.__init__", ¶meter_string)) return -1; - + self->context = g_option_context_new(parameter_string); return 0; } @@ -48,7 +49,7 @@ static void pyg_option_context_dealloc(PyGOptionContext *self) { Py_CLEAR(self->main_group); - + if (self->context != NULL) { GOptionContext *tmp = self->context; @@ -60,8 +61,8 @@ pyg_option_context_dealloc(PyGOptionContext *self) } static PyObject * -pyg_option_context_parse(PyGOptionContext *self, - PyObject *args, +pyg_option_context_parse(PyGOptionContext *self, + PyObject *args, PyObject *kwargs) { static char *kwlist[] = { "argv", NULL }; @@ -72,26 +73,26 @@ pyg_option_context_parse(PyGOptionContext *self, char **argv_content, **original; GError *error = NULL; gboolean result; - - if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O:GOptionContext.parse", + + if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O:GOptionContext.parse", kwlist, &argv)) return NULL; - + if (!PyList_Check(argv)) { - PyErr_SetString(PyExc_TypeError, + PyErr_SetString(PyExc_TypeError, "GOptionContext.parse expects a list of strings."); return NULL; } - + argv_length = PyList_Size(argv); if (argv_length == -1) { - PyErr_SetString(PyExc_TypeError, + PyErr_SetString(PyExc_TypeError, "GOptionContext.parse expects a list of strings."); return NULL; } - + argv_content = g_new(char*, argv_length + 1); argv_content[argv_length] = NULL; for (pos = 0; pos < argv_length; pos++) @@ -121,31 +122,34 @@ pyg_option_context_parse(PyGOptionContext *self, pyglib_error_check(&error); return NULL; } - + new_argv = PyList_New(g_strv_length(argv_content)); for (pos = 0; pos < argv_length; pos++) { arg = _PyUnicode_FromString(argv_content[pos]); PyList_SetItem(new_argv, pos, arg); } - + g_strfreev(original); g_strfreev(argv_content); return new_argv; } static PyObject * -pyg_option_context_set_help_enabled(PyGOptionContext *self, +pyg_option_context_set_help_enabled(PyGOptionContext *self, PyObject *args, PyObject *kwargs) { static char *kwlist[] = { "help_enable", NULL }; + PyObject *help_enabled; - if (! PyArg_ParseTupleAndKeywords(args, kwargs, - "O:GOptionContext.set_help_enabled", + if (! PyArg_ParseTupleAndKeywords(args, kwargs, + "O:GOptionContext.set_help_enabled", kwlist, &help_enabled)) return NULL; + g_option_context_set_help_enabled(self->context, PyObject_IsTrue(help_enabled)); + Py_INCREF(Py_None); return Py_None; } @@ -157,18 +161,22 @@ pyg_option_context_get_help_enabled(PyGOptionContext *self) } static PyObject * -pyg_option_context_set_ignore_unknown_options(PyGOptionContext *self, +pyg_option_context_set_ignore_unknown_options(PyGOptionContext *self, PyObject *args, PyObject *kwargs) { static char *kwlist[] = { "ignore_unknown_options", NULL }; PyObject *ignore_unknown_options; - if (! PyArg_ParseTupleAndKeywords(args, kwargs, - "O:GOptionContext.set_ignore_unknown_options", + + if (! PyArg_ParseTupleAndKeywords(args, kwargs, + "O:GOptionContext.set_ignore_unknown_options", kwlist, &ignore_unknown_options)) return NULL; - g_option_context_set_ignore_unknown_options(self->context, - PyObject_IsTrue(ignore_unknown_options)); + + g_option_context_set_ignore_unknown_options(self->context, + PyObject_IsTrue(ignore_unknown_options)); + + Py_INCREF(Py_None); return Py_None; } @@ -181,21 +189,21 @@ pyg_option_context_get_ignore_unknown_options(PyGOptionContext *self) } static PyObject * -pyg_option_context_set_main_group(PyGOptionContext *self, - PyObject *args, +pyg_option_context_set_main_group(PyGOptionContext *self, + PyObject *args, PyObject *kwargs) { static char *kwlist[] = { "group", NULL }; GOptionGroup *g_group; PyObject *group; - - if (! PyArg_ParseTupleAndKeywords(args, kwargs, - "O:GOptionContext.set_main_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, + PyErr_SetString(PyExc_TypeError, "GOptionContext.set_main_group expects a GOptionGroup."); return NULL; } @@ -209,9 +217,10 @@ pyg_option_context_set_main_group(PyGOptionContext *self, } g_option_context_set_main_group(self->context, g_group); + Py_INCREF(group); self->main_group = (PyGOptionGroup*) group; - + Py_INCREF(Py_None); return Py_None; } @@ -223,41 +232,45 @@ pyg_option_context_get_main_group(PyGOptionContext *self) { Py_INCREF(Py_None); return Py_None; - } + } Py_INCREF(self->main_group); return (PyObject*) self->main_group; } static PyObject * -pyg_option_context_add_group(PyGOptionContext *self, - PyObject *args, +pyg_option_context_add_group(PyGOptionContext *self, + PyObject *args, PyObject *kwargs) { static char *kwlist[] = { "group", NULL }; GOptionGroup *g_group; PyObject *group; - if (! PyArg_ParseTupleAndKeywords(args, kwargs, - "O:GOptionContext.add_group", + + if (! PyArg_ParseTupleAndKeywords(args, kwargs, + "O:GOptionContext.add_group", kwlist, &group)) return NULL; + if (PyObject_IsInstance(group, (PyObject*) &PyGOptionGroup_Type) != 1) { PyErr_SetString(PyExc_TypeError, "GOptionContext.add_group expects a GOptionGroup."); return NULL; } + g_group = pyglib_option_group_transfer_group(group); if (g_group == NULL) { - PyErr_SetString(PyExc_RuntimeError, + PyErr_SetString(PyExc_RuntimeError, "Group is already in a OptionContext."); return NULL; } Py_INCREF(group); + g_option_context_add_group(self->context, g_group); - + Py_INCREF(Py_None); return Py_None; -} +} static int pyg_option_context_compare(PyGOptionContext *self, PyGOptionContext *context) 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"); } - - - |