1//-------------------------------------------------------------------------- 2// Name: dvcvariant.sip 3// Purpose: MappedType for wxDVCVariant 4// 5// Author: Robin Dunn 6// 7// Created: 9-Nov-2012 8// Copyright: (c) 2012-2018 by Total Control Software 9// Licence: wxWindows license 10//-------------------------------------------------------------------------- 11 12%ModuleHeaderCode 13// A wxDVCVariant is really the same thing as a wxVariant. We just create 14// this new type so a different %MappedType can be created for it that also 15// knows how to put DVC types in and out of a variant. 16typedef wxVariant wxDVCVariant; 17 18wxVariant wxDVCVariant_in_helper(PyObject* source); 19PyObject* wxDVCVariant_out_helper(const wxVariant& value); 20 21#include <wx/vector.h> 22typedef wxVector<wxVariant> wxVariantVector; 23%End 24 25 26%ModuleCode 27wxVariant wxDVCVariant_in_helper(PyObject* source) 28{ 29 wxVariant ret; 30 31 if (wxPyWrappedPtr_TypeCheck(source, wxT("wxDataViewIconText"))) { 32 wxDataViewIconText* ptr; 33 wxPyConvertWrappedPtr(source, (void**)&ptr, wxT("wxDataViewIconText")); 34 ret << *ptr; 35 } 36 else 37 ret = wxVariant_in_helper(source); 38 return ret; 39} 40 41 42PyObject* wxDVCVariant_out_helper(const wxVariant& value) 43{ 44 PyObject* ret; 45 46 if ( value.IsType("wxDataViewIconText") ) 47 { 48 wxDataViewIconText val; 49 val << value; 50 ret = wxPyConstructObject(new wxDataViewIconText(val), wxT("wxDataViewIconText"), 0); 51 } 52 else 53 ret = wxVariant_out_helper(value); 54 return ret; 55} 56%End 57 58 59 60%MappedType wxDVCVariant 61{ 62 %ConvertToTypeCode 63 // Code to test a PyObject for compatibility. 64 if (!sipIsErr) { 65 // Any type should work since we'll just use the PyObject directly 66 // if the type is not one that is explicitly supported. 67 return TRUE; 68 } 69 70 // Code to create a new wxVariant from the PyObject 71 wxVariant* value = new wxVariant(wxDVCVariant_in_helper(sipPy)); 72 *sipCppPtr = value; 73 return sipGetState(sipTransferObj); 74 %End 75 76 77 %ConvertFromTypeCode 78 // Code to convert a wxVariant to a PyObject. 79 if (sipCpp == NULL) { 80 return Py_None; 81 } else { 82 return wxDVCVariant_out_helper(*sipCpp); 83 } 84 %End 85}; 86 87 88 89// Some DVC classes also make use of a wxVector<wxVariant> type. This code 90// will convert Python sequences to that type. 91%MappedType wxVariantVector 92{ 93 %ConvertToTypeCode 94 if (!sipIsErr) { 95 // We expect a sequence 96 return PySequence_Check(sipPy); 97 } 98 99 wxVariantVector* vector = new wxVariantVector; 100 Py_ssize_t size = PySequence_Length(sipPy); 101 Py_ssize_t idx; 102 for (idx=0; idx<size; idx+=1) { 103 PyObject* item = PySequence_GetItem(sipPy, idx); 104 vector->push_back( wxDVCVariant_in_helper(item) ); 105 Py_DECREF(item); 106 } 107 108 *sipCppPtr = vector; 109 return sipGetState(sipTransferObj); 110 %End 111 112 113 %ConvertFromTypeCode 114 // no C++ --> Python convert needed yet... 115 return NULL; 116 %End 117}; 118 119 120 121