forked from wxWidgets/Phoenix
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdvcvariant.sip
120 lines (95 loc) · 3.07 KB
/
dvcvariant.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
106
107
108
109
110
111
112
113
114
115
116
117
//--------------------------------------------------------------------------
// Name: dvcvariant.sip
// Purpose: MappedType for wxDVCVariant
//
// Author: Robin Dunn
//
// Created: 9-Nov-2012
// Copyright: (c) 2012-2017 by Total Control Software
// Licence: wxWindows license
//--------------------------------------------------------------------------
%ModuleHeaderCode
// A wxDVCVariant is really the same thing as a wxVariant. We just create
// this new type so a different %MappedType can be created for it that also
// knows how to put DVC types in and out of a variant.
typedef wxVariant wxDVCVariant;
wxVariant wxDVCVariant_in_helper(PyObject* source);
PyObject* wxDVCVariant_out_helper(const wxVariant& value);
#include <wx/vector.h>
typedef wxVector<wxVariant> wxVariantVector;
%End
%ModuleCode
wxVariant wxDVCVariant_in_helper(PyObject* source)
{
wxVariant ret;
if (wxPyWrappedPtr_TypeCheck(source, wxT("wxDataViewIconText"))) {
wxDataViewIconText* ptr;
wxPyConvertWrappedPtr(source, (void**)&ptr, wxT("wxDataViewIconText"));
ret << *ptr;
}
else
ret = wxVariant_in_helper(source);
return ret;
}
PyObject* wxDVCVariant_out_helper(const wxVariant& value)
{
PyObject* ret;
if ( value.IsType("wxDataViewIconText") )
{
wxDataViewIconText val;
val << value;
ret = wxPyConstructObject(new wxDataViewIconText(val), wxT("wxDataViewIconText"), 0);
}
else
ret = wxVariant_out_helper(value);
return ret;
}
%End
%MappedType wxDVCVariant
{
%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(wxDVCVariant_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 wxDVCVariant_out_helper(*sipCpp);
}
%End
};
// Some DVC classes also make use of a wxVector<wxVariant> type. This code
// will convert Python sequences to that type.
%MappedType wxVariantVector
{
%ConvertToTypeCode
if (!sipIsErr) {
// We expect a sequence
return PySequence_Check(sipPy);
}
wxVariantVector* vector = new wxVariantVector;
Py_ssize_t size = PySequence_Length(sipPy);
Py_ssize_t idx;
for (idx=0; idx<size; idx+=1) {
PyObject* item = PySequence_GetItem(sipPy, idx);
vector->push_back( wxDVCVariant_in_helper(item) );
Py_DECREF(item);
}
*sipCppPtr = vector;
return sipGetState(sipTransferObj);
%End
%ConvertFromTypeCode
// no C++ --> Python convert needed yet...
return NULL;
%End
};