summaryrefslogtreecommitdiff
path: root/gtk/gtkobject-support.c
diff options
context:
space:
mode:
authorJohn Finlay <finlay@src.gnome.org>2006-06-14 08:19:12 +0000
committerJohn Finlay <finlay@src.gnome.org>2006-06-14 08:19:12 +0000
commit5832ac858de60cec000e7792875de0ee77e43334 (patch)
tree06d1712d582dc973c3fa298b11ed58aa5d2f6be4 /gtk/gtkobject-support.c
parentaba9ecd5a4a30ff97d94a42455b5329ebd2922fe (diff)
downloadpygtk-5832ac858de60cec000e7792875de0ee77e43334.tar.gz
Use pygtk_target_list_from_sequence and pygtk_target_list_to_list.
* gtk/gtktextview.override (_wrap_gtk_text_buffer_get_copy_target_list): * gtk/gtk.override (_wrap_gtk_drag_dest_find_target) (_wrap_gtk_drag_dest_get_target_list) (_wrap_gtk_drag_dest_set_target_list, _wrap_gtk_drag_begin) (_wrap_gtk_drag_source_get_target_list) (_wrap_gtk_drag_source_set_target_list) (_wrap_gtk_target_list_add_text_targets) (_wrap_gtk_target_list_add_image_targets) (_wrap_gtk_target_list_add_uri_targets) (_wrap_gtk_target_list_add_rich_text_targets): Use pygtk_target_list_from_sequence and pygtk_target_list_to_list. * gtk/gtkobject-support.c (pygtk_target_list_from_sequence) (pygtk_target_list_to_list): Add.
Diffstat (limited to 'gtk/gtkobject-support.c')
-rw-r--r--gtk/gtkobject-support.c53
1 files changed, 52 insertions, 1 deletions
diff --git a/gtk/gtkobject-support.c b/gtk/gtkobject-support.c
index d5e181fc..a6c072f1 100644
--- a/gtk/gtkobject-support.c
+++ b/gtk/gtkobject-support.c
@@ -1,6 +1,6 @@
/* -*- Mode: C; c-basic-offset: 4 -*-
* pygtk- Python bindings for the GTK toolkit.
- * Copyright (C) 1998-2003 James Henstridge
+ * Copyright (C) 1998-2006 James Henstridge
*
* gtkobject-support.c: some helper routines for the GTK module.
*
@@ -69,3 +69,54 @@ pygdk_atom_vector_from_sequence(PyObject *py_targets, gint *n_targets)
Py_DECREF(py_targets);
return targets;
}
+
+GtkTargetList *
+pygtk_target_list_from_sequence(PyObject *py_targets)
+{
+ gint n_targets, i;
+ GtkTargetEntry *targets;
+ GtkTargetList *target_list;
+
+ if (!(py_targets = PySequence_Fast(py_targets,
+ "target list must be a sequence")))
+ return NULL;
+ n_targets = PySequence_Fast_GET_SIZE(py_targets);
+ targets = g_new(GtkTargetEntry, n_targets);
+ for (i = 0; i < n_targets; i++) {
+ PyObject *item = PySequence_Fast_GET_ITEM(py_targets, i);
+ if (!PyArg_ParseTuple(item, "sii", &targets[i].target,
+ &targets[i].flags, &targets[i].info)) {
+ PyErr_Clear();
+ PyErr_SetString(PyExc_TypeError,
+ "target list items should be of form (string,int,int)");
+ g_free(targets);
+ Py_DECREF(py_targets);
+ return NULL;
+ }
+ }
+ target_list = gtk_target_list_new(targets, n_targets);
+ g_free(targets);
+ Py_DECREF(py_targets);
+ return target_list;
+}
+
+PyObject *
+pygtk_target_list_to_list(GtkTargetList *targets)
+{
+ GList *tmp;
+ PyObject *list = PyList_New(0);
+
+ for (tmp = targets->list; tmp != NULL; tmp = tmp->next) {
+ GtkTargetPair *pair = tmp->data;
+ PyObject *item;
+ gchar * name = gdk_atom_name(pair->target);
+ item = Py_BuildValue("(Nii)",
+ PyString_FromString(name),
+ pair->flags, pair->info);
+ PyList_Append(list, item);
+ g_free(name);
+ Py_DECREF(item);
+ }
+ return list;
+}
+