]>
Commit | Line | Data |
---|---|---|
7bf85405 RD |
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 | ||
cf694132 RD |
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 | ||
7bf85405 | 23 | //---------------------------------------------------------------------- |
2f90df85 RD |
24 | // LCOUNT and LIST go together. They allow a single Python list to be |
25 | // converted to an integer count and an array count items long. | |
7bf85405 RD |
26 | |
27 | %typemap(python,build) int LCOUNT { | |
cf694132 RD |
28 | if (_in_LIST) { |
29 | $target = PyList_Size(_in_LIST); | |
30 | } | |
31 | else { | |
32 | $target = 0; | |
33 | } | |
7bf85405 RD |
34 | } |
35 | ||
36 | ||
37 | ||
b639c3c5 RD |
38 | %typemap(python,in) byte* LIST { |
39 | $target = byte_LIST_helper($source); | |
40 | if ($target == NULL) { | |
41 | return NULL; | |
42 | } | |
43 | } | |
44 | %typemap(python,freearg) byte* LIST { | |
45 | delete [] $source; | |
46 | } | |
47 | ||
48 | ||
7bf85405 RD |
49 | %typemap(python,in) int* LIST { |
50 | $target = int_LIST_helper($source); | |
51 | if ($target == NULL) { | |
52 | return NULL; | |
53 | } | |
54 | } | |
55 | %typemap(python,freearg) int* LIST { | |
56 | delete [] $source; | |
57 | } | |
58 | ||
59 | ||
60 | %typemap(python,in) long* LIST { | |
61 | $target = long_LIST_helper($source); | |
62 | if ($target == NULL) { | |
63 | return NULL; | |
64 | } | |
65 | } | |
66 | %typemap(python,freearg) long* LIST { | |
67 | delete [] $source; | |
68 | } | |
69 | ||
70 | ||
71 | %typemap(python,in) unsigned long* LIST { | |
72 | $target = (unsigned long*)long_LIST_helper($source); | |
73 | if ($target == NULL) { | |
74 | return NULL; | |
75 | } | |
76 | } | |
77 | %typemap(python,freearg) unsigned long* LIST { | |
78 | delete [] $source; | |
79 | } | |
80 | ||
81 | ||
82 | ||
83 | %typemap(python,in) wxDash* LIST = unsigned long* LIST; | |
84 | %typemap(python,freearg) wxDash* LIST = unsigned long* LIST; | |
85 | ||
86 | ||
87 | %typemap(python,in) char** LIST { | |
88 | $target = string_LIST_helper($source); | |
89 | if ($target == NULL) { | |
90 | return NULL; | |
91 | } | |
92 | } | |
93 | %typemap(python,freearg) char** LIST { | |
94 | delete [] $source; | |
95 | } | |
96 | ||
97 | ||
98 | ||
99 | %typemap(python,in) wxPoint* LIST { | |
100 | $target = wxPoint_LIST_helper($source); | |
101 | if ($target == NULL) { | |
102 | return NULL; | |
103 | } | |
104 | } | |
105 | %typemap(python,freearg) wxPoint* LIST { | |
106 | delete [] $source; | |
107 | } | |
108 | ||
109 | %typemap(python,in) wxBitmap** LIST { | |
110 | $target = wxBitmap_LIST_helper($source); | |
111 | if ($target == NULL) { | |
112 | return NULL; | |
113 | } | |
114 | } | |
115 | %typemap(python,freearg) wxBitmap** LIST { | |
116 | delete [] $source; | |
117 | } | |
118 | ||
119 | %typemap(python,in) wxString* LIST { | |
120 | $target = wxString_LIST_helper($source); | |
121 | if ($target == NULL) { | |
122 | return NULL; | |
123 | } | |
124 | } | |
125 | %typemap(python,freearg) wxString* LIST { | |
126 | delete [] $source; | |
127 | } | |
128 | ||
129 | %typemap(python,in) wxAcceleratorEntry* LIST { | |
130 | $target = wxAcceleratorEntry_LIST_helper($source); | |
131 | if ($target == NULL) { | |
132 | return NULL; | |
133 | } | |
134 | } | |
135 | %typemap(python,freearg) wxAcceleratorEntry* LIST { | |
136 | delete [] $source; | |
137 | } | |
138 | ||
139 | ||
140 | //--------------------------------------------------------------------------- | |
141 | ||
142 | %{ | |
143 | static char* wxStringErrorMsg = "string type is required for parameter"; | |
144 | %} | |
145 | ||
146 | %typemap(python, in) wxString& { | |
147 | if (!PyString_Check($source)) { | |
148 | PyErr_SetString(PyExc_TypeError, wxStringErrorMsg); | |
149 | return NULL; | |
150 | } | |
cf694132 | 151 | $target = new wxString(PyString_AsString($source), PyString_Size($source)); |
7bf85405 RD |
152 | } |
153 | %typemap(python, freearg) wxString& { | |
154 | if ($target) | |
155 | delete $source; | |
156 | } | |
157 | ||
158 | ||
159 | ||
160 | %typemap(python, out) wxString { | |
161 | $target = PyString_FromString(WXSTRINGCAST *($source)); | |
162 | } | |
163 | %typemap(python, ret) wxString { | |
164 | delete $source; | |
165 | } | |
166 | ||
167 | ||
168 | %typemap(python, out) wxString* { | |
169 | $target = PyString_FromString(WXSTRINGCAST (*$source)); | |
170 | } | |
171 | ||
172 | ||
2f90df85 RD |
173 | |
174 | ||
175 | ||
7bf85405 | 176 | //--------------------------------------------------------------------------- |
2f90df85 RD |
177 | // Typemaps to convert Python sequence objects (2-tuples, etc.) to |
178 | // wxSize, wxPoint, wxRealPoint, and wxRect. | |
179 | ||
180 | %typemap(python,in) wxSize& (wxSize temp) { | |
181 | $target = &temp; | |
182 | if (! wxSize_helper($source, &$target)) | |
183 | return NULL; | |
184 | } | |
185 | ||
186 | %typemap(python,in) wxPoint& (wxPoint temp) { | |
187 | $target = &temp; | |
188 | if (! wxPoint_helper($source, &$target)) | |
189 | return NULL; | |
190 | } | |
191 | ||
192 | %typemap(python,in) wxRealPoint& (wxRealPoint temp) { | |
193 | $target = &temp; | |
194 | if (! wxRealPoint_helper($source, &$target)) | |
195 | return NULL; | |
196 | } | |
7bf85405 | 197 | |
2f90df85 RD |
198 | %typemap(python,in) wxRect& (wxRect temp) { |
199 | $target = &temp; | |
200 | if (! wxRect_helper($source, &$target)) | |
201 | return NULL; | |
202 | } | |
7bf85405 RD |
203 | |
204 | ||
2f90df85 | 205 | //--------------------------------------------------------------------------- |
7bf85405 RD |
206 | // Map T_OUTPUTs for floats to return ints. |
207 | ||
208 | ||
209 | %typemap(python,ignore) float *T_OUTPUT_TOINT(float temp), | |
210 | double *T_OUTPUT_TOINT(double temp) | |
211 | { | |
212 | $target = &temp; | |
213 | } | |
214 | ||
215 | ||
216 | %typemap(python,argout) float *T_OUTPUT_TOINT, | |
217 | double *T_OUTPUT_TOINT | |
218 | { | |
219 | PyObject *o; | |
220 | o = PyInt_FromLong((long) (*$source)); | |
221 | $target = t_output_helper($target, o); | |
222 | } | |
223 | ||
224 | //--------------------------------------------------------------------------- | |
2f90df85 | 225 | //--------------------------------------------------------------------------- |
7bf85405 | 226 |