]> git.saurik.com Git - wxWidgets.git/blob - utils/wxPython/src/my_typemaps.i
Some updates and fixes
[wxWidgets.git] / utils / wxPython / src / my_typemaps.i
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: my_typemaps.i
3 // Purpose: Special typemaps specifically for wxPython.
4 //
5 // Author: Robin Dunn
6 //
7 // Created: 7/3/97
8 // RCS-ID: $Id$
9 // Copyright: (c) 1998 by Total Control Software
10 // Licence: wxWindows license
11 /////////////////////////////////////////////////////////////////////////////
12
13
14 //---------------------------------------------------------------------------
15 // Tell SWIG to wrap all the wrappers with Python's thread macros
16
17 %except(python) {
18 wxPy_BEGIN_ALLOW_THREADS;
19 $function
20 wxPy_END_ALLOW_THREADS;
21 }
22
23 //----------------------------------------------------------------------
24 // LCOUNT and choices go together. They allow a single Python list to be
25 // converted to an integer count and an array count items long.
26
27 %typemap(python,build) int LCOUNT {
28 if (_in_choices) {
29 $target = PyList_Size(_in_choices);
30 }
31 else {
32 $target = 0;
33 }
34 }
35
36
37
38 %typemap(python,in) byte* choices {
39 $target = byte_LIST_helper($source);
40 if ($target == NULL) {
41 return NULL;
42 }
43 }
44 %typemap(python,freearg) byte* choices {
45 delete [] $source;
46 }
47
48
49 %typemap(python,in) int* choices {
50 $target = int_LIST_helper($source);
51 if ($target == NULL) {
52 return NULL;
53 }
54 }
55 %typemap(python,freearg) int* choices {
56 delete [] $source;
57 }
58
59
60 %typemap(python,in) long* choices {
61 $target = long_LIST_helper($source);
62 if ($target == NULL) {
63 return NULL;
64 }
65 }
66 %typemap(python,freearg) long* choices {
67 delete [] $source;
68 }
69
70
71 %typemap(python,in) unsigned long* choices {
72 $target = (unsigned long*)long_LIST_helper($source);
73 if ($target == NULL) {
74 return NULL;
75 }
76 }
77 %typemap(python,freearg) unsigned long* choices {
78 delete [] $source;
79 }
80
81
82 #ifdef __WXMSW__
83 %typemap(python,in) wxDash* choices = unsigned long* choices;
84 %typemap(python,freearg) wxDash* choices = unsigned long* choices;
85 #else
86 %typemap(python,in) wxDash* choices = byte* choices;
87 %typemap(python,freearg) wxDash* choices = byte* choices;
88 #endif
89
90
91 %typemap(python,in) char** choices {
92 $target = string_LIST_helper($source);
93 if ($target == NULL) {
94 return NULL;
95 }
96 }
97 %typemap(python,freearg) char** choices {
98 delete [] $source;
99 }
100
101
102 %typemap(python,in) wxBitmap** choices {
103 $target = wxBitmap_LIST_helper($source);
104 if ($target == NULL) {
105 return NULL;
106 }
107 }
108 %typemap(python,freearg) wxBitmap** choices {
109 delete [] $source;
110 }
111
112 %typemap(python,in) wxString* choices {
113 $target = wxString_LIST_helper($source);
114 if ($target == NULL) {
115 return NULL;
116 }
117 }
118 %typemap(python,freearg) wxString* choices {
119 delete [] $source;
120 }
121
122 %typemap(python,in) wxAcceleratorEntry* choices {
123 $target = wxAcceleratorEntry_LIST_helper($source);
124 if ($target == NULL) {
125 return NULL;
126 }
127 }
128 %typemap(python,freearg) wxAcceleratorEntry* choices {
129 delete [] $source;
130 }
131
132
133
134
135
136 %typemap(python,build) int PCOUNT {
137 if (_in_points) {
138 $target = PyList_Size(_in_points);
139 }
140 else {
141 $target = 0;
142 }
143 }
144
145 %typemap(python,in) wxPoint* points {
146 $target = wxPoint_LIST_helper($source);
147 if ($target == NULL) {
148 return NULL;
149 }
150 }
151 %typemap(python,freearg) wxPoint* points {
152 delete [] $source;
153 }
154
155
156
157 //---------------------------------------------------------------------------
158
159 %{
160 static char* wxStringErrorMsg = "string type is required for parameter";
161 %}
162
163 %typemap(python, in) wxString& {
164 if (!PyString_Check($source)) {
165 PyErr_SetString(PyExc_TypeError, wxStringErrorMsg);
166 return NULL;
167 }
168 $target = new wxString(PyString_AsString($source), PyString_Size($source));
169 }
170 %typemap(python, freearg) wxString& {
171 if ($target)
172 delete $source;
173 }
174
175
176
177 %typemap(python, out) wxString {
178 $target = PyString_FromStringAndSize($source->c_str(), $source->Len());
179 }
180 %typemap(python, ret) wxString {
181 delete $source;
182 }
183
184
185 %typemap(python, out) wxString* {
186 $target = PyString_FromStringAndSize($source->c_str(), $source->Len());
187 }
188
189
190
191
192
193 //---------------------------------------------------------------------------
194 // Typemaps to convert Python sequence objects (2-tuples, etc.) to
195 // wxSize, wxPoint, wxRealPoint, and wxRect.
196
197 %typemap(python,in) wxSize& (wxSize temp) {
198 $target = &temp;
199 if (! wxSize_helper($source, &$target))
200 return NULL;
201 }
202
203 %typemap(python,in) wxPoint& (wxPoint temp) {
204 $target = &temp;
205 if (! wxPoint_helper($source, &$target))
206 return NULL;
207 }
208
209 %typemap(python,in) wxRealPoint& (wxRealPoint temp) {
210 $target = &temp;
211 if (! wxRealPoint_helper($source, &$target))
212 return NULL;
213 }
214
215 %typemap(python,in) wxRect& (wxRect temp) {
216 $target = &temp;
217 if (! wxRect_helper($source, &$target))
218 return NULL;
219 }
220
221
222 //---------------------------------------------------------------------------
223 // Map T_OUTPUTs for floats to return ints.
224
225
226 %typemap(python,ignore) float *T_OUTPUT_TOINT(float temp),
227 double *T_OUTPUT_TOINT(double temp)
228 {
229 $target = &temp;
230 }
231
232
233 %typemap(python,argout) float *T_OUTPUT_TOINT,
234 double *T_OUTPUT_TOINT
235 {
236 PyObject *o;
237 o = PyInt_FromLong((long) (*$source));
238 $target = t_output_helper($target, o);
239 }
240
241 //---------------------------------------------------------------------------
242 //---------------------------------------------------------------------------
243