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
This commit is contained in:
Robin Dunn
2006-01-29 02:09:45 +00:00
parent 9a3fba2459
commit 214c4fbea5
32 changed files with 391 additions and 181 deletions

View File

@@ -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"

View File

@@ -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',

View File

@@ -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

View File

@@ -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; }}
};

View File

@@ -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`", "");
%cleardisown( wxDataObject *data );
%clear wxDataObject *data;
DocDeclStr(
virtual bool , IsSupported( const wxDataFormat& format ),

View File

@@ -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.", "");
%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);

View File

@@ -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),

View File

@@ -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;
}

View File

@@ -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; } }
};

View File

@@ -230,14 +230,11 @@ data.", "");
// return all formats in the provided array (of size GetFormatCount())
//virtual void GetAllFormats(wxDataFormat *formats,
// Direction dir = Get) const;
%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.", "");
%extend {
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;
%extend {
DocAStr(GetDataHere,
"GetDataHere(self, DataFormat format) -> String",
"Get the data bytes in the specified format, returns None on failure.
", "
"Get the data bytes in the specified format, returns None on failure.", "
:todo: This should use the python buffer interface isntead...");
%extend {
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.", "");
%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.", "");
}
%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();
%extend {
DocAStr(SetData,
"SetData(self, String data) -> bool",
"Copy the data value to the data object.", "");
%extend {
bool SetData(PyObject* data) {
bool rval;
wxPyBlock_t blocked = wxPyBeginBlockThreads();
@@ -783,10 +779,10 @@ public:
"Get the size of the data.", "");
%extend {
DocAStr(GetData,
"GetData(self) -> String",
"Returns the data bytes from the data object as a string.", "");
%extend {
PyObject* GetData() {
PyObject* obj;
wxPyBlock_t blocked = wxPyBeginBlockThreads();

View File

@@ -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

View File

@@ -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);

View File

@@ -72,6 +72,7 @@ public:
}
}
%pythonAppend _setOORInfo "args[0].thisown = 0";
%extend {
void _setOORInfo(PyObject* _self, bool incref=true) {
if (_self && _self != Py_None) {

View File

@@ -73,6 +73,7 @@ class wxGBPosition
{
public:
wxGBPosition(int row=0, int col=0);
~wxGBPosition();
int GetRow() const;
int GetCol() const;
@@ -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
@@ -406,6 +416,7 @@ position, False if something was already there.
}
}
%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,

View File

@@ -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;

View File

@@ -54,7 +54,7 @@ class wxLog
{
public:
wxLog();
~wxLog();
// these functions allow to completely disable all log messages
// is logging disabled now?
@@ -80,8 +80,11 @@ 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()
@@ -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);

View File

@@ -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));

View File

@@ -24,7 +24,12 @@ 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();
@@ -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
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------

View File

@@ -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;

View File

@@ -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() {

View File

@@ -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);

View File

@@ -44,6 +44,8 @@ methods are called.
:see: `wx.SizerItemSpacer`, `wx.SizerItemWindow`, `wx.SizerItemSizer`", "");
~wxSizerItem();
%extend {
DocStr(
@@ -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 {

View File

@@ -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;

View File

@@ -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();

View File

@@ -341,11 +341,6 @@ public:
static wxVisualAttributes
GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL);
%pythoncode {
def SendSizeEvent(self):
self.ProcessEvent(wx.SizeEvent((-1,-1)))
}
};
//---------------------------------------------------------------------------

View File

@@ -121,6 +121,7 @@ public:
class wxPyTreeItemData {
public:
wxPyTreeItemData(PyObject* obj = NULL);
~wxPyTreeItemData();
PyObject* GetData();
void SetData(PyObject* obj);
@@ -128,6 +129,7 @@ public:
const wxTreeItemId& GetId();
void SetId(const wxTreeItemId& id);
%pythonAppend Destroy "args[0].thisown = 0"
%extend { void Destroy() { delete self; } }
};
@@ -144,6 +146,7 @@ public:
wxTreeItemAttr(const wxColour& colText = wxNullColour,
const wxColour& colBack = wxNullColour,
const wxFont& font = wxNullFont);
~wxTreeItemAttr();
// setters
void SetTextColour(const wxColour& colText);
@@ -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,6 +623,7 @@ public:
wxPyTreeItemData *data = NULL);
%cleardisown( wxPyTreeItemData* data );
// delete this item and associated data if any
void Delete(const wxTreeItemId& item);

View File

@@ -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,6 +1871,7 @@ 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(
@@ -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)))
}
};

View File

@@ -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 );

View File

@@ -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 }
};

View File

@@ -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) 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, $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) 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, $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) 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, $owner); }
%typemap(out) wxSizer* { $result = wxPyMake_wxObject($1, (bool)$owner); }
//---------------------------------------------------------------------------

View File

@@ -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) {
// 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 (!target) {
target = o;
} else if (target == Py_None) {
Py_DECREF(Py_None);
target = o;
if (!result) {
result = obj;
} else if (result == Py_None) {
Py_DECREF(result);
result = obj;
} else {
if (!PyTuple_Check(target)) {
o2 = target;
target = PyTuple_New(1);
PyTuple_SetItem(target, 0, o2);
if (!PyTuple_Check(result)) {
o2 = result;
result = PyTuple_New(1);
PyTuple_SET_ITEM(result, 0, o2);
}
o3 = PyTuple_New(1);
PyTuple_SetItem(o3, 0, o);
o2 = target;
target = PySequence_Concat(o2, o3);
PyTuple_SetItem(o3, 0, obj);
o2 = result;
result = PySequence_Concat(o2, o3);
Py_DECREF(o2);
Py_DECREF(o3);
}
return target;
return result;
}
%}
#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