~brian-sidebotham/wxwidgets-cmake/wxpython-2.9.4

« back to all changes in this revision

Viewing changes to wxPython/src/_core_api.i

  • Committer: Brian Sidebotham
  • Date: 2013-08-03 14:30:08 UTC
  • Revision ID: brian.sidebotham@gmail.com-20130803143008-c7806tkych1tp6fc
Initial import into Bazaar

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/////////////////////////////////////////////////////////////////////////////
 
2
// Name:        _core_api.i
 
3
// Purpose:
 
4
//
 
5
// Author:      Robin Dunn
 
6
//
 
7
// Created:     13-Sept-2003
 
8
// RCS-ID:      $Id: _core_api.i 60204 2009-04-16 19:23:12Z RD $
 
9
// Copyright:   (c) 2003 by Total Control Software
 
10
// Licence:     wxWindows license
 
11
/////////////////////////////////////////////////////////////////////////////
 
12
 
 
13
// Not a %module
 
14
 
 
15
 
 
16
//---------------------------------------------------------------------------
 
17
%{
 
18
#ifndef wxPyUSE_EXPORT
 
19
// Helper functions for dealing with SWIG objects and such.  These are
 
20
// located here so they know about the SWIG types and functions declared
 
21
// in the wrapper code.
 
22
 
 
23
#include <wx/hashmap.h>
 
24
WX_DECLARE_STRING_HASH_MAP( swig_type_info*, wxPyTypeInfoHashMap );
 
25
 
 
26
 
 
27
// Maintains a hashmap of className to swig_type_info pointers.  Given the
 
28
// name of a class either looks up the type info in the cache, or scans the
 
29
// SWIG tables for it.
 
30
extern PyObject* wxPyPtrTypeMap; 
 
31
static
 
32
swig_type_info* wxPyFindSwigType(const wxString& className) {
 
33
 
 
34
    static wxPyTypeInfoHashMap* typeInfoCache = NULL;
 
35
 
 
36
    if (typeInfoCache == NULL)
 
37
        typeInfoCache = new wxPyTypeInfoHashMap;
 
38
 
 
39
    wxString name(className);
 
40
    swig_type_info* swigType = (*typeInfoCache)[name];
 
41
 
 
42
    if (! swigType) {
 
43
        // it wasn't in the cache, so look it up from SWIG
 
44
        name.Append(wxT(" *"));
 
45
        swigType = SWIG_TypeQuery(name.mb_str());
 
46
        
 
47
        // if it still wasn't found, try looking for a mapped name
 
48
        if (!swigType) {
 
49
            PyObject* item;
 
50
            name = className;
 
51
            
 
52
            if ((item = PyDict_GetItemString(wxPyPtrTypeMap,
 
53
                               (char*)(const char*)name.mbc_str())) != NULL) {
 
54
                name = wxString(PyString_AsString(item), *wxConvCurrent);
 
55
                name.Append(wxT(" *"));
 
56
                swigType = SWIG_TypeQuery(name.mb_str());
 
57
            }
 
58
        }
 
59
        if (swigType) {
 
60
            // and add it to the map if found
 
61
            (*typeInfoCache)[className] = swigType;
 
62
        }
 
63
    }
 
64
    return swigType;    
 
65
}
 
66
 
 
67
 
 
68
// Check if a class name is a type known to SWIG
 
69
bool wxPyCheckSwigType(const wxString& className) {
 
70
 
 
71
    swig_type_info* swigType = wxPyFindSwigType(className);
 
72
    return swigType != NULL;
 
73
}
 
74
 
 
75
    
 
76
// Given a pointer to a C++ object and a class name, construct a Python proxy
 
77
// object for it.    
 
78
PyObject* wxPyConstructObject(void* ptr,
 
79
                              const wxString& className,
 
80
                              int setThisOwn) {
 
81
 
 
82
    swig_type_info* swigType = wxPyFindSwigType(className);
 
83
    wxCHECK_MSG(swigType != NULL, NULL, wxT("Unknown type in wxPyConstructObject"));
 
84
 
 
85
    return SWIG_Python_NewPointerObj(ptr, swigType, setThisOwn);
 
86
}
 
87
 
 
88
 
 
89
// Extract a pointer to the wrapped C++ object from a Python proxy object.
 
90
// Ensures that the proxy object is of the specified (or derived) type.  If
 
91
// not able to perform the conversion then a Python exception is set and the
 
92
// error should be handled properly in the caller.  Returns True on success.
 
93
bool wxPyConvertSwigPtr(PyObject* obj, void **ptr,
 
94
                        const wxString& className) {
 
95
 
 
96
    swig_type_info* swigType = wxPyFindSwigType(className);
 
97
    wxCHECK_MSG(swigType != NULL, false, wxT("Unknown type in wxPyConvertSwigPtr"));
 
98
 
 
99
    return SWIG_Python_ConvertPtr(obj, ptr, swigType, SWIG_POINTER_EXCEPTION) != -1;
 
100
}
 
101
 
 
102
%}
 
103
 
 
104
 
 
105
#if SWIG_VERSION < 0x010328
 
106
%{
 
107
// Make a SWIGified pointer object suitable for a .this attribute
 
108
PyObject* wxPyMakeSwigPtr(void* ptr, const wxString& className) {
 
109
    
 
110
    PyObject* robj = NULL;
 
111
 
 
112
    swig_type_info* swigType = wxPyFindSwigType(className);
 
113
    wxCHECK_MSG(swigType != NULL, NULL, wxT("Unknown type in wxPyMakeSwigPtr"));
 
114
 
 
115
#ifdef SWIG_COBJECT_TYPES
 
116
    robj = PySwigObject_FromVoidPtrAndDesc((void *) ptr, (char *)swigType->name);
 
117
#else
 
118
    {
 
119
        char result[1024];
 
120
        robj = SWIG_PackVoidPtr(result, ptr, swigType->name, sizeof(result)) ?
 
121
            PyString_FromString(result) : 0;
 
122
    }
 
123
#endif
 
124
    return robj;
 
125
}
 
126
%}
 
127
 
 
128
#else // SWIG_VERSION >= 1.3.28
 
129
%{
 
130
// Make a SWIGified pointer object suitable for a .this attribute
 
131
PyObject* wxPyMakeSwigPtr(void* ptr, const wxString& className) {
 
132
    
 
133
    PyObject* robj = NULL;
 
134
 
 
135
    swig_type_info* swigType = wxPyFindSwigType(className);
 
136
    wxCHECK_MSG(swigType != NULL, NULL, wxT("Unknown type in wxPyMakeSwigPtr"));
 
137
 
 
138
    robj = PySwigObject_New(ptr, swigType, 0);
 
139
    return robj;
 
140
}
 
141
%}
 
142
#endif
 
143
 
 
144
 
 
145
 
 
146
%{    
 
147
// Python's PyInstance_Check does not return True for instances of new-style
 
148
// classes.  This should get close enough for both new and old classes but I
 
149
// should re-evaluate the need for doing instance checks...
 
150
bool wxPyInstance_Check(PyObject* obj) {
 
151
    return PyObject_HasAttrString(obj, "__class__") != 0;
 
152
}
 
153
 
 
154
 
 
155
// This one checks if the object is an instance of a SWIG proxy class (it has
 
156
// a .this attribute, and the .this attribute is a PySwigObject.)
 
157
bool wxPySwigInstance_Check(PyObject* obj) {
 
158
    static PyObject* this_str = NULL;
 
159
    if (this_str == NULL)
 
160
        this_str = PyString_FromString("this");
 
161
    
 
162
    PyObject* this_attr = PyObject_GetAttr(obj, this_str);
 
163
    if (this_attr) {
 
164
        bool retval = (PySwigObject_Check(this_attr) != 0);
 
165
        Py_DECREF(this_attr);
 
166
        return retval;
 
167
    }
 
168
 
 
169
    PyErr_Clear();
 
170
    return false;
 
171
}
 
172
 
 
173
 
 
174
// Export a C API in a struct.  Other modules will be able to load this from
 
175
// the wx._core_ module and will then have safe access to these functions,
 
176
// even if they are located in another shared library.
 
177
static wxPyCoreAPI API = {
 
178
 
 
179
    wxPyCheckSwigType,
 
180
    wxPyConstructObject,
 
181
    wxPyConvertSwigPtr,
 
182
    wxPyMakeSwigPtr,
 
183
                                             
 
184
    wxPyBeginAllowThreads,
 
185
    wxPyEndAllowThreads,
 
186
    wxPyBeginBlockThreads,
 
187
    wxPyEndBlockThreads,
 
188
                                             
 
189
    NULL,  // A function was removed, reserve the slot so the others don't
 
190
           // change location
 
191
                                             
 
192
    wxString_in_helper,
 
193
    Py2wxString,
 
194
    wx2PyString,
 
195
                                             
 
196
    byte_LIST_helper,
 
197
    int_LIST_helper,
 
198
    long_LIST_helper,
 
199
    string_LIST_helper,
 
200
    wxPoint_LIST_helper,
 
201
    wxBitmap_LIST_helper,
 
202
    wxString_LIST_helper,
 
203
    wxAcceleratorEntry_LIST_helper,
 
204
                                             
 
205
    wxSize_helper,
 
206
    wxPoint_helper,
 
207
    wxRealPoint_helper,
 
208
    wxRect_helper,
 
209
    wxColour_helper,
 
210
    wxPoint2D_helper,
 
211
                                             
 
212
    wxPySimple_typecheck,
 
213
    wxColour_typecheck,
 
214
 
 
215
    wxPyCBH_setCallbackInfo,
 
216
    wxPyCBH_findCallback,
 
217
    wxPyCBH_callCallback,
 
218
    wxPyCBH_callCallbackObj,
 
219
    wxPyCBH_delete,
 
220
                                             
 
221
    wxPyMake_wxObject,
 
222
    wxPyMake_wxSizer,
 
223
    wxPyPtrTypeMap_Add,
 
224
    wxPy2int_seq_helper,
 
225
    wxPy4int_seq_helper,
 
226
    wxArrayString2PyList_helper,
 
227
    wxArrayInt2PyList_helper,
 
228
                                             
 
229
    wxPyClientData_dtor,
 
230
    wxPyUserData_dtor,
 
231
    wxPyOORClientData_dtor,
 
232
                                             
 
233
    wxPyCBInputStream_create,
 
234
    wxPyCBInputStream_copy,
 
235
    
 
236
    wxPyInstance_Check,
 
237
    wxPySwigInstance_Check,
 
238
 
 
239
    wxPyCheckForApp,
 
240
 
 
241
    wxArrayDouble2PyList_helper,
 
242
    wxPoint2D_LIST_helper,
 
243
    wxRect2D_helper,
 
244
    wxPosition_helper,
 
245
    
 
246
    wxPyCBOutputStream_create,
 
247
    wxPyCBOutputStream_copy,
 
248
 
 
249
    wxVariant_in_helper,
 
250
    wxVariant_out_helper,
 
251
 
 
252
    wxPyTextOrBitmap_helper,
 
253
};
 
254
 
 
255
#endif
 
256
%}
 
257
 
 
258
 
 
259
 
 
260
 
 
261
%init %{
 
262
#ifndef wxPyUSE_EXPORT
 
263
    // Make our API structure a CObject so other modules can import it
 
264
    // from this module.
 
265
    PyObject* cobj = PyCObject_FromVoidPtr(&API, NULL);
 
266
    PyDict_SetItemString(d,"_wxPyCoreAPI", cobj);
 
267
    Py_XDECREF(cobj);
 
268
#endif
 
269
%}
 
270
 
 
271
//---------------------------------------------------------------------------