]>
Commit | Line | Data |
---|---|---|
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 | // wxDash is a signed char | |
49 | %typemap(python,in) wxDash* choices { | |
50 | $target = (wxDash*)byte_LIST_helper($source); | |
51 | if ($target == NULL) { | |
52 | return NULL; | |
53 | } | |
54 | } | |
55 | %typemap(python,freearg) wxDash* choices { | |
56 | delete [] $source; | |
57 | } | |
58 | ||
59 | ||
60 | %typemap(python,in) int* choices { | |
61 | $target = int_LIST_helper($source); | |
62 | if ($target == NULL) { | |
63 | return NULL; | |
64 | } | |
65 | } | |
66 | %typemap(python,freearg) int* choices { | |
67 | delete [] $source; | |
68 | } | |
69 | ||
70 | ||
71 | %typemap(python,in) long* choices { | |
72 | $target = long_LIST_helper($source); | |
73 | if ($target == NULL) { | |
74 | return NULL; | |
75 | } | |
76 | } | |
77 | %typemap(python,freearg) long* choices { | |
78 | delete [] $source; | |
79 | } | |
80 | ||
81 | ||
82 | %typemap(python,in) unsigned long* choices { | |
83 | $target = (unsigned long*)long_LIST_helper($source); | |
84 | if ($target == NULL) { | |
85 | return NULL; | |
86 | } | |
87 | } | |
88 | %typemap(python,freearg) unsigned long* choices { | |
89 | delete [] $source; | |
90 | } | |
91 | ||
92 | ||
93 | %typemap(python,in) char** choices { | |
94 | $target = string_LIST_helper($source); | |
95 | if ($target == NULL) { | |
96 | return NULL; | |
97 | } | |
98 | } | |
99 | %typemap(python,freearg) char** choices { | |
100 | delete [] $source; | |
101 | } | |
102 | ||
103 | ||
104 | %typemap(python,in) wxBitmap** choices { | |
105 | $target = wxBitmap_LIST_helper($source); | |
106 | if ($target == NULL) { | |
107 | return NULL; | |
108 | } | |
109 | } | |
110 | %typemap(python,freearg) wxBitmap** choices { | |
111 | delete [] $source; | |
112 | } | |
113 | ||
114 | %typemap(python,in) wxString* choices { | |
115 | $target = wxString_LIST_helper($source); | |
116 | if ($target == NULL) { | |
117 | return NULL; | |
118 | } | |
119 | } | |
120 | %typemap(python,freearg) wxString* choices { | |
121 | delete [] $source; | |
122 | } | |
123 | ||
124 | %typemap(python,in) wxAcceleratorEntry* choices { | |
125 | $target = wxAcceleratorEntry_LIST_helper($source); | |
126 | if ($target == NULL) { | |
127 | return NULL; | |
128 | } | |
129 | } | |
130 | %typemap(python,freearg) wxAcceleratorEntry* choices { | |
131 | delete [] $source; | |
132 | } | |
133 | ||
134 | ||
135 | ||
136 | ||
137 | ||
138 | %typemap(python,build) int PCOUNT { | |
139 | if (_in_points) { | |
140 | $target = PyList_Size(_in_points); | |
141 | } | |
142 | else { | |
143 | $target = 0; | |
144 | } | |
145 | } | |
146 | ||
147 | %typemap(python,in) wxPoint* points { | |
148 | $target = wxPoint_LIST_helper($source); | |
149 | if ($target == NULL) { | |
150 | return NULL; | |
151 | } | |
152 | } | |
153 | %typemap(python,freearg) wxPoint* points { | |
154 | delete [] $source; | |
155 | } | |
156 | ||
157 | ||
158 | ||
159 | //--------------------------------------------------------------------------- | |
160 | ||
161 | %{ | |
162 | static char* wxStringErrorMsg = "string type is required for parameter"; | |
163 | %} | |
164 | ||
165 | %typemap(python, in) wxString& { | |
166 | if (!PyString_Check($source)) { | |
167 | PyErr_SetString(PyExc_TypeError, wxStringErrorMsg); | |
168 | return NULL; | |
169 | } | |
170 | $target = new wxString(PyString_AsString($source), PyString_Size($source)); | |
171 | } | |
172 | %typemap(python, freearg) wxString& { | |
173 | if ($target) | |
174 | delete $source; | |
175 | } | |
176 | ||
177 | ||
178 | ||
179 | %typemap(python, out) wxString { | |
180 | $target = PyString_FromStringAndSize($source->c_str(), $source->Len()); | |
181 | } | |
182 | %typemap(python, ret) wxString { | |
183 | delete $source; | |
184 | } | |
185 | ||
186 | ||
187 | %typemap(python, out) wxString* { | |
188 | $target = PyString_FromStringAndSize($source->c_str(), $source->Len()); | |
189 | } | |
190 | ||
191 | ||
192 | ||
193 | ||
194 | ||
195 | //--------------------------------------------------------------------------- | |
196 | // Typemaps to convert Python sequence objects (2-tuples, etc.) to | |
197 | // wxSize, wxPoint, wxRealPoint, and wxRect. | |
198 | ||
199 | %typemap(python,in) wxSize& (wxSize temp) { | |
200 | $target = &temp; | |
201 | if (! wxSize_helper($source, &$target)) | |
202 | return NULL; | |
203 | } | |
204 | ||
205 | %typemap(python,in) wxPoint& (wxPoint temp) { | |
206 | $target = &temp; | |
207 | if (! wxPoint_helper($source, &$target)) | |
208 | return NULL; | |
209 | } | |
210 | ||
211 | %typemap(python,in) wxRealPoint& (wxRealPoint temp) { | |
212 | $target = &temp; | |
213 | if (! wxRealPoint_helper($source, &$target)) | |
214 | return NULL; | |
215 | } | |
216 | ||
217 | %typemap(python,in) wxRect& (wxRect temp) { | |
218 | $target = &temp; | |
219 | if (! wxRect_helper($source, &$target)) | |
220 | return NULL; | |
221 | } | |
222 | ||
223 | //--------------------------------------------------------------------------- | |
224 | // Typemap to convert strings to wxColour. Two string formats are accepted, | |
225 | // either a colour name, for a hex colour spec like "#RRGGBB" | |
226 | ||
227 | %typemap(python,in) wxColour& (wxColour temp) { | |
228 | $target = &temp; | |
229 | if (! wxColour_helper($source, &$target)) | |
230 | return NULL; | |
231 | } | |
232 | ||
233 | ||
234 | //--------------------------------------------------------------------------- | |
235 | // Map T_OUTPUTs for floats to return ints. | |
236 | ||
237 | ||
238 | %typemap(python,ignore) float *T_OUTPUT_TOINT(float temp), | |
239 | double *T_OUTPUT_TOINT(double temp) | |
240 | { | |
241 | $target = &temp; | |
242 | } | |
243 | ||
244 | ||
245 | %typemap(python,argout) float *T_OUTPUT_TOINT, | |
246 | double *T_OUTPUT_TOINT | |
247 | { | |
248 | PyObject *o; | |
249 | o = PyInt_FromLong((long) (*$source)); | |
250 | $target = t_output_helper($target, o); | |
251 | } | |
252 | ||
253 | //--------------------------------------------------------------------------- | |
254 | //--------------------------------------------------------------------------- | |
255 |