]> Dogcows Code - chaz/openbox/blob - wrap/otk_property.i
focus new windows
[chaz/openbox] / wrap / otk_property.i
1 // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
2
3 %module otk_property
4
5 %{
6 #include "config.h"
7 #include "property.hh"
8 %}
9
10 %include "otk_ustring.i"
11
12 %typemap(python,in) const otk::Property::StringVect & (otk::Property::StringVect temp) {
13 if (PyList_Check($input)) {
14 int s = PyList_Size($input);
15 temp = otk::Property::StringVect(s);
16 for (int i = 0; i < s; ++i) {
17 PyObject *o = PyList_GetItem($input, i);
18 if (PyString_Check(o)) {
19 temp[i] = PyString_AsString(o);
20 } else {
21 SWIG_exception(SWIG_TypeError, "list of strings expected");
22 }
23 }
24 $1 = &temp;
25 } else {
26 SWIG_exception(SWIG_TypeError, "list expected");
27 }
28 }
29
30 %typemap(python,in) unsigned long value[] (unsigned long *temp) {
31 if (PyList_Check($input)) {
32 int s = PyList_Size($input);
33 temp = new unsigned long[s];
34 for (int i = 0; i < s; ++i) {
35 PyObject *o = PyList_GetItem($input, i);
36 if (PyInt_Check(o)) {
37 temp[i] = PyInt_AsLong(o);
38 } else if (PyLong_Check(o)) {
39 temp[i] = PyLong_AsLong(o);
40 } else {
41 SWIG_exception(SWIG_TypeError, "list of numbers expected");
42 }
43 }
44 $1 = temp;
45 } else {
46 SWIG_exception(SWIG_TypeError, "list expected");
47 }
48 }
49
50 %typemap(python,freearg) unsigned long value[] {
51 delete [] $1;
52 }
53
54 %typemap(python,in,numinputs=0) otk::ustring *value (otk::ustring temp) {
55 $1 = &temp;
56 }
57
58 %typemap(python,argout) otk::ustring *value {
59 PyObject *tuple;
60 int s;
61 if (PyTuple_Check($result)) {
62 s = PyTuple_Size($result);
63 _PyTuple_Resize(&$result, s + 1);
64 tuple = $result;
65 } else {
66 tuple = PyTuple_New(2);
67 PyTuple_SET_ITEM(tuple, 0, $result);
68 Py_INCREF($result);
69 s = 1;
70 }
71
72 PyTuple_SET_ITEM(tuple, s, PyString_FromString($1->c_str()));
73 $result = tuple;
74 }
75
76 %typemap(python,in,numinputs=0) unsigned long *value (unsigned long temp) {
77 $1 = &temp;
78 }
79
80 %typemap(python,argout) unsigned long *value {
81 PyObject *s = PyLong_FromLong(*$1);
82 $result = s;
83 }
84
85 %typemap(python,in,numinputs=0) unsigned long *nelements (unsigned long temp) {
86 $1 = &temp;
87 }
88
89 %typemap(python,in) unsigned long *nelements (unsigned long temp) {
90 temp = (unsigned)PyLong_AsLong($input);
91 $1 = &temp;
92 }
93
94 %typemap(python,in,numinputs=0) unsigned long **value (unsigned long *temp) {
95 $1 = &temp;
96 }
97
98 %typemap(python,argout) (unsigned long *nelements, unsigned long **value) {
99 PyObject *tuple;
100 int s;
101 if (PyTuple_Check($result)) {
102 s = PyTuple_Size($result);
103 _PyTuple_Resize(&$result, s + 2);
104 tuple = $result;
105 } else {
106 tuple = PyTuple_New(3);
107 PyTuple_SET_ITEM(tuple, 0, $result);
108 Py_INCREF($result);
109 s = 1;
110 }
111
112 int sz = *$1;
113
114 PyTuple_SET_ITEM(tuple, s++, PyLong_FromLong(sz));
115
116 PyObject *r = PyList_New(sz);
117 for (int i = 0; i < sz; ++i) {
118 PyList_SET_ITEM(r, i, PyLong_FromLong((*$2)[i]));
119 }
120 PyTuple_SET_ITEM(tuple, s, r);
121 $result = tuple;
122 }
123
124 %typemap(python,in,numinputs=0) StringVect *strings (StringVect temp) {
125 $1 = &temp;
126 }
127
128 %typemap(python,argout) (unsigned long *nelements, StringVect *strings) {
129 PyObject *tuple;
130 int s;
131 if (PyTuple_Check($result)) {
132 s = PyTuple_Size($result);
133 _PyTuple_Resize(&$result, s + 2);
134 tuple = $result;
135 } else {
136 tuple = PyTuple_New(3);
137 PyTuple_SET_ITEM(tuple, 0, $result);
138 Py_INCREF($result);
139 s = 1;
140 }
141
142 int sz = *$1;
143
144 PyTuple_SET_ITEM(tuple, s++, PyLong_FromLong(sz));
145
146 PyObject *r = PyList_New(sz);
147 for (int i = 0; i < sz; ++i) {
148 PyList_SET_ITEM(r, i, PyString_FromString((*$2)[i].c_str()));
149 }
150 PyTuple_SET_ITEM(tuple, s, r);
151 $result = tuple;
152 }
153
154 namespace otk {
155
156 %immutable otk::Property::atoms;
157
158 %ignore Property::NUM_STRING_TYPE;
159 %ignore Property::initialize();
160
161 %rename(getNum) Property::get(Window, Atom, Atom, unsigned long*);
162 %rename(getNums) Property::get(Window, Atom, Atom, unsigned long*,
163 unsigned long**);
164 %rename(getString) Property::get(Window, Atom, StringType, ustring*);
165 %rename(getStrings) Property::get(Window, Atom, StringType, unsigned long*,
166 StringVect);
167
168 }
169
170 %include "property.hh"
This page took 0.041968 seconds and 4 git commands to generate.