[pygtk] Wrap gtk.Border attributes and constructor



commit 807239aac5d1a8ae7ab1e3e2360d54ee572bbfdd
Author: Mariano Suárez-Alvarez <mariano suarezalvarez+bugzilla gmail com>
Date:   Fri May 8 21:39:53 2009 +0300

    Wrap gtk.Border attributes and constructor
    
    Closes bug #414779.
---
 docs/reference/pygtk-gtkborder.xml |  102 +++++++++++++++++++++++
 gtk/Makefile.am                    |    1 +
 gtk/gtk-base.defs                  |    6 ++
 gtk/gtk.override                   |    1 +
 gtk/gtkborder.override             |  159 ++++++++++++++++++++++++++++++++++++
 5 files changed, 269 insertions(+), 0 deletions(-)

diff --git a/docs/reference/pygtk-gtkborder.xml b/docs/reference/pygtk-gtkborder.xml
index 5929418..adf763a 100644
--- a/docs/reference/pygtk-gtkborder.xml
+++ b/docs/reference/pygtk-gtkborder.xml
@@ -22,7 +22,51 @@
 	<methodparam></methodparam>
       </methodsynopsis>
     </classsynopsis>
+  </refsect1>
 
+  <refsect1>
+    <title>Attributes</title>
+
+    <note>
+      <para>All attributes are available in PyGTK 2.16 and above.</para>
+    </note>
+
+    <blockquote role="properties">
+      <informaltable pgwide="1" frame="none">
+	<tgroup cols="3">
+	<?dbhtml cellpadding="5"?>
+	  <colspec column="1" colwidth="1in"/>
+	  <colspec column="2" colwidth="1in"/>
+	  <colspec column="3" colwidth="4in"/>
+	  <tbody>
+
+	    <row valign="top">
+	      <entry>"left"</entry>
+	      <entry>Read-Write</entry>
+	      <entry>The width of the left border margin.</entry>
+	    </row>
+
+	    <row valign="top">
+	      <entry>"right"</entry>
+	      <entry>Read-Write</entry>
+	      <entry>The width of the right border margin.</entry>
+	    </row>
+
+	    <row valign="top">
+	      <entry>"top"</entry>
+	      <entry>Read-Write</entry>
+	      <entry>The width of the bottom border margin.</entry>
+	    </row>
+
+	    <row valign="top">
+	      <entry>"bottom"</entry>
+	      <entry>Read-Write</entry>
+	      <entry>The width of the bottom border margin.</entry>
+	    </row>
+	  </tbody>
+	</tgroup>
+      </informaltable>
+    </blockquote>
   </refsect1>
 
   <refsect1>
@@ -45,6 +89,64 @@ linkend="method-gtkborder--copy"><methodname>copy</methodname>()</link> and
 <link
 linkend="method-gtkborder--free"><methodname>free</methodname>()</link>.</para>
 
+    <para>Starting with PyGTK 2.16 you can also
+      treat <link linkend="class-gtkborder"><classname>gtk.Border</classname></link>
+      objects as sequences of 4 integer values.  E.g. you can convert to a tuple or read
+      and assign individual values by index.</para>
+  </refsect1>
+
+  <refsect1 id="constructor-gtkborder">
+    <title>Constructor</title>
+
+    <programlisting><constructorsynopsis language="python">
+	<methodname>gtk.Border</methodname>
+	<methodparam><parameter
+		       role="keyword">left</parameter>
+	  <initializer>0</initializer></methodparam>
+	<methodparam><parameter
+		       role="keyword">right</parameter>
+	  <initializer>0</initializer></methodparam>
+	<methodparam><parameter
+		       role="keyword">top</parameter>
+	  <initializer>0</initializer></methodparam>
+	<methodparam><parameter
+		       role="keyword">bottom</parameter>
+	  <initializer>0</initializer></methodparam>
+      </constructorsynopsis></programlisting>
+    <variablelist>
+      <varlistentry>
+	<term><parameter role="keyword">left</parameter>&nbsp;:</term>
+	<listitem><simpara>the width of the left margin</simpara></listitem>
+      </varlistentry>
+      <varlistentry>
+	<term><parameter role="keyword">right</parameter>&nbsp;:</term>
+	<listitem><simpara>the width of the right margin</simpara></listitem>
+      </varlistentry>
+      <varlistentry>
+	<term><parameter role="keyword">top</parameter>&nbsp;:</term>
+	<listitem><simpara>the width of the top margin</simpara></listitem>
+      </varlistentry>
+      <varlistentry>
+	<term><parameter role="keyword">bottom</parameter>&nbsp;:</term>
+	<listitem><simpara>the width of the bottom margin</simpara></listitem>
+      </varlistentry>
+      <varlistentry>
+	<term><emphasis>Returns</emphasis>&nbsp;:</term>
+	<listitem><simpara>a new <link
+linkend="class-gdkrectangle"><classname>gtk.gdk.Rectangle</classname></link>
+object</simpara></listitem>
+      </varlistentry>
+    </variablelist>
+
+    <note>
+      <para>This constructor is available in PyGTK 2.16 and above.</para>
+    </note>
+
+    <para>Creates a
+      new <link linkend="class-gtkborder"><classname>gtk.Border</classname></link> with
+      the attributes specified
+      by <parameter>left</parameter>, <parameter>right</parameter>, <parameter>top</parameter>
+      and <parameter>bottom</parameter>. Any unspecified attributes default to 0.</para>
   </refsect1>
 
   <refsect1>
diff --git a/gtk/Makefile.am b/gtk/Makefile.am
index 0f92ae8..690a6aa 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 3cdfc8f..7daf5c9 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 a3a9b74..f5babed 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 0000000..e24d373
--- /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;
+}
+



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]