From 807239aac5d1a8ae7ab1e3e2360d54ee572bbfdd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mariano=20Su=C3=A1rez-Alvarez?= Date: Fri, 8 May 2009 21:39:53 +0300 Subject: Wrap gtk.Border attributes and constructor Closes bug #414779. --- gtk/Makefile.am | 1 + gtk/gtk-base.defs | 6 ++ gtk/gtk.override | 1 + gtk/gtkborder.override | 159 +++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 167 insertions(+) create mode 100644 gtk/gtkborder.override (limited to 'gtk') diff --git a/gtk/Makefile.am b/gtk/Makefile.am index 0f92ae8e..690a6aa2 100644 --- a/gtk/Makefile.am +++ b/gtk/Makefile.am @@ -102,6 +102,7 @@ GDK_OVERRIDES = \ GTK_OVERRIDES = \ gtk.override \ + gtkborder.override \ gtkbuilder.override \ gtkclist.override \ gtkcontainer.override \ diff --git a/gtk/gtk-base.defs b/gtk/gtk-base.defs index 3cdfc8f2..7daf5c96 100644 --- a/gtk/gtk-base.defs +++ b/gtk/gtk-base.defs @@ -17489,6 +17489,12 @@ ) ) +(define-function gtk_border_new + (c-name "gtk_border_new") + (is-constructor-of "GtkBorder") + (return-type "GtkBorder") +) + (define-function gtk_border_get_type (c-name "gtk_border_get_type") (return-type "GType") diff --git a/gtk/gtk.override b/gtk/gtk.override index a3a9b74a..f5babed9 100644 --- a/gtk/gtk.override +++ b/gtk/gtk.override @@ -130,6 +130,7 @@ static int _loop(void) %% include + gtkborder.override gtkbuilder.override gtkclist.override gtkcontainer.override diff --git a/gtk/gtkborder.override b/gtk/gtkborder.override new file mode 100644 index 00000000..e24d3737 --- /dev/null +++ b/gtk/gtkborder.override @@ -0,0 +1,159 @@ +/* -*- Mode: C; c-basic-offset: 4 -*- + * pygtk- Python bindings for the GTK toolkit. + * Copyright (C) 2007 Mariano Suárez-Alvarez + * + * gtkborder.override: gtk.Border overrides + * + * 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 + */ +%% +override gtk_border_new kwargs +static int +_wrap_gtk_border_new(PyGBoxed *self, PyObject *args, PyObject *kwargs) +{ + static char *kwlist[] = { "left", "right", "top", "bottom", NULL }; + GtkBorder border = {0, 0, 0, 0}; + + if (!PyArg_ParseTupleAndKeywords(args, kwargs, + "|iiii:GdkRectangle.__init__", + kwlist, &border.left, &border.right, + &border.top, &border.bottom)) + return -1; + + self->boxed = g_boxed_copy(GTK_TYPE_BORDER, &border); + self->free_on_dealloc = TRUE; + self->gtype = GTK_TYPE_BORDER; + + return 0; +} +%% +override-slot GtkBorder.tp_as_sequence +static Py_ssize_t +_wrap_gtk_border_length(PyGBoxed *self) +{ + return 4; +} +static PyObject * +_wrap_gtk_border_getitem(PyGBoxed *self, Py_ssize_t pos) +{ + GtkBorder *border; + + if (pos < 0) + pos += 4; + if (pos < 0 || pos >= 4) { + PyErr_SetString(PyExc_IndexError, "index out of range"); + return NULL; + } + border = pyg_boxed_get(self, GtkBorder); + switch (pos) { + case 0: return PyInt_FromLong(border->left); + case 1: return PyInt_FromLong(border->right); + case 2: return PyInt_FromLong(border->top); + case 3: return PyInt_FromLong(border->bottom); + default: + g_assert_not_reached(); + return NULL; + } +} +static int +_wrap_gtk_border_setitem(PyGBoxed *self, Py_ssize_t pos, PyObject *value) +{ + GtkBorder *border; + gint val; + + if (pos < 0) + pos += 4; + if (pos < 0 || pos >= 4) { + PyErr_SetString(PyExc_IndexError, "index out of range"); + return -1; + } + border = pyg_boxed_get(self, GtkBorder); + val = PyInt_AsLong(value); + if (PyErr_Occurred()) + return -1; + switch(pos) { + case 0: border->left = val; break; + case 1: border->right = val; break; + case 2: border->top = val; break; + case 3: border->bottom = val; break; + default: + g_assert_not_reached(); + return -1; + } + return 0; +} +static PySequenceMethods _wrap_gtk_border_tp_as_sequence = { + (lenfunc)_wrap_gtk_border_length, + 0, + 0, + (ssizeargfunc)_wrap_gtk_border_getitem, + 0, + (ssizeobjargproc)_wrap_gtk_border_setitem, + 0, +}; +%% +override-attr GtkBorder.left +static int +_wrap_gtk_border__set_left(PyGBoxed *self, PyObject *value, void *closure) +{ + gint val; + + val = PyInt_AsLong(value); + if (PyErr_Occurred()) + return -1; + pyg_boxed_get(self, GtkBorder)->left = val; + return 0; +} +%% +override-attr GtkBorder.right +static int +_wrap_gtk_border__set_right(PyGBoxed *self, PyObject *value, void *closure) +{ + gint val; + + val = PyInt_AsLong(value); + if (PyErr_Occurred()) + return -1; + pyg_boxed_get(self, GtkBorder)->right = val; + return 0; +} +%% +override-attr GtkBorder.top +static int +_wrap_gtk_border__set_top(PyGBoxed *self, PyObject *value, void *closure) +{ + gint val; + + val = PyInt_AsLong(value); + if (PyErr_Occurred()) + return -1; + pyg_boxed_get(self, GtkBorder)->top = val; + return 0; +} +%% +override-attr GtkBorder.bottom +static int +_wrap_gtk_border__set_bottom(PyGBoxed *self, PyObject *value, void *closure) +{ + gint val; + + val = PyInt_AsLong(value); + if (PyErr_Occurred()) + return -1; + pyg_boxed_get(self, GtkBorder)->bottom = val; + return 0; +} + -- cgit v1.2.1