From 214c4fbea5875368cc21a082d20cb082cd38cb3c Mon Sep 17 00:00:00 2001 From: Robin Dunn <robin@alldunn.com> Date: Sun, 29 Jan 2006 02:09:45 +0000 Subject: [PATCH] Changes needed to be able to build with SWIG 1.3.24, 1.3.27 as well as the upcoming 1.3.28, using #if statements on SWIG_VERSION. Adjustments to ownership of SWIG objects, add some destructors and explicitly disown non-window objects when their ownership is transfered to a C++ object. Since all window objects are owned by their parent, or by themselves, always set their thisown attribute to False. Explicitly set thisown to False after any Destroy() methods are called, so SWIG doesn't try to destroy them again. Etc. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@37203 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- wxPython/b.win32 | 2 +- wxPython/config.py | 5 +- wxPython/contrib/gizmos/gizmos.i | 4 +- wxPython/src/_artprov.i | 6 +- wxPython/src/_clipbrd.i | 6 +- wxPython/src/_cmndlgs.i | 17 +++-- wxPython/src/_config.i | 4 +- wxPython/src/_core_api.i | 7 +- wxPython/src/_cshelp.i | 4 ++ wxPython/src/_dataobj.i | 52 +++++++------- wxPython/src/_defs.i | 40 ++++++++--- wxPython/src/_dnd.i | 5 +- wxPython/src/_evthandler.i | 1 + wxPython/src/_gbsizer.i | 16 ++++- wxPython/src/_listbox.i | 18 ++--- wxPython/src/_listctrl.i | 11 +-- wxPython/src/_log.i | 10 ++- wxPython/src/_menu.i | 4 +- wxPython/src/_misc.i | 58 ++++++++++++++- wxPython/src/_notebook.i | 4 +- wxPython/src/_obj.i | 1 + wxPython/src/_process.i | 4 ++ wxPython/src/_sizers.i | 19 ++++- wxPython/src/_stockobjs.i | 2 + wxPython/src/_taskbar.i | 2 + wxPython/src/_toplvl.i | 5 -- wxPython/src/_treectrl.i | 18 +++-- wxPython/src/_window.i | 23 ++++-- wxPython/src/grid.i | 13 ++-- wxPython/src/html.i | 9 ++- wxPython/src/my_typemaps.i | 92 ++++++++++++------------ wxPython/src/pyfragments.swg | 120 ++++++++++++++++++++++--------- 32 files changed, 396 insertions(+), 186 deletions(-) diff --git a/wxPython/b.win32 b/wxPython/b.win32 index aac2d54f47..77ff580765 100644 --- a/wxPython/b.win32 +++ b/wxPython/b.win32 @@ -6,7 +6,7 @@ # if this breaks something at your end, let me know and we can # figure out some solution for both of us. if [ "$SWIGDIR" = "" ]; then - SWIGDIR=$PROJECTS\\SWIG-cvs + SWIGDIR=$PROJECTS\\SWIG-1.3.27 fi FLAGS="USE_SWIG=1 SWIG=$SWIGDIR\\swig.exe" diff --git a/wxPython/config.py b/wxPython/config.py index af616106ed..1f6d7242ab 100644 --- a/wxPython/config.py +++ b/wxPython/config.py @@ -700,6 +700,7 @@ if os.name == 'nt': ('WXUSINGDLL', '1'), ('SWIG_TYPE_TABLE', WXPYTHON_TYPE_TABLE), + ('SWIG_PYTHON_OUTPUT_TUPLE', None), ('WXP_USE_THREAD', '1'), ] @@ -754,7 +755,7 @@ elif os.name == 'posix': WXDIR = '..' includes = ['include', 'src'] defines = [('SWIG_TYPE_TABLE', WXPYTHON_TYPE_TABLE), - ('HAVE_CONFIG_H', None), + ('SWIG_PYTHON_OUTPUT_TUPLE', None), ('WXP_USE_THREAD', '1'), ] if UNDEF_NDEBUG: @@ -873,7 +874,7 @@ i_files_includes = [ '-I' + opj(WXPY_SRC, 'src'), swig_cmd = SWIG swig_force = force swig_args = ['-c++', - '-Wall', + #'-Wall', '-python', '-new_repr', '-modern', diff --git a/wxPython/contrib/gizmos/gizmos.i b/wxPython/contrib/gizmos/gizmos.i index 2a3821483a..71dccd36c6 100644 --- a/wxPython/contrib/gizmos/gizmos.i +++ b/wxPython/contrib/gizmos/gizmos.i @@ -582,11 +582,11 @@ public: void SetStateImageList(wxImageList *imageList); void SetButtonsImageList(wxImageList *imageList); - %apply SWIGTYPE *DISOWN { wxImageList *imageList }; + %disownarg( wxImageList *imageList ); void AssignImageList(wxImageList *imageList); void AssignStateImageList(wxImageList *imageList); void AssignButtonsImageList(wxImageList *imageList); - %clear wxImageList *imageList; + %cleardisown( wxImageList *imageList ); // adds a column diff --git a/wxPython/src/_artprov.i b/wxPython/src/_artprov.i index add7ff93d5..4d02334a93 100644 --- a/wxPython/src/_artprov.i +++ b/wxPython/src/_artprov.i @@ -245,19 +245,22 @@ public: %pythonAppend wxPyArtProvider "self._setCallbackInfo(self, ArtProvider)" wxPyArtProvider(); + ~wxPyArtProvider(); void _setCallbackInfo(PyObject* self, PyObject* _class); + %disownarg( wxPyArtProvider *provider ); DocDeclStr( static void , PushProvider(wxPyArtProvider *provider), "Add new provider to the top of providers stack.", ""); + %cleardisown( wxPyArtProvider *provider ); DocDeclStr( static bool , PopProvider(), "Remove latest added provider and delete it.", ""); - + %pythonAppend RemoveProvider "args[1].thisown = 1"; DocDeclStr( static bool , RemoveProvider(wxPyArtProvider *provider), "Remove provider. The provider must have been added previously! The @@ -286,6 +289,7 @@ topmost provider if platform_dependent = false", ""); + %pythonAppend Destroy "args[0].thisown = 0" %extend { void Destroy() { delete self; }} }; diff --git a/wxPython/src/_clipbrd.i b/wxPython/src/_clipbrd.i index 53a040abed..d3ca994dbc 100644 --- a/wxPython/src/_clipbrd.i +++ b/wxPython/src/_clipbrd.i @@ -65,7 +65,7 @@ True on success.", ""); - %apply SWIGTYPE *DISOWN { wxDataObject *data }; + %disownarg( wxDataObject *data ); DocDeclStr( virtual bool , AddData( wxDataObject *data ), @@ -84,8 +84,8 @@ do not delete the data explicitly. :see: `wx.DataObject`", ""); - - %clear wxDataObject *data; + %cleardisown( wxDataObject *data ); + DocDeclStr( virtual bool , IsSupported( const wxDataFormat& format ), diff --git a/wxPython/src/_cmndlgs.i b/wxPython/src/_cmndlgs.i index 901f41f1a2..c0050c56cc 100644 --- a/wxPython/src/_cmndlgs.i +++ b/wxPython/src/_cmndlgs.i @@ -289,23 +289,22 @@ which will be used when the dialog is first displayed. After the dialog is shown, this is the index selected by the user.", ""); - DocStr(GetFilenames, - "Returns a list of filenames chosen in the dialog. This function + %extend { + DocStr(GetFilenames, + "Returns a list of filenames chosen in the dialog. This function should only be used with the dialogs which have wx.MULTIPLE style, use GetFilename for the others.", ""); - - DocStr(GetPaths, - "Fills the array paths with the full paths of the files chosen. This -function should only be used with the dialogs which have wx.MULTIPLE -style, use GetPath for the others.", ""); - - %extend { PyObject* GetFilenames() { wxArrayString arr; self->GetFilenames(arr); return wxArrayString2PyList_helper(arr); } + DocStr(GetPaths, + "Fills the array paths with the full paths of the files chosen. This +function should only be used with the dialogs which have wx.MULTIPLE +style, use GetPath for the others.", ""); + PyObject* GetPaths() { wxArrayString arr; self->GetPaths(arr); diff --git a/wxPython/src/_config.i b/wxPython/src/_config.i index 4ee0060a0f..434b42cdb1 100644 --- a/wxPython/src/_config.i +++ b/wxPython/src/_config.i @@ -85,12 +85,12 @@ public: }; - %apply SWIGTYPE *DISOWN { wxConfigBase *config }; + %disownarg( wxConfigBase *config ); DocDeclStr( static wxConfigBase *, Set(wxConfigBase *config), "Sets the global config object (the one returned by Get) and returns a reference to the previous global config object.", ""); - %clear wxConfigBase *config; + %cleardisown( wxConfigBase *config ); DocDeclStr( static wxConfigBase *, Get(bool createOnDemand = true), diff --git a/wxPython/src/_core_api.i b/wxPython/src/_core_api.i index 17f8b0efc5..153124b842 100644 --- a/wxPython/src/_core_api.i +++ b/wxPython/src/_core_api.i @@ -106,8 +106,9 @@ PyObject* wxPyMakeSwigPtr(void* ptr, const wxChar* className) { PyObject* robj = NULL; swig_type_info* swigType = wxPyFindSwigType(className); - wxCHECK_MSG(swigType != NULL, NULL, wxT("Unknown type in wxPyConvertSwigPtr")); + wxCHECK_MSG(swigType != NULL, NULL, wxT("Unknown type in wxPyMakeSwigPtr")); +#if SWIG_VERSION < 0x010328 #ifdef SWIG_COBJECT_TYPES robj = PySwigObject_FromVoidPtrAndDesc((void *) ptr, (char *)swigType->name); #else @@ -117,7 +118,9 @@ PyObject* wxPyMakeSwigPtr(void* ptr, const wxChar* className) { PyString_FromString(result) : 0; } #endif - +#else // SWIG_VERSION >= 1.3.28 + robj = PySwigObject_New(ptr, swigType, 0); +#endif return robj; } diff --git a/wxPython/src/_cshelp.i b/wxPython/src/_cshelp.i index ca04f0cae8..927fcea157 100644 --- a/wxPython/src/_cshelp.i +++ b/wxPython/src/_cshelp.i @@ -208,11 +208,14 @@ application using wx.HelpProvider.Set().", ""); class wxHelpProvider { public: + %disownarg( wxHelpProvider *helpProvider ); + %newobject Set; DocDeclStr( static wxHelpProvider *, Set(wxHelpProvider *helpProvider), "Sset the current, application-wide help provider. Returns the previous one. Unlike some other classes, the help provider is not created on demand. This must be explicitly done by the application.", ""); + %cleardisown( wxHelpProvider *helpProvider ); DocDeclStr( static wxHelpProvider *, Get(), @@ -250,6 +253,7 @@ table of help strings will fill up and when window pointers are reused, the wrong help string will be found.", ""); + %pythonAppend Destroy "args[0].thisown = 0" %extend { void Destroy() { delete self; } } }; diff --git a/wxPython/src/_dataobj.i b/wxPython/src/_dataobj.i index c2e0c7f693..fd6cd5c5b0 100644 --- a/wxPython/src/_dataobj.i +++ b/wxPython/src/_dataobj.i @@ -230,14 +230,11 @@ data.", ""); - // return all formats in the provided array (of size GetFormatCount()) - //virtual void GetAllFormats(wxDataFormat *formats, - // Direction dir = Get) const; - DocAStr(GetAllFormats, - "GetAllFormats(self, int dir=Get) -> [formats]", - "Returns a list of all the wx.DataFormats that this dataobject supports -in the given direction.", ""); %extend { + DocAStr(GetAllFormats, + "GetAllFormats(self, int dir=Get) -> [formats]", + "Returns a list of all the wx.DataFormats that this dataobject supports +in the given direction.", ""); PyObject* GetAllFormats(Direction dir = Get) { size_t count = self->GetFormatCount(dir); wxDataFormat* formats = new wxDataFormat[count]; @@ -262,12 +259,11 @@ in the given direction.", ""); // True if data copied successfully, False otherwise // virtual bool GetDataHere(const wxDataFormat& format, void *buf) const; - DocAStr(GetDataHere, - "GetDataHere(self, DataFormat format) -> String", - "Get the data bytes in the specified format, returns None on failure. -", " -:todo: This should use the python buffer interface isntead..."); %extend { + DocAStr(GetDataHere, + "GetDataHere(self, DataFormat format) -> String", + "Get the data bytes in the specified format, returns None on failure.", " +:todo: This should use the python buffer interface isntead..."); PyObject* GetDataHere(const wxDataFormat& format) { PyObject* rval = NULL; size_t size = self->GetDataSize(format); @@ -353,12 +349,12 @@ assumed that the format is supported in both directions.", ""); - DocAStr(GetDataHere, - "GetDataHere(self) -> String", - "Returns the data bytes from the data object as a string, returns None + %extend { + DocAStr(GetDataHere, + "GetDataHere(self) -> String", + "Returns the data bytes from the data object as a string, returns None on failure. Must be implemented in the derived class if the object supports rendering its data.", ""); - %extend { PyObject* GetDataHere() { PyObject* rval = NULL; size_t size = self->GetDataSize(); @@ -379,12 +375,12 @@ supports rendering its data.", ""); } - DocAStr(SetData, - "SetData(self, String data) -> bool", - "Copy the data value to the data object. Must be implemented in the + %extend { + DocAStr(SetData, + "SetData(self, String data) -> bool", + "Copy the data value to the data object. Must be implemented in the derived class if the object supports setting its data. ", ""); - %extend { bool SetData(PyObject* data) { bool rval; wxPyBlock_t blocked = wxPyBeginBlockThreads(); @@ -520,14 +516,14 @@ class wxDataObjectComposite : public wxDataObject { public: wxDataObjectComposite(); - %apply SWIGTYPE *DISOWN { wxDataObjectSimple *dataObject }; + %disownarg( wxDataObjectSimple *dataObject ); DocDeclStr( void , Add(wxDataObjectSimple *dataObject, bool preferred = false), "Adds the dataObject to the list of supported objects and it becomes the preferred object if preferred is True.", ""); - %clear wxDataObjectSimple *dataObject; + %cleardisown( wxDataObjectSimple *dataObject ); }; //--------------------------------------------------------------------------- @@ -757,10 +753,10 @@ public: wxCustomDataObject(); - DocAStr(SetData, - "SetData(self, String data) -> bool", - "Copy the data value to the data object.", ""); %extend { + DocAStr(SetData, + "SetData(self, String data) -> bool", + "Copy the data value to the data object.", ""); bool SetData(PyObject* data) { bool rval; wxPyBlock_t blocked = wxPyBeginBlockThreads(); @@ -783,10 +779,10 @@ public: "Get the size of the data.", ""); - DocAStr(GetData, - "GetData(self) -> String", - "Returns the data bytes from the data object as a string.", ""); %extend { + DocAStr(GetData, + "GetData(self) -> String", + "Returns the data bytes from the data object as a string.", ""); PyObject* GetData() { PyObject* obj; wxPyBlock_t blocked = wxPyBeginBlockThreads(); diff --git a/wxPython/src/_defs.i b/wxPython/src/_defs.i index 014339c36b..c07f2078b6 100644 --- a/wxPython/src/_defs.i +++ b/wxPython/src/_defs.i @@ -12,8 +12,8 @@ //--------------------------------------------------------------------------- -// Globally turn on the autodoc feature +// Globally turn on the autodoc feature %feature("autodoc", "1"); // 0 == no param types, 1 == show param types // Turn on kwargs by default @@ -22,24 +22,39 @@ // Don't generate separate wrappers for each default args combination %feature("compactdefaultargs"); +#if SWIG_VERSION < 0x010328 // Don't generate default ctors or dtors if the C++ doesn't have them %feature("nodefault"); - +#else // This is the SWIG 1.3.28 way to do the above... -// // Don't generate default ctors or dtors if the C++ doesn't have them -// %feature("nodefaultctor"); -// %feature("nodefaultdtor"); +%feature("nodefaultctor"); +%feature("nodefaultdtor"); +#endif + +// For now, just supress the warning about using Python keywords as parameter +// names. Will need to come back later and correct these rather than just +// hide them... +#pragma SWIG nowarn=314 //--------------------------------------------------------------------------- -// Tell SWIG to wrap all the wrappers with our thread protection by default +// Tell SWIG to wrap all the wrappers with our thread protection +%define %threadWrapperOn %exception { PyThreadState* __tstate = wxPyBeginAllowThreads(); $action wxPyEndAllowThreads(__tstate); if (PyErr_Occurred()) SWIG_fail; } +%enddef + +// This one will turn off the generation of the thread wrapper code +%define %threadWrapperOff +%exception +%enddef +// Turn it on by default +%threadWrapperOn // This one can be used to add a check for an existing wxApp before the real // work is done. An exception is raised if there isn't one. @@ -75,10 +90,19 @@ typedef unsigned long wxUIntPtr; #define %pythonAppend %feature("pythonappend") #define %pythonPrepend %feature("pythonprepend") -#define %kwargs %feature("kwargs") -#define %nokwargs %feature("kwargs", "0") #define %noautodoc %feature("noautodoc") +#if SWIG_VERSION >= 0x010327 +#define %kwargs %feature("kwargs", "1") +#define %nokwargs %feature("kwargs", "0") +#else +#define %kwargs %feature("kwargs") +#define %nokwargs %feature("nokwargs") +#endif + +#define %disownarg(typespec) %typemap(in) typespec = SWIGTYPE* DISOWN +#define %cleardisown(typespec) %typemap(in) typespec + #ifndef %pythoncode diff --git a/wxPython/src/_dnd.i b/wxPython/src/_dnd.i index 29a4d2cc19..39702a1980 100644 --- a/wxPython/src/_dnd.i +++ b/wxPython/src/_dnd.i @@ -137,7 +137,8 @@ class wxPyDropTarget // : public wxDropTarget public: %pythonAppend wxPyDropTarget "self._setCallbackInfo(self, DropTarget)" - %apply SWIGTYPE *DISOWN { wxDataObject *dataObject }; + + %disownarg( wxDataObject *dataObject ); wxPyDropTarget(wxDataObject *dataObject = NULL); void _setCallbackInfo(PyObject* self, PyObject* _class); @@ -148,7 +149,7 @@ public: wxDataObject *GetDataObject(); void SetDataObject(wxDataObject *dataObject); - %clear wxDataObject *dataObject; + %cleardisown( wxDataObject *dataObject ); wxDragResult base_OnEnter(wxCoord x, wxCoord y, wxDragResult def); wxDragResult base_OnDragOver(wxCoord x, wxCoord y, wxDragResult def); diff --git a/wxPython/src/_evthandler.i b/wxPython/src/_evthandler.i index d54c5aa1eb..5df2f19381 100644 --- a/wxPython/src/_evthandler.i +++ b/wxPython/src/_evthandler.i @@ -72,6 +72,7 @@ public: } } + %pythonAppend _setOORInfo "args[0].thisown = 0"; %extend { void _setOORInfo(PyObject* _self, bool incref=true) { if (_self && _self != Py_None) { diff --git a/wxPython/src/_gbsizer.i b/wxPython/src/_gbsizer.i index 80f6429fe2..8b79cc4c7d 100644 --- a/wxPython/src/_gbsizer.i +++ b/wxPython/src/_gbsizer.i @@ -73,7 +73,8 @@ class wxGBPosition { public: wxGBPosition(int row=0, int col=0); - + ~wxGBPosition(); + int GetRow() const; int GetCol() const; void SetRow(int row); @@ -143,6 +144,8 @@ public: colspan. The default is (1,1). (Meaning that the item occupies one cell in each direction.", ""); + ~wxGBSpan(); + int GetRowspan() const; int GetColspan() const; void SetRowspan(int rowspan); @@ -218,6 +221,9 @@ item can be used in a Sizer. You will probably never need to create a wx.GBSizerItem directly as they are created automatically when the sizer's Add method is called.", ""); + ~wxGBSizerItem(); + + %extend { DocStr(wxGBSizerItem( wxWindow *window, const wxGBPosition& pos,const wxGBSpan& span,int flag,int border,PyObject* userData=NULL ), "Construct a `wx.GBSizerItem` for a window.", ""); @@ -241,6 +247,7 @@ are created automatically when the sizer's Add method is called.", ""); DocStr(wxGBSizerItem( wxSizer *sizer,const wxGBPosition& pos,const wxGBSpan& span,int flag,int border,PyObject* userData=NULL ), "Construct a `wx.GBSizerItem` for a sizer", ""); + %disownarg( wxSizer *sizer ); %RenameCtor(GBSizerItemSizer, wxGBSizerItem( wxSizer *sizer, const wxGBPosition& pos, const wxGBSpan& span, @@ -256,6 +263,7 @@ are created automatically when the sizer's Add method is called.", ""); } return new wxGBSizerItem(sizer, pos, span, flag, border, data); } + %cleardisown( wxSizer *sizer ); DocStr(wxGBSizerItem( int width,int height,const wxGBPosition& pos,const wxGBSpan& span,int flag,int border,PyObject* userData=NULL), @@ -392,6 +400,8 @@ position, False if something was already there. wxPySizerItemInfo info = wxPySizerItemTypeHelper(item, true, false); if ( userData && (info.window || info.sizer || info.gotSize) ) data = new wxPyUserData(userData); + if ( info.sizer ) + PyObject_SetAttrString(item,"thisown",Py_False); wxPyEndBlockThreads(blocked); // Now call the real Add method if a valid item type was found @@ -405,7 +415,8 @@ position, False if something was already there. return NULL; } } - + + %disownarg( wxGBSizerItem *item ); DocDeclAStrName( wxGBSizerItem* , Add( wxGBSizerItem *item ), "Add(self, GBSizerItem item) -> wx.GBSizerItem", @@ -413,6 +424,7 @@ position, False if something was already there. the item was successfully placed at its given cell position, False if something was already there.", "", AddItem); + %cleardisown( wxGBSizerItem *item ); DocDeclStr( wxSize , GetCellSize(int row, int col) const, diff --git a/wxPython/src/_listbox.i b/wxPython/src/_listbox.i index c3c01ea3e7..565dea0bd1 100644 --- a/wxPython/src/_listbox.i +++ b/wxPython/src/_listbox.i @@ -79,15 +79,15 @@ public: // GetSelection which only works for listboxes with single selection) //virtual int GetSelections(wxArrayInt& aSelections) const; %extend { - PyObject* GetSelections() { - wxArrayInt lst; - self->GetSelections(lst); - PyObject *tup = PyTuple_New(lst.GetCount()); - for(size_t i=0; i<lst.GetCount(); i++) { - PyTuple_SetItem(tup, i, PyInt_FromLong(lst[i])); - } - return tup; - } + PyObject* GetSelections() { + wxArrayInt lst; + self->GetSelections(lst); + PyObject *tup = PyTuple_New(lst.GetCount()); + for(size_t i=0; i<lst.GetCount(); i++) { + PyTuple_SetItem(tup, i, PyInt_FromLong(lst[i])); + } + return tup; + } } // set the specified item at the first visible item or scroll to max diff --git a/wxPython/src/_listctrl.i b/wxPython/src/_listctrl.i index 836730ddac..22113546b4 100644 --- a/wxPython/src/_listctrl.i +++ b/wxPython/src/_listctrl.i @@ -153,7 +153,7 @@ public: wxListItemAttr(const wxColour& colText = wxNullColour, const wxColour& colBack = wxNullColour, const wxFont& font = wxNullFont); - + ~wxListItemAttr(); // setters void SetTextColour(const wxColour& colText); @@ -169,6 +169,9 @@ public: wxColour GetBackgroundColour(); wxFont GetFont(); + void AssignFrom(const wxListItemAttr& source); + + %pythonAppend Destroy "args[0].thisown = 0" %extend { void Destroy() { delete self; } } }; @@ -592,11 +595,9 @@ public: // Sets the image list void SetImageList(wxImageList *imageList, int which); - // is there a way to tell SWIG to disown this??? - - %apply SWIGTYPE *DISOWN { wxImageList *imageList }; + %disownarg( wxImageList *imageList ); void AssignImageList(wxImageList *imageList, int which); - %clear wxImageList *imageList; + %cleardisown( wxImageList *imageList ); // are we in report mode? bool InReportView() const; diff --git a/wxPython/src/_log.i b/wxPython/src/_log.i index 8084857b0a..4aa96d65bd 100644 --- a/wxPython/src/_log.i +++ b/wxPython/src/_log.i @@ -54,7 +54,7 @@ class wxLog { public: wxLog(); - + ~wxLog(); // these functions allow to completely disable all log messages // is logging disabled now? @@ -80,9 +80,12 @@ public: // create one if none exists static wxLog *GetActiveTarget(); + %disownarg( wxLog* pLogger ); + %newobject SetActiveTarget; // change log target, pLogger may be NULL static wxLog *SetActiveTarget(wxLog *pLogger); - + %cleardisown( wxLog* pLogger ); + // suspend the message flushing of the main target until the next call // to Resume() - this is mainly for internal use (to prevent wxYield() // from flashing the messages) @@ -149,6 +152,7 @@ public: } } + %pythonAppend Destroy "args[0].thisown = 0"; %extend { void Destroy() { delete self; } } }; @@ -222,7 +226,7 @@ public: unsigned long wxSysErrorCode(); const wxString wxSysErrorMsg(unsigned long nErrCode = 0); -%{// Make somce wrappers that double any % signs so they are 'escaped' +%{// Make some wrappers that double any % signs so they are 'escaped' void wxPyLogFatalError(const wxString& msg) { wxString m(msg); diff --git a/wxPython/src/_menu.i b/wxPython/src/_menu.i index 3ab2403291..b57f7bd6e7 100644 --- a/wxPython/src/_menu.i +++ b/wxPython/src/_menu.i @@ -133,8 +133,10 @@ public: bool Delete(int id); %Rename(DeleteItem, bool, Delete(wxMenuItem *item)); - // delete the item from menu and destroy it (if it's a submenu) + %pythonAppend Destroy "args[0].thisown = 0" %extend { void Destroy() { delete self; } } + + // delete the item from menu and destroy it (if it's a submenu) %Rename(DestroyId, bool, Destroy(int id)); %Rename(DestroyItem, bool, Destroy(wxMenuItem *item)); diff --git a/wxPython/src/_misc.i b/wxPython/src/_misc.i index 291fca6802..1b352d6ca2 100644 --- a/wxPython/src/_misc.i +++ b/wxPython/src/_misc.i @@ -24,8 +24,13 @@ MustHaveApp(wxToolTip); class wxToolTip : public wxObject { public: + %typemap(out) wxToolTip*; // turn off this typemap wxToolTip(const wxString &tip); + // Turn it back on again + %typemap(out) wxToolTip* { $result = wxPyMake_wxObject($1, $owner); } + ~wxToolTip(); + void SetTip(const wxString& tip); wxString GetTip(); // *** Not in the "public" interface void SetWindow(wxWindow *win); @@ -43,9 +48,10 @@ MustHaveApp(wxCaret); class wxCaret { public: wxCaret(wxWindow* window, const wxSize& size); -// ~wxCaret(); Window takes ownership + ~wxCaret(); %extend { + %pythonAppend Destroy "args[0].thisown = 0" DocStr(Destroy, "Deletes the C++ object this Python object is a proxy for.", ""); void Destroy() { @@ -308,5 +314,55 @@ bool wxDrawWindowOnDC(wxWindow* window, const wxDC& dc %} + +#if 0 +%{ + void t_output_tester1(int* a, int* b, int* c, int* d) + { + *a = 1234; + *b = 2345; + *c = 3456; + *d = 4567; + } + PyObject* t_output_tester2(int* a, int* b, int* c, int* d) + { + *a = 1234; + *b = 2345; + *c = 3456; + *d = 4567; + Py_INCREF(Py_None); + return Py_None; + } + PyObject* t_output_tester3(int* a, int* b, int* c, int* d) + { + *a = 1234; + *b = 2345; + *c = 3456; + *d = 4567; + PyObject* res = PyTuple_New(2); + PyTuple_SetItem(res, 0, PyInt_FromLong(1)); + PyTuple_SetItem(res, 1, PyInt_FromLong(2)); + return res; + } + PyObject* t_output_tester4() + { + PyObject* res = PyTuple_New(2); + PyTuple_SetItem(res, 0, PyInt_FromLong(132)); + PyTuple_SetItem(res, 1, PyInt_FromLong(244)); + return res; + } +%} + +%newobject t_output_tester2; +%newobject t_output_tester3; +%newobject t_output_tester4; + +void t_output_tester1(int* OUTPUT, int* OUTPUT, int* OUTPUT, int* OUTPUT); +PyObject* t_output_tester2(int* OUTPUT, int* OUTPUT, int* OUTPUT, int* OUTPUT); +PyObject* t_output_tester3(int* OUTPUT, int* OUTPUT, int* OUTPUT, int* OUTPUT); +PyObject* t_output_tester4(); + +#endif + //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- diff --git a/wxPython/src/_notebook.i b/wxPython/src/_notebook.i index 1d9565a555..3f5e131b6f 100644 --- a/wxPython/src/_notebook.i +++ b/wxPython/src/_notebook.i @@ -69,9 +69,9 @@ public: virtual void SetImageList(wxImageList *imageList); // as SetImageList() but we will delete the image list ourselves - %apply SWIGTYPE *DISOWN { wxImageList *imageList }; + %disownarg( wxImageList *imageList ); void AssignImageList(wxImageList *imageList); - %clear wxImageList *imageList; + %cleardisown( wxImageList *imageList ); // get pointer (may be NULL) to the associated image list wxImageList* GetImageList() const; diff --git a/wxPython/src/_obj.i b/wxPython/src/_obj.i index c0c72f124a..cb77d13273 100644 --- a/wxPython/src/_obj.i +++ b/wxPython/src/_obj.i @@ -30,6 +30,7 @@ public: return self->GetClassInfo()->GetClassName(); } + %pythonAppend Destroy "args[0].thisown = 0" DocStr(Destroy, "Deletes the C++ object this Python object is a proxy for.", ""); void Destroy() { diff --git a/wxPython/src/_process.i b/wxPython/src/_process.i index bada7e7ac4..7c26a92e8b 100644 --- a/wxPython/src/_process.i +++ b/wxPython/src/_process.i @@ -187,7 +187,11 @@ long wxExecute(const wxString& command, { PyObject* o; o = PyInt_FromLong((long) (*$1)); +#if SWIG_VERSION < 0x010328 $result = t_output_helper($result, o); +#else + $result = SWIG_Python_AppendOutput($result, o); +#endif } int wxKill(long pid, wxSignal sig = wxSIGTERM, wxKillError* rc, int flags = wxKILL_NOCHILDREN); diff --git a/wxPython/src/_sizers.i b/wxPython/src/_sizers.i index 05d6af4e7e..04fa9fed83 100644 --- a/wxPython/src/_sizers.i +++ b/wxPython/src/_sizers.i @@ -43,6 +43,8 @@ methods are called. :see: `wx.SizerItemSpacer`, `wx.SizerItemWindow`, `wx.SizerItemSizer`", ""); + + ~wxSizerItem(); %extend { @@ -86,6 +88,7 @@ methods are called. int border, PyObject* userData=NULL ), "Constructs a `wx.SizerItem` for tracking a subsizer", ""); + %disownarg( wxSizer *sizer ); %RenameCtor(SizerItemSizer, wxSizerItem( wxSizer *sizer, int proportion, int flag, int border, PyObject* userData=NULL )) { @@ -97,6 +100,7 @@ methods are called. } return new wxSizerItem(sizer, proportion, flag, border, data); } + %cleardisown( wxSizer *sizer ); } @@ -214,9 +218,11 @@ added, if needed.", ""); wxSizer *, GetSizer(), "Get the subsizer (if any) that is managed by this sizer item.", ""); + %disownarg( wxSizer *sizer ); DocDeclStr( void , SetSizer( wxSizer *sizer ), "Set the subsizer to be managed by this sizer item.", ""); + %cleardisown( wxSizer *sizer ); DocDeclStr( @@ -395,7 +401,8 @@ method to determine where the drawing operations should take place. class wxSizer : public wxObject { public: // wxSizer(); **** abstract, can't instantiate - // ~wxSizer(); + + ~wxSizer(); %extend { void _setOORInfo(PyObject* _self) { @@ -512,6 +519,8 @@ public: wxPySizerItemInfo info = wxPySizerItemTypeHelper(item, true, false); if ( userData && (info.window || info.sizer || info.gotSize) ) data = new wxPyUserData(userData); + if ( info.sizer ) + PyObject_SetAttrString(item,"thisown",Py_False); wxPyEndBlockThreads(blocked); // Now call the real Add method if a valid item type was found @@ -543,6 +552,8 @@ the item at index *before*. See `Add` for a description of the parameters.", "" wxPySizerItemInfo info = wxPySizerItemTypeHelper(item, true, false); if ( userData && (info.window || info.sizer || info.gotSize) ) data = new wxPyUserData(userData); + if ( info.sizer ) + PyObject_SetAttrString(item,"thisown",Py_False); wxPyEndBlockThreads(blocked); // Now call the real Insert method if a valid item type was found @@ -575,6 +586,8 @@ this sizer. See `Add` for a description of the parameters.", ""); wxPySizerItemInfo info = wxPySizerItemTypeHelper(item, true, false); if ( userData && (info.window || info.sizer || info.gotSize) ) data = new wxPyUserData(userData); + if ( info.sizer ) + PyObject_SetAttrString(item,"thisown",Py_False); wxPyEndBlockThreads(blocked); // Now call the real Prepend method if a valid item type was found @@ -693,6 +706,9 @@ the item to be found.", ""); return self._SetItemMinSize(item, args[0]) } + + %disownarg( wxSizerItem *item ); + DocDeclAStrName( wxSizerItem* , Add( wxSizerItem *item ), "AddItem(self, SizerItem item)", @@ -711,6 +727,7 @@ the item to be found.", ""); "Prepends a `wx.SizerItem` to the sizer.", "", PrependItem); + %cleardisown( wxSizerItem *item ); %pythoncode { diff --git a/wxPython/src/_stockobjs.i b/wxPython/src/_stockobjs.i index 7ae7546af4..b3227af463 100644 --- a/wxPython/src/_stockobjs.i +++ b/wxPython/src/_stockobjs.i @@ -19,6 +19,7 @@ // See also wxPy_ReinitStockObjects in helpers.cpp %immutable; +%threadWrapperOff; wxFont* const wxNORMAL_FONT; wxFont* const wxSMALL_FONT; @@ -69,6 +70,7 @@ const wxPalette wxNullPalette; const wxFont wxNullFont; const wxColour wxNullColour; +%threadWrapperOn; %mutable; diff --git a/wxPython/src/_taskbar.i b/wxPython/src/_taskbar.i index 1a5ea7b228..abdc2c6539 100644 --- a/wxPython/src/_taskbar.i +++ b/wxPython/src/_taskbar.i @@ -104,9 +104,11 @@ public: %pythonAppend wxPyTaskBarIcon "self._setCallbackInfo(self, TaskBarIcon, 0)" wxPyTaskBarIcon(); + ~wxPyTaskBarIcon(); void _setCallbackInfo(PyObject* self, PyObject* _class, int incref); + %pythonAppend Destroy "args[0].thisown = 0"; %extend { void Destroy() { self->RemoveIcon(); diff --git a/wxPython/src/_toplvl.i b/wxPython/src/_toplvl.i index 7938545b17..7b9786d46c 100644 --- a/wxPython/src/_toplvl.i +++ b/wxPython/src/_toplvl.i @@ -341,11 +341,6 @@ public: static wxVisualAttributes GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL); - - %pythoncode { - def SendSizeEvent(self): - self.ProcessEvent(wx.SizeEvent((-1,-1))) - } }; //--------------------------------------------------------------------------- diff --git a/wxPython/src/_treectrl.i b/wxPython/src/_treectrl.i index 8c86481e5d..841df1aa77 100644 --- a/wxPython/src/_treectrl.i +++ b/wxPython/src/_treectrl.i @@ -121,13 +121,15 @@ public: class wxPyTreeItemData { public: wxPyTreeItemData(PyObject* obj = NULL); - + ~wxPyTreeItemData(); + PyObject* GetData(); void SetData(PyObject* obj); const wxTreeItemId& GetId(); void SetId(const wxTreeItemId& id); + %pythonAppend Destroy "args[0].thisown = 0" %extend { void Destroy() { delete self; } } }; @@ -144,7 +146,8 @@ public: wxTreeItemAttr(const wxColour& colText = wxNullColour, const wxColour& colBack = wxNullColour, const wxFont& font = wxNullFont); - + ~wxTreeItemAttr(); + // setters void SetTextColour(const wxColour& colText); void SetBackgroundColour(const wxColour& colBack); @@ -159,6 +162,7 @@ public: wxColour GetBackgroundColour(); wxFont GetFont(); + %pythonAppend Destroy "args[0].thisown = 0" %extend { void Destroy() { delete self; } } }; @@ -372,10 +376,10 @@ public: void SetImageList(wxImageList *imageList); void SetStateImageList(wxImageList *imageList); - %apply SWIGTYPE *DISOWN { wxImageList *imageList }; + %disownarg( wxImageList *imageList ); void AssignImageList(wxImageList *imageList); void AssignStateImageList(wxImageList *imageList); - %clear wxImageList *imageList; + %cleardisown( wxImageList *imageList ); // retrieve items label @@ -430,10 +434,12 @@ public: %extend { // associate a wxPyTreeItemData with the tree item + %disownarg( wxPyTreeItemData* data ); void SetItemData(const wxTreeItemId& item, wxPyTreeItemData* data) { data->SetId(item); // set the id self->SetItemData(item, data); } + %cleardisown( wxPyTreeItemData* data ); // associate a Python object with the tree item void SetItemPyData(const wxTreeItemId& item, PyObject* obj) { @@ -582,6 +588,7 @@ public: wxTreeItemId GetPrevVisible(const wxTreeItemId& item) const; + %disownarg( wxPyTreeItemData* data ); // add the root node to the tree wxTreeItemId AddRoot(const wxString& text, @@ -616,7 +623,8 @@ public: wxPyTreeItemData *data = NULL); - + %cleardisown( wxPyTreeItemData* data ); + // delete this item and associated data if any void Delete(const wxTreeItemId& item); diff --git a/wxPython/src/_window.i b/wxPython/src/_window.i index de89a749cf..4409434262 100644 --- a/wxPython/src/_window.i +++ b/wxPython/src/_window.i @@ -259,6 +259,7 @@ instead."); + %pythonAppend Destroy "args[0].thisown = 0" DocDeclStr( virtual bool , Destroy(), "Destroys the window safely. Frames and dialogs are not destroyed @@ -1454,9 +1455,11 @@ be reset back to default.", ""); + %disownarg( wxCaret *caret ); DocDeclStr( void , SetCaret(wxCaret *caret), "Sets the caret associated with the window.", ""); + %cleardisown( wxCaret *caret ); DocDeclStr( wxCaret *, GetCaret() const, @@ -1767,7 +1770,10 @@ wxHelpProvider implementation, and not in the window object itself.", ""); DocStr(SetToolTip, "Attach a tooltip to the window.", ""); %Rename(SetToolTipString, void, SetToolTip( const wxString &tip )); + + %disownarg( wxToolTip *tip ); void SetToolTip( wxToolTip *tip ); + %cleardisown( wxToolTip *tip ); DocDeclStr( wxToolTip* , GetToolTip() const, @@ -1782,16 +1788,12 @@ wxHelpProvider implementation, and not in the window object itself.", ""); // drag and drop // ------------- - // set/retrieve the drop target associated with this window (may be - // NULL; it's owned by the window and will be deleted by it) - %apply SWIGTYPE *DISOWN { wxPyDropTarget *dropTarget }; - + %disownarg( wxPyDropTarget *dropTarget ); DocDeclStr( virtual void , SetDropTarget( wxPyDropTarget *dropTarget ), "Associates a drop target with this window. If the window already has a drop target, it is deleted.", ""); - - %clear wxPyDropTarget *dropTarget; + %cleardisown( wxPyDropTarget *dropTarget ); DocDeclStr( @@ -1855,6 +1857,7 @@ this function gets called automatically by the default EVT_SIZE handler when the window is resized.", ""); + %disownarg( wxSizer *sizer ); DocDeclStr( void , SetSizer(wxSizer *sizer, bool deleteOld = true ), "Sets the window to have the given layout sizer. The window will then @@ -1868,7 +1871,8 @@ non-None, and False otherwise.", ""); void , SetSizerAndFit( wxSizer *sizer, bool deleteOld = true ), "The same as SetSizer, except it also sets the size hints for the window based on the sizer's minimum size.", ""); - + %cleardisown( wxSizer *sizer ); + DocDeclStr( wxSizer *, GetSizer() const, @@ -1963,6 +1967,11 @@ wxControl where it returns true.", ""); if hasattr(self, '_setCallbackInfo'): self._setCallbackInfo(self, self.__class__) } + + %pythoncode { + def SendSizeEvent(self): + self.GetEventhandler().ProcessEvent(wx.SizeEvent((-1,-1))) + } }; diff --git a/wxPython/src/grid.i b/wxPython/src/grid.i index 48bfc14501..fa42ac8fee 100644 --- a/wxPython/src/grid.i +++ b/wxPython/src/grid.i @@ -44,11 +44,11 @@ MAKE_CONST_WXSTRING_NOSWIG(DefaultDateTimeFormat); //--------------------------------------------------------------------------- // OOR related typemaps and helper functions -%typemap(out) wxGridCellRenderer* { $result = wxPyMake_wxGridCellRenderer($1, $owner); } -%typemap(out) wxGridCellEditor* { $result = wxPyMake_wxGridCellEditor($1, $owner); } -%typemap(out) wxGridCellAttr* { $result = wxPyMake_wxGridCellAttr($1, $owner); } -%typemap(out) wxGridCellAttrProvider* { $result = wxPyMake_wxGridCellAttrProvider($1, $owner); } -%typemap(out) wxGridTableBase* { $result = wxPyMake_wxGridTableBase($1, $owner); } +%typemap(out) wxGridCellRenderer* { $result = wxPyMake_wxGridCellRenderer($1, (bool)$owner); } +%typemap(out) wxGridCellEditor* { $result = wxPyMake_wxGridCellEditor($1, (bool)$owner); } +%typemap(out) wxGridCellAttr* { $result = wxPyMake_wxGridCellAttr($1, (bool)$owner); } +%typemap(out) wxGridCellAttrProvider* { $result = wxPyMake_wxGridCellAttrProvider($1, (bool)$owner); } +%typemap(out) wxGridTableBase* { $result = wxPyMake_wxGridTableBase($1, (bool)$owner); } %{ @@ -796,6 +796,8 @@ public: virtual void StartingKey(wxKeyEvent& event); virtual void StartingClick(); virtual void HandleReturn(wxKeyEvent& event); + + %pythonAppend Destroy "args[0].thisown = 0" virtual void Destroy(); }; @@ -1362,6 +1364,7 @@ public: wxPyGridTableBase(); void _setCallbackInfo(PyObject* self, PyObject* _class); + %pythonAppend Destroy "args[0].thisown = 0" %extend { void Destroy() { delete self; } } wxString base_GetTypeName( int row, int col ); diff --git a/wxPython/src/html.i b/wxPython/src/html.i index 651cfe2767..e7656c3b64 100644 --- a/wxPython/src/html.i +++ b/wxPython/src/html.i @@ -1255,7 +1255,10 @@ public: wxHtmlHelpData* GetData(); wxHtmlHelpController* GetController() const; + + %disownarg( wxHtmlHelpController* controller ); void SetController(wxHtmlHelpController* controller); + %cleardisown( wxHtmlHelpController* controller ); // Displays page x. If not found it will offect the user a choice of // searching books. @@ -1360,7 +1363,9 @@ public: wxHtmlHelpController* GetController() const; /// Sets the help controller associated with the window. + %disownarg( wxHtmlHelpController* controller ); void SetController(wxHtmlHelpController* controller); + %cleardisown( wxHtmlHelpController* controller ); /// Returns the help window. wxHtmlHelpWindow* GetHelpWindow() const; @@ -1417,7 +1422,9 @@ public: wxHtmlHelpController* GetController() const; /// Sets the controller associated with this dialog. + %disownarg( wxHtmlHelpController* controller ); void SetController(wxHtmlHelpController* controller); + %cleardisown( wxHtmlHelpController* controller ); /// Returns the help window. wxHtmlHelpWindow* GetHelpWindow() const; @@ -1533,8 +1540,6 @@ public: void MakeModalIfNeeded(); wxWindow* FindTopLevelWindow(); - - %pythoncode { def Destroy(self): pass } }; diff --git a/wxPython/src/my_typemaps.i b/wxPython/src/my_typemaps.i index c22b3ae7ef..f8b436a38b 100644 --- a/wxPython/src/my_typemaps.i +++ b/wxPython/src/my_typemaps.i @@ -325,52 +325,52 @@ MAKE_INT_ARRAY_TYPEMAPS(styles, styles_field) // NOTE: For those classes that also call _setOORInfo these typemaps should be // disabled for the constructor. -%typemap(out) wxEvtHandler* { $result = wxPyMake_wxObject($1, $owner); } -%typemap(out) wxMenu* { $result = wxPyMake_wxObject($1, $owner); } -%typemap(out) wxValidator* { $result = wxPyMake_wxObject($1, $owner); } - -%typemap(out) wxApp* { $result = wxPyMake_wxObject($1, $owner); } -%typemap(out) wxPyApp* { $result = wxPyMake_wxObject($1, $owner); } -%typemap(out) wxDC* { $result = wxPyMake_wxObject($1, $owner); } -%typemap(out) wxFSFile* { $result = wxPyMake_wxObject($1, $owner); } -%typemap(out) wxFileSystem* { $result = wxPyMake_wxObject($1, $owner); } -%typemap(out) wxImageList* { $result = wxPyMake_wxObject($1, $owner); } -%typemap(out) wxImage* { $result = wxPyMake_wxObject($1, $owner); } -%typemap(out) wxListItem* { $result = wxPyMake_wxObject($1, $owner); } -%typemap(out) wxMenuItem* { $result = wxPyMake_wxObject($1, $owner); } -%typemap(out) wxMouseEvent* { $result = wxPyMake_wxObject($1, $owner); } -%typemap(out) wxObject* { $result = wxPyMake_wxObject($1, $owner); } -%typemap(out) wxPyPrintout* { $result = wxPyMake_wxObject($1, $owner); } -%typemap(out) wxToolBarToolBase* { $result = wxPyMake_wxObject($1, $owner); } -%typemap(out) wxToolTip* { $result = wxPyMake_wxObject($1, $owner); } - - -%typemap(out) wxBitmapButton* { $result = wxPyMake_wxObject($1, $owner); } -%typemap(out) wxButton* { $result = wxPyMake_wxObject($1, $owner); } -%typemap(out) wxControl* { $result = wxPyMake_wxObject($1, $owner); } -%typemap(out) wxFrame* { $result = wxPyMake_wxObject($1, $owner); } -%typemap(out) wxGrid* { $result = wxPyMake_wxObject($1, $owner); } -//%typemap(out) wxListCtrl* { $result = wxPyMake_wxObject($1, $owner); } -%typemap(out) wxMDIChildFrame* { $result = wxPyMake_wxObject($1, $owner); } -%typemap(out) wxMDIClientWindow* { $result = wxPyMake_wxObject($1, $owner); } -%typemap(out) wxMenuBar* { $result = wxPyMake_wxObject($1, $owner); } -%typemap(out) wxNotebook* { $result = wxPyMake_wxObject($1, $owner); } -%typemap(out) wxStaticBox* { $result = wxPyMake_wxObject($1, $owner); } -%typemap(out) wxStatusBar* { $result = wxPyMake_wxObject($1, $owner); } -%typemap(out) wxTextCtrl* { $result = wxPyMake_wxObject($1, $owner); } -%typemap(out) wxToolBar* { $result = wxPyMake_wxObject($1, $owner); } -%typemap(out) wxToolBarBase* { $result = wxPyMake_wxObject($1, $owner); } -//%typemap(out) wxTreeCtrl* { $result = wxPyMake_wxObject($1, $owner); } -%typemap(out) wxPyTreeCtrl* { $result = wxPyMake_wxObject($1, $owner); } -%typemap(out) wxWindow* { $result = wxPyMake_wxObject($1, $owner); } -%typemap(out) wxPyHtmlWindow* { $result = wxPyMake_wxObject($1, $owner); } -%typemap(out) wxWizardPage* { $result = wxPyMake_wxObject($1, $owner); } -%typemap(out) wxPyWizardPage* { $result = wxPyMake_wxObject($1, $owner); } -%typemap(out) wxPanel* { $result = wxPyMake_wxObject($1, $owner); } -%typemap(out) wxDialog* { $result = wxPyMake_wxObject($1, $owner); } -%typemap(out) wxScrolledWindow* { $result = wxPyMake_wxObject($1, $owner); } - -%typemap(out) wxSizer* { $result = wxPyMake_wxObject($1, $owner); } +%typemap(out) wxEvtHandler* { $result = wxPyMake_wxObject($1, (bool)$owner); } +%typemap(out) wxMenu* { $result = wxPyMake_wxObject($1, (bool)$owner); } +%typemap(out) wxValidator* { $result = wxPyMake_wxObject($1, (bool)$owner); } + +%typemap(out) wxApp* { $result = wxPyMake_wxObject($1, (bool)$owner); } +%typemap(out) wxPyApp* { $result = wxPyMake_wxObject($1, (bool)$owner); } +%typemap(out) wxDC* { $result = wxPyMake_wxObject($1, (bool)$owner); } +%typemap(out) wxFSFile* { $result = wxPyMake_wxObject($1, (bool)$owner); } +%typemap(out) wxFileSystem* { $result = wxPyMake_wxObject($1, (bool)$owner); } +%typemap(out) wxImageList* { $result = wxPyMake_wxObject($1, (bool)$owner); } +%typemap(out) wxImage* { $result = wxPyMake_wxObject($1, (bool)$owner); } +%typemap(out) wxListItem* { $result = wxPyMake_wxObject($1, (bool)$owner); } +%typemap(out) wxMenuItem* { $result = wxPyMake_wxObject($1, (bool)$owner); } +%typemap(out) wxMouseEvent* { $result = wxPyMake_wxObject($1, (bool)$owner); } +%typemap(out) wxObject* { $result = wxPyMake_wxObject($1, (bool)$owner); } +%typemap(out) wxPyPrintout* { $result = wxPyMake_wxObject($1, (bool)$owner); } +%typemap(out) wxToolBarToolBase* { $result = wxPyMake_wxObject($1, (bool)$owner); } +%typemap(out) wxToolTip* { $result = wxPyMake_wxObject($1, (bool)$owner); } + + +%typemap(out) wxBitmapButton* { $result = wxPyMake_wxObject($1, (bool)$owner); } +%typemap(out) wxButton* { $result = wxPyMake_wxObject($1, (bool)$owner); } +%typemap(out) wxControl* { $result = wxPyMake_wxObject($1, (bool)$owner); } +%typemap(out) wxFrame* { $result = wxPyMake_wxObject($1, (bool)$owner); } +%typemap(out) wxGrid* { $result = wxPyMake_wxObject($1, (bool)$owner); } +//%typemap(out) wxListCtrl* { $result = wxPyMake_wxObject($1, (bool)$owner); } +%typemap(out) wxMDIChildFrame* { $result = wxPyMake_wxObject($1, (bool)$owner); } +%typemap(out) wxMDIClientWindow* { $result = wxPyMake_wxObject($1, (bool)$owner); } +%typemap(out) wxMenuBar* { $result = wxPyMake_wxObject($1, (bool)$owner); } +%typemap(out) wxNotebook* { $result = wxPyMake_wxObject($1, (bool)$owner); } +%typemap(out) wxStaticBox* { $result = wxPyMake_wxObject($1, (bool)$owner); } +%typemap(out) wxStatusBar* { $result = wxPyMake_wxObject($1, (bool)$owner); } +%typemap(out) wxTextCtrl* { $result = wxPyMake_wxObject($1, (bool)$owner); } +%typemap(out) wxToolBar* { $result = wxPyMake_wxObject($1, (bool)$owner); } +%typemap(out) wxToolBarBase* { $result = wxPyMake_wxObject($1, (bool)$owner); } +//%typemap(out) wxTreeCtrl* { $result = wxPyMake_wxObject($1, (bool)$owner); } +%typemap(out) wxPyTreeCtrl* { $result = wxPyMake_wxObject($1, (bool)$owner); } +%typemap(out) wxWindow* { $result = wxPyMake_wxObject($1, (bool)$owner); } +%typemap(out) wxPyHtmlWindow* { $result = wxPyMake_wxObject($1, (bool)$owner); } +%typemap(out) wxWizardPage* { $result = wxPyMake_wxObject($1, (bool)$owner); } +%typemap(out) wxPyWizardPage* { $result = wxPyMake_wxObject($1, (bool)$owner); } +%typemap(out) wxPanel* { $result = wxPyMake_wxObject($1, (bool)$owner); } +%typemap(out) wxDialog* { $result = wxPyMake_wxObject($1, (bool)$owner); } +%typemap(out) wxScrolledWindow* { $result = wxPyMake_wxObject($1, (bool)$owner); } + +%typemap(out) wxSizer* { $result = wxPyMake_wxObject($1, (bool)$owner); } //--------------------------------------------------------------------------- diff --git a/wxPython/src/pyfragments.swg b/wxPython/src/pyfragments.swg index 84fc9a705a..e3394d8c29 100644 --- a/wxPython/src/pyfragments.swg +++ b/wxPython/src/pyfragments.swg @@ -1,45 +1,54 @@ -// There standard t_output_helper has been changed to return a list rather -// than a tuple, we'll replace it with the old implementation here. - - -%fragment("t_output_helper","header") %{ - static PyObject* t_output_helper(PyObject* target, PyObject* o) { - PyObject* o2; - PyObject* o3; - - if (!target) { - target = o; - } else if (target == Py_None) { - Py_DECREF(Py_None); - target = o; - } else { - if (!PyTuple_Check(target)) { - o2 = target; - target = PyTuple_New(1); - PyTuple_SetItem(target, 0, o2); - } - o3 = PyTuple_New(1); - PyTuple_SetItem(o3, 0, o); - - o2 = target; - target = PySequence_Concat(o2, o3); - Py_DECREF(o2); - Py_DECREF(o3); +//---------------------------------------------------------------------- + +// The standard t_output_helper has been changed to return a list rather than +// a tuple, we'll replace it with the old implementation here. In SWIG 1.3.27 +// and earlier it is implemented as a $fragment, so it is only inserted in to +// the modules that need it. For SWIG 1.3.28 we just need to add a -D on the +// compile command line to turn on this version of the AppendOuput function. +#if SWIG_VERSION < 0x010328 +%fragment("t_output_helper","header") +%{ + static PyObject* t_output_helper(PyObject* result, PyObject* obj) + { + PyObject* o2; + PyObject* o3; + if (!result) { + result = obj; + } else if (result == Py_None) { + Py_DECREF(result); + result = obj; + } else { + if (!PyTuple_Check(result)) { + o2 = result; + result = PyTuple_New(1); + PyTuple_SET_ITEM(result, 0, o2); + } + o3 = PyTuple_New(1); + PyTuple_SetItem(o3, 0, obj); + o2 = result; + result = PySequence_Concat(o2, o3); + Py_DECREF(o2); + Py_DECREF(o3); + } + return result; } - return target; - } %} +#endif + + +//---------------------------------------------------------------------- // These fragments are inserted in modules that need to convert PyObjects to // integer values, my versions allow any numeric type to be used, as long as // it can be converted to a PyInt. (Specifically, I allow floats where the // default SWIG_AsVal_long would just raise an exception. // +#if SWIG_VERSION < 0x010328 %fragment(SWIG_AsVal_frag(long), "header") { SWIGINTERN int @@ -50,7 +59,7 @@ SWIG_AsVal(long)(PyObject* obj, long* val) return 1; } else { - SWIG_type_error("number", obj); + SWIG_Python_TypeError("number", obj); } return 0; } @@ -64,7 +73,7 @@ SWIG_AsVal(unsigned long)(PyObject* obj, unsigned long* val) { long v = 0; if (SWIG_AsVal_long(obj, &v) && v < 0) { - SWIG_type_error("unsigned number", obj); + SWIG_Python_TypeError("unsigned number", obj); } else if (val) *val = (unsigned long)v; @@ -82,8 +91,55 @@ SWIG_AsVal(double)(PyObject *obj, double* val) return 1; } else { - SWIG_type_error("number", obj); + SWIG_Python_TypeError("number", obj); } return 0; } } + + +#else // SWIG_VERSION >= 1.3.28 + +%fragment(SWIG_AsVal_frag(long), "header") { +SWIGINTERN int +SWIG_AsVal(long)(PyObject* obj, long* val) +{ + if (PyNumber_Check(obj)) { + if (val) *val = PyInt_AsLong(obj); + return SWIG_OK; + } + return SWIG_TypeError; +} +} + + +%fragment(SWIG_AsVal_frag(unsigned long), "header", + fragment=SWIG_AsVal_frag(long)) { +SWIGINTERN int +SWIG_AsVal(unsigned long)(PyObject* obj, unsigned long* val) +{ + long v = 0; + if (SWIG_AsVal_long(obj, &v) && v < 0) { + return SWIG_TypeError; + } + else if (val) + *val = (unsigned long)v; + return SWIG_OK; +} +} + + +%fragment(SWIG_AsVal_frag(double), "header") { +SWIGINTERN int +SWIG_AsVal(double)(PyObject *obj, double* val) +{ + if (PyNumber_Check(obj)) { + if (val) *val = PyFloat_AsDouble(obj); + return SWIG_OK; + } + return SWIG_TypeError; +} +} + + +#endif // SWIG_VERSION -- 2.47.2