diff --git a/etg/_core.py b/etg/_core.py index ba924c7a..32ea3bc2 100644 --- a/etg/_core.py +++ b/etg/_core.py @@ -122,7 +122,7 @@ INCLUDES = [ 'defs', 'dirdlg', 'config', 'searchctrl', - #'variant', + 'variant', #'radiobox', # need to resolve abiguous GetDefaultBorder issue with mult. inheritance 'radiobtn', 'scrolwin', diff --git a/etg/dataview.py b/etg/dataview.py index 5ca7b686..d89b3569 100644 --- a/etg/dataview.py +++ b/etg/dataview.py @@ -38,11 +38,6 @@ def run(): # Tweak the parsed meta objects in the module object as needed for # customizing the generated code and docstrings. - module.insertItem(0, etgtools.WigCode("""\ - // forward declarations - class wxVariant; - """)) - c = module.find('wxDataViewModel') c.abstract = True #c.find('GetValue').ignore() diff --git a/etg/variant.py b/etg/variant.py deleted file mode 100644 index d80082ee..00000000 --- a/etg/variant.py +++ /dev/null @@ -1,75 +0,0 @@ -#--------------------------------------------------------------------------- -# Name: etg/variant.py -# Author: Kevin Ollivier -# -# Created: 15-Sept-2010 -# Copyright: (c) 2011 by Kevin Ollivier -# License: wxWindows License -#--------------------------------------------------------------------------- - -import etgtools -import etgtools.tweaker_tools as tools - -PACKAGE = "wx" -MODULE = "_core" -NAME = "variant" # Base name of the file to generate to for this script -DOCSTRING = "" - -# The classes and/or the basename of the Doxygen XML files to be processed by -# this script. -ITEMS = [ 'wxVariant', 'wxVariantData', ] - -#--------------------------------------------------------------------------- - -def run(): - # Parse the XML file(s) building a collection of Extractor objects - module = etgtools.ModuleDef(PACKAGE, MODULE, NAME, DOCSTRING) - etgtools.parseDoxyXML(module, ITEMS) - - #----------------------------------------------------------------- - # Tweak the parsed meta objects in the module object as needed for - # customizing the generated code and docstrings. - - - c = module.find('wxVariant') - - # FIXME: No matter what I do here, I always get 'same signature' errors - # for the various constructors. I've tried removing the ones that seem - # similar, and renaming parameters in the wx interface file, but neither - # approach changes things. Do we just need to use a mapped type for all conversions? - c.find('wxVariant').overloads = [] - #c.find('wxVariant').findOverload('wxAny').ignore() - #c.find('wxVariant').findOverload('wxChar *').ignore() - #c.find('wxVariant').findOverload('wxChar').ignore() - #c.find('wxVariant').findOverload('wxLongLong').ignore() - #c.find('wxVariant').findOverload('wxULongLong').ignore() - #c.find('wxVariant').findOverload('void *').ignore() - - c.find('GetAny').ignore() - - # SIP doesn't like the syntax on these methods. I don't know if it's - # something wrong about the SIP output, or if SIP doesn't support these. - c.find('operator double').ignore() - c.find('operator long').ignore() - c.find('operator wxLongLong').ignore() - c.find('operator wxULongLong').ignore() - - c.find('operator void *').ignore() - c.find('operator wxChar').ignore() - c.find('operator wxDateTime').ignore() - c.find('operator wxString').ignore() - - assert isinstance(c, etgtools.ClassDef) - - - - - #----------------------------------------------------------------- - tools.doCommonTweaks(module) - tools.runGenerators(module) - - -#--------------------------------------------------------------------------- -if __name__ == '__main__': - run() - diff --git a/src/variant.sip b/src/variant.sip new file mode 100644 index 00000000..2653fdca --- /dev/null +++ b/src/variant.sip @@ -0,0 +1,87 @@ +//-------------------------------------------------------------------------- +// Name: variant.sip +// Purpose: +// +// Author: Kevin Ollivier +// +// Created: 20-Sept-2011 +// Copyright: (c) 2011 by Kevin Ollivier +// 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 +{ + %ConvertToTypeCode + // Code to test a PyObject for compatibility + if (!sipIsErr) { + if (PyString_Check(sipPy) || PyUnicode_Check(sipPy)) + return TRUE; + else if (PyInt_Check(sipPy) || PyLong_Check(sipPy)) + return TRUE; + else if (PyBool_Check(sipPy)) + return TRUE; + else if (PyFloat_Check(sipPy)) + return TRUE; + + return FALSE; + } + + // Code to create a new wxPyUserData from the PyObject + wxVariant* data = new wxVariant(); + if (PyString_Check(sipPy) || PyUnicode_Check(sipPy)) { + // TODO: Can we just reuse the code in string.sip somehow? + + // TODO: check state or iserr? + int iserr = 0; + wxString* strPtr = (wxString*)sipConvertToType(sipPy, sipType_wxString, NULL, SIP_NOT_NONE, NULL, &iserr); + *data = *strPtr; + } + else if (PyInt_Check(sipPy)) + *data = (long)PyInt_AS_LONG(sipPy); + else if (PyLong_Check(sipPy)) + *data = (long)PyLong_AsLong(sipPy); + else if (PyBool_Check(sipPy)) { + if (sipPy == Py_True) + *data = true; + else + *data = false; + } + else if (PyFloat_Check(sipPy)) + *data = PyFloat_AS_DOUBLE(sipPy); + *sipCppPtr = data; + return sipGetState(sipTransferObj); + %End + + + %ConvertFromTypeCode + // Code to convert a wxClientData back to the PyObject. + PyObject* obj; + + if (sipCpp == NULL) { + obj = Py_None; + } else { + if (sipCpp->GetType() == "string") + obj = PyUnicode_FromWideChar(sipCpp->GetString().wc_str(), sipCpp->GetString().length()); + else if (sipCpp->GetType() == "long") + obj = PyLong_FromLong(sipCpp->GetLong()); + else if (sipCpp->GetType() == "double") + obj = PyFloat_FromDouble(sipCpp->GetDouble()); + else if (sipCpp->GetType() == "bool") + obj = PyBool_FromLong((long)sipCpp->GetBool()); + } + return obj; + %End + +}; + +// Used just for unittesting the MappedType code, it can be removed later +%ModuleCode +wxVariant testVariantTypemap(const wxVariant& arr) +{ + wxVariant local = arr; // force a copy + return local; +} +%End +wxVariant testVariantTypemap(const wxVariant& arr);