forked from wxWidgets/Phoenix
-
Notifications
You must be signed in to change notification settings - Fork 0
/
variant.sip
105 lines (89 loc) · 3.04 KB
/
variant.sip
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
//--------------------------------------------------------------------------
// Name: variant.sip
// Purpose: MappedType for wxVariant
//
// Author: Kevin Ollivier, Robin Dunn
//
// Created: 20-Sept-2011
// Copyright: (c) 2011 by Kevin Ollivier
// Copyright: (c) 2011-2018 by Total Control Software
// Licence: wxWindows license
//--------------------------------------------------------------------------
// We always convert wxVariant to / from the native Python types since its purpose
// is basically to allow a variable to be multiple types in C++
%MappedType wxVariant /AllowNone/
{
%ConvertToTypeCode
// Code to test a PyObject for compatibility.
if (!sipIsErr) {
// Any type should work since we'll just use the PyObject directly
// if the type is not one that is explicitly supported.
return TRUE;
}
// Code to create a new wxVariant from the PyObject
wxVariant* value = new wxVariant(wxVariant_in_helper(sipPy));
*sipCppPtr = value;
return sipGetState(sipTransferObj);
%End
%ConvertFromTypeCode
// Code to convert a wxVariant to a PyObject.
if (sipCpp == NULL) {
return Py_None;
} else {
return wxVariant_out_helper(*sipCpp);
}
%End
};
// Add a typemap for wxVariantList
%MappedType wxVariantList
{
%ConvertToTypeCode
// Code to test a PyObject for compatibility.
if (!sipIsErr) {
// Any type sequence type is okay.
int success = PySequence_Check(sipPy);
if (!success)
PyErr_SetString(PyExc_TypeError, "Sequence type expected.");
return success;
}
// Code to create a new wxVariantList from the PyObject sequence
wxVariantList* value = new wxVariantList();
Py_ssize_t len = PySequence_Length(sipPy);
Py_ssize_t idx = 0;
while (idx < len) {
PyObject* item = PySequence_GetItem(sipPy, idx);
value->Append(new wxVariant(wxVariant_in_helper(item)));
Py_DECREF(item);
}
*sipCppPtr = value;
return sipGetState(sipTransferObj);
%End
%ConvertFromTypeCode
// Code to convert a wxVariantList to a Python list.
if (sipCpp == NULL) {
return Py_None;
} else {
size_t idx = 0;
PyObject* value = PyList_New(0);
for (idx=0; idx < sipCpp->GetCount(); idx++) {
PyObject* item = wxVariant_out_helper(sipCpp->Item(idx));
PyList_Append(value, item);
}
return value;
}
%End
};
// Used just for unit testing the MappedType code, it can be removed later
%ModuleCode
wxVariant testVariantTypemap(const wxVariant& var)
{
wxVariant local = var; // force a copy
return local;
}
wxString testVariantTypeName(const wxVariant& var)
{
return var.GetType();
}
%End
wxVariant testVariantTypemap(const wxVariant& var);
wxString testVariantTypeName(const wxVariant& var);