summaryrefslogtreecommitdiff
path: root/gtk/gtkborder.override
blob: e24d37377784b240b869c30031e91c4413c5f3d6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
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;
}