From 6733e06ff2870fa1e8269cae6c1af55333a6256b Mon Sep 17 00:00:00 2001 From: Robin Dunn Date: Fri, 31 Dec 2010 19:26:22 +0000 Subject: [PATCH] We can now use PyObject* instead of SIP_PYOBJECT git-svn-id: https://svn.wxwidgets.org/svn/wx/wxPython/Phoenix/trunk@66509 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- etgtools/sip_generator.py | 10 +++++++--- etgtools/tweaker_tools.py | 17 ++++++++++++----- sip/gen/app.sip | 3 ++- sip/gen/colour.sip | 2 +- sip/gen/event.sip | 8 ++++---- sip/gen/gdicmn.sip | 8 ++++---- sip/gen/geometry.sip | 4 ++-- sip/gen/window.sip | 6 +++--- src/pyevent.sip | 25 +++++++++++++++---------- 9 files changed, 50 insertions(+), 33 deletions(-) diff --git a/etgtools/sip_generator.py b/etgtools/sip_generator.py index cb273f6d..caf09a9f 100644 --- a/etgtools/sip_generator.py +++ b/etgtools/sip_generator.py @@ -453,9 +453,13 @@ from %s import * pnames = ', '.join(pnames) if pnames: pnames = ', ' + pnames - # convert PyObject* to SIP_PYOBJECT in the return type and param types - typ = method.type.replace('PyObject*', 'SIP_PYOBJECT') - argsString = method.argsString.replace('PyObject*', 'SIP_PYOBJECT') + if False: + # convert PyObject* to SIP_PYOBJECT in the return type and param types + typ = method.type.replace('PyObject*', 'SIP_PYOBJECT') + argsString = method.argsString.replace('PyObject*', 'SIP_PYOBJECT') + else: + typ = method.type + argsString = method.argsString # spit it all out if method.isCtor: stream.write('%s%s%s%s;\n' % diff --git a/etgtools/tweaker_tools.py b/etgtools/tweaker_tools.py index 42643e20..8b6298bd 100644 --- a/etgtools/tweaker_tools.py +++ b/etgtools/tweaker_tools.py @@ -16,6 +16,7 @@ import extractors import sys, os + def removeWxPrefixes(node): """ Rename items with a 'wx' prefix to not have the prefix. If the back-end @@ -36,7 +37,12 @@ def removeWxPrefixes(node): item.pyName = item.name - +def removeWxPrefix(name): + if name.startswith('wx') and not name.startswith('wxEVT_'): + name = name[2:] + return name + + def ignoreAssignmentOperators(node): """ Set the ignored flag for all class methods that are assignment operators @@ -423,7 +429,8 @@ def convertFourDoublesTemplate(CLASS): def wxListWrapperTemplate(ListClass, ItemClass, RealItemClass=None): if RealItemClass is None: RealItemClass = ItemClass - + ListClass_noPrefix = removeWxPrefix(ListClass) + # *** TODO: This can probably be done in a way that is not SIP-specfic. Try # creating extractor objects from scratch and attach cppMethods to them. @@ -499,10 +506,10 @@ public: }}; %Extract(id=pycode) -def _{ListClass}___repr__(self): +def _{ListClass_noPrefix}___repr__(self): return "{ListClass}: " + repr(list(self)) -{ListClass}.__repr__ = _{ListClass}___repr__ -del _{ListClass}___repr__ +{ListClass_noPrefix}.__repr__ = _{ListClass_noPrefix}___repr__ +del _{ListClass_noPrefix}___repr__ %End '''.format(**locals())) diff --git a/sip/gen/app.sip b/sip/gen/app.sip index 62918e42..607a0428 100644 --- a/sip/gen/app.sip +++ b/sip/gen/app.sip @@ -17,7 +17,8 @@ }; class wxPyApp; - wxPyApp* wxGetApp(); + wxPyApp* wxGetApp(); + %End diff --git a/sip/gen/colour.sip b/sip/gen/colour.sip index a9069f64..96a3a4d7 100644 --- a/sip/gen/colour.sip +++ b/sip/gen/colour.sip @@ -188,7 +188,7 @@ public: return sipBuildResult(&_isErr, "(iii)", red, green, blue); } %End - SIP_PYOBJECT Get(bool includeAlpha=true); + PyObject* Get(bool includeAlpha=true); %MethodCode sipRes = _wxColour_Get(sipCpp, sipIsErr, includeAlpha); %End diff --git a/sip/gen/event.sip b/sip/gen/event.sip index 5998b14f..ecba3402 100644 --- a/sip/gen/event.sip +++ b/sip/gen/event.sip @@ -227,7 +227,7 @@ public: } } %End - void Connect(int id, int lastId, wxEventType eventType, SIP_PYOBJECT func); + void Connect(int id, int lastId, wxEventType eventType, PyObject* func); %MethodCode _wxEvtHandler_Connect(sipCpp, sipIsErr, id, lastId, eventType, func); %End @@ -273,7 +273,7 @@ public: } } %End - bool Disconnect(int id, int lastId=-1, wxEventType eventType=wxEVT_NULL, SIP_PYOBJECT func=NULL); + bool Disconnect(int id, int lastId=-1, wxEventType eventType=wxEVT_NULL, PyObject* func=NULL); %MethodCode sipRes = _wxEvtHandler_Disconnect(sipCpp, sipIsErr, id, lastId, eventType, func); %End @@ -425,7 +425,7 @@ public: } } %End - SIP_PYOBJECT GetClientData(); + PyObject* GetClientData(); %MethodCode sipRes = _wxCommandEvent_GetClientData(sipCpp, sipIsErr); %End @@ -437,7 +437,7 @@ public: self->SetClientObject(data); } %End - void SetClientData(SIP_PYOBJECT clientData); + void SetClientData(PyObject* clientData); %MethodCode _wxCommandEvent_SetClientData(sipCpp, sipIsErr, clientData); %End diff --git a/sip/gen/gdicmn.sip b/sip/gen/gdicmn.sip index 17b56a83..824115c2 100644 --- a/sip/gen/gdicmn.sip +++ b/sip/gen/gdicmn.sip @@ -67,7 +67,7 @@ public: return sipBuildResult(&_isErr, "(ii)", self->x, self->y); } %End - SIP_PYOBJECT Get(); + PyObject* Get(); %MethodCode sipRes = _wxPoint_Get(sipCpp, sipIsErr); %End @@ -293,7 +293,7 @@ public: return sipBuildResult(&_isErr, "(ii)", self->GetWidth(), self->GetHeight()); } %End - SIP_PYOBJECT Get(); + PyObject* Get(); %MethodCode sipRes = _wxSize_Get(sipCpp, sipIsErr); %End @@ -587,7 +587,7 @@ public: self->x, self->y, self->width, self->height); } %End - SIP_PYOBJECT Get(); + PyObject* Get(); %MethodCode sipRes = _wxRect_Get(sipCpp, sipIsErr); %End @@ -750,7 +750,7 @@ public: return sipBuildResult(&_isErr, "(dd)", self->x, self->y); } %End - SIP_PYOBJECT Get(); + PyObject* Get(); %MethodCode sipRes = _wxRealPoint_Get(sipCpp, sipIsErr); %End diff --git a/sip/gen/geometry.sip b/sip/gen/geometry.sip index cad01e24..8eec6f18 100644 --- a/sip/gen/geometry.sip +++ b/sip/gen/geometry.sip @@ -114,7 +114,7 @@ public: return sipBuildResult(&_isErr, "(dd)", self->m_x, self->m_y); } %End - SIP_PYOBJECT Get(); + PyObject* Get(); %MethodCode sipRes = _wxPoint2DDouble_Get(sipCpp, sipIsErr); %End @@ -445,7 +445,7 @@ public: self->m_x, self->m_y, self->m_width, self->m_height); } %End - SIP_PYOBJECT Get(); + PyObject* Get(); %MethodCode sipRes = _wxRect2DDouble_Get(sipCpp, sipIsErr); %End diff --git a/sip/gen/window.sip b/sip/gen/window.sip index 17e967e3..1bb60b00 100644 --- a/sip/gen/window.sip +++ b/sip/gen/window.sip @@ -1227,10 +1227,10 @@ public: }; %Extract(id=pycode) -def _wxWindowList___repr__(self): +def _WindowList___repr__(self): return "wxWindowList: " + repr(list(self)) -wxWindowList.__repr__ = _wxWindowList___repr__ -del _wxWindowList___repr__ +WindowList.__repr__ = _WindowList___repr__ +del _WindowList___repr__ %End diff --git a/src/pyevent.sip b/src/pyevent.sip index 5e381498..7db84f07 100644 --- a/src/pyevent.sip +++ b/src/pyevent.sip @@ -20,8 +20,11 @@ // transport those attributes over to the clone when wx needs to make a copy // of the event instance. - // NOTE: This class is intentionally not exposed to SIP (see wxPyEvent - // and wxPyCommandEvent) + // NOTE: This class is intentionally not exposed to SIP as there is no + // need for it in Python code. Intead we just tell SIP that the __*attr__ + // methods are in the event classes. (See wxPyEvent and wxPyCommandEvent + // below.) + class wxPyEvtDict { public: @@ -43,7 +46,7 @@ wxPyEndBlockThreads(blocked); } - PyObject* _getDict() + PyObject* _getAttrDict() { Py_INCREF(m_dict); return m_dict; @@ -119,21 +122,23 @@ implement the Clone method in your derived classes. public: wxPyEvent(int id=0, wxEventType eventType = wxEVT_NULL ); virtual wxEvent* Clone() const /Factory/; + PyObject* _getAttrDict(); - SIP_PYOBJECT __getattr__(SIP_PYOBJECT name); + PyObject* __getattr__(PyObject* name); %MethodCode sipRes = sipCpp->__getattr__(name); %End - void __setattr__(SIP_PYOBJECT name, SIP_PYOBJECT value); + void __setattr__(PyObject* name, PyObject* value); %MethodCode sipCpp->__setattr__(name, value); %End - void __delattr__(SIP_PYOBJECT name); + void __delattr__(PyObject* name); %MethodCode sipCpp->__delattr__(name); %End + }; @@ -168,19 +173,19 @@ implement the Clone method in your derived classes. public: wxPyCommandEvent(wxEventType eventType = wxEVT_NULL, int id=0); virtual wxEvent* Clone() const /Factory/; - SIP_PYOBJECT _getDict(); + PyObject* _getAttrDict(); - SIP_PYOBJECT __getattr__(SIP_PYOBJECT name); + PyObject* __getattr__(PyObject* name); %MethodCode sipRes = sipCpp->__getattr__(name); %End - void __setattr__(SIP_PYOBJECT name, SIP_PYOBJECT value); + void __setattr__(PyObject* name, PyObject* value); %MethodCode sipCpp->__setattr__(name, value); %End - void __delattr__(SIP_PYOBJECT name); + void __delattr__(PyObject* name); %MethodCode sipCpp->__delattr__(name); %End