From 811f1aaeb877bf3bf59a43516dbed4268b11ad3a Mon Sep 17 00:00:00 2001 From: Robin Dunn Date: Sat, 1 Oct 2011 00:33:19 +0000 Subject: [PATCH] dataobject --> dataobj git-svn-id: https://svn.wxwidgets.org/svn/wx/wxPython/Phoenix/trunk@69255 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- etg/accel.py | 79 ++++++++++++++++++++++++++++++++++++++++++++--- etg/dataobj.py | 17 ++++++++-- etg/dataobject.py | 47 ---------------------------- 3 files changed, 89 insertions(+), 54 deletions(-) delete mode 100644 etg/dataobject.py diff --git a/etg/accel.py b/etg/accel.py index 7a9edea5..c13f40b5 100644 --- a/etg/accel.py +++ b/etg/accel.py @@ -29,13 +29,82 @@ def run(): #----------------------------------------------------------------- # Tweak the parsed meta objects in the module object as needed for # customizing the generated code and docstrings. - + + c = module.find('wxAcceleratorEntry') + assert isinstance(c, etgtools.ClassDef) + tools.removeVirtuals(c) + c = module.find('wxAcceleratorTable') - # Mac doesn't have this? + assert isinstance(c, etgtools.ClassDef) + tools.removeVirtuals(c) + + # Replace the implementation of the AcceleratorTable ctor so it can + # accept a Python sequence of tuples or AcceleratorEntry objects like + # Classic does. Using the arraySize and array annotations does let us + # pass a list of entries, but they have to already be AccelertorEntry + # obejcts. We want to allow Items in the list to be either + # wx.AcceleratorEntry items or a 3-tuple containing the values to pass to + # the wx.AcceleratorEntry ctor. + + # See EXPERIMENTAL in object.py... + # First ignore the fact that this class derives from wxObject. This is + # so there will not be any inherited virtuals, so SIP will not generate a + # derived class. That makes the adding of a new ctor easier. + #c.bases = [] + + # Ignore the current constructor + c.find('wxAcceleratorTable').findOverload('entries').ignore() + + # and add the code for the new constructor + c.addCppCtor( + briefDoc="TODO", + argsString='(PyObject* entries)', + body="""\ + const char* errmsg = "Expected a sequence of 3-tuples or wx.AcceleratorEntry objects."; + if (!PySequence_Check(entries)) { + PyErr_SetString(PyExc_TypeError, errmsg); + return NULL; + } + int count = PySequence_Size(entries); + wxAcceleratorEntry* tmpEntries = new wxAcceleratorEntry[count]; + if (! tmpEntries) { + PyErr_SetString(PyExc_MemoryError, "Unable to allocate temporary array"); + return NULL; + } + int idx; + for (idx=0; idx( + sipConvertToType(obj, sipType_wxAcceleratorEntry, NULL, 0, 0, &err)); + tmpEntries[idx] = *entryPtr; + } + else if (PySequence_Check(obj) && PySequence_Size(obj) == 3) { + PyObject* o1 = PySequence_ITEM(obj, 0); + PyObject* o2 = PySequence_ITEM(obj, 1); + PyObject* o3 = PySequence_ITEM(obj, 2); + tmpEntries[idx].Set(PyInt_AsLong(o1), PyInt_AsLong(o2), PyInt_AsLong(o3)); + Py_DECREF(o1); + Py_DECREF(o2); + Py_DECREF(o3); + } + else { + PyErr_SetString(PyExc_TypeError, errmsg); + return NULL; + } + Py_DECREF(obj); + } + + wxAcceleratorTable* table = new wxAcceleratorTable(count, tmpEntries); + delete tmpEntries; + return table; + """) + + # Mac doesn't have this, and we don't real with resource files from + # wxPython anyway. c.find('wxAcceleratorTable').findOverload('resource').ignore() - c.find('wxAcceleratorTable.n').arraySize = True - c.find('wxAcceleratorTable.entries').array = True - c.find('wxAcceleratorTable.entries').type += '*' + #----------------------------------------------------------------- tools.doCommonTweaks(module) tools.addGetterSetterProps(module) diff --git a/etg/dataobj.py b/etg/dataobj.py index 95c3c16e..0175c2a6 100644 --- a/etg/dataobj.py +++ b/etg/dataobj.py @@ -18,8 +18,17 @@ DOCSTRING = "" # The classes and/or the basename of the Doxygen XML files to be processed by # this script. ITEMS = [ 'wxDataFormat', - # TODO: specify the rest of the classes in dataobj.h here + 'wxDataObject', + #'wxDataObjectSimple', + #'wxCustomDataObject', + #'wxDataObjectComposite', + #'wxBitmapDataObject', + #'wxTextDataObject', + #'wxURLDataObject', + #'wxFileDataObject', ] + +# TODO: apply some tweaks similar to how Classic implements these classes #--------------------------------------------------------------------------- @@ -34,8 +43,12 @@ def run(): c = module.find('wxDataFormat') assert isinstance(c, etgtools.ClassDef) - c.find('GetType').setCppCode("return static_cast(self->GetType());") + + + c = module.find('wxDataObject') + c.abstract = True + #----------------------------------------------------------------- tools.doCommonTweaks(module) diff --git a/etg/dataobject.py b/etg/dataobject.py deleted file mode 100644 index 28afbce3..00000000 --- a/etg/dataobject.py +++ /dev/null @@ -1,47 +0,0 @@ -#--------------------------------------------------------------------------- -# Name: etg/dataobject.py -# Author: Kevin Ollivier -# -# Created: 24-Sep-2011 -# Copyright: (c) 2011 by Kevin Ollivier -# License: wxWindows License -#--------------------------------------------------------------------------- - -import etgtools -import etgtools.tweaker_tools as tools - -PACKAGE = "wx" -MODULE = "_core" -NAME = "dataobject" # 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 = [ - "wxDataObject", -] - -#--------------------------------------------------------------------------- - -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('wxDataObject') - c.abstract = True - - #----------------------------------------------------------------- - tools.doCommonTweaks(module) - tools.addGetterSetterProps(module) - tools.runGenerators(module) - - -#--------------------------------------------------------------------------- -if __name__ == '__main__': - run() -