Changed wxSWIG to not generate Python code using apply, (since it will

be deprecated in the future) wxSWIG will use spam(*args, **kw) syntax
instead.  Also changed the generated __repr__ methods to be a bit more
informative.


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_4_BRANCH@19911 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Robin Dunn
2003-04-01 01:36:08 +00:00
parent 9137f764b6
commit c21b5bcd98
8 changed files with 54 additions and 43 deletions

View File

@@ -2,11 +2,19 @@ CHANGES.txt for wxPython
---------------------------------------------------------------------- ----------------------------------------------------------------------
????? 2.4.0.8
------- -------
Added wxScrolledPanel from Wil Sadkin Added wxScrolledPanel from Wil Sadkin
Added SetShape method to top level windows (e.g. wxFrame.)
Changed wxSWIG to not generate Python code using apply, (since it will
be deprecated in the future) wxSWIG will use spam(*args, **kw) syntax
instead. Also changed the generated __repr__ methods to be a bit more
informative.
2.4.0.7 2.4.0.7

View File

@@ -732,7 +732,7 @@ def wxCallAfter(callable, *args, **kw):
if _wxCallAfterId is None: if _wxCallAfterId is None:
_wxCallAfterId = wxNewEventType() _wxCallAfterId = wxNewEventType()
app.Connect(-1, -1, _wxCallAfterId, app.Connect(-1, -1, _wxCallAfterId,
lambda event: apply(event.callable, event.args, event.kw) ) lambda event: event.callable(*event.args, **event.kw) )
evt = wxPyEvent() evt = wxPyEvent()
evt.SetEventType(_wxCallAfterId) evt.SetEventType(_wxCallAfterId)
evt.callable = callable evt.callable = callable
@@ -904,7 +904,7 @@ class wxPyWidgetTester(wxApp):
return True return True
def SetWidget(self, widgetClass, *args): def SetWidget(self, widgetClass, *args):
w = apply(widgetClass, (self.frame,) + args) w = widgetClass(self.frame, *args)
self.frame.Show(True) self.frame.Show(True)
#---------------------------------------------------------------------------- #----------------------------------------------------------------------------

View File

@@ -454,7 +454,7 @@ public:
} // The OOR typemaps don't know what to do with the %new, so fix it up. } // The OOR typemaps don't know what to do with the %new, so fix it up.
%pragma(python) addtoclass = " %pragma(python) addtoclass = "
def GetColumn(self, *_args, **_kwargs): def GetColumn(self, *_args, **_kwargs):
val = apply(controls2c.wxListCtrl_GetColumn,(self,) + _args, _kwargs) val = ontrols2c.wxListCtrl_GetColumn(self, *_args, **_kwargs)
if val is not None: val.thisown = 1 if val is not None: val.thisown = 1
return val return val
" "
@@ -493,7 +493,7 @@ public:
} // The OOR typemaps don't know what to do with the %new, so fix it up. } // The OOR typemaps don't know what to do with the %new, so fix it up.
%pragma(python) addtoclass = " %pragma(python) addtoclass = "
def GetItem(self, *_args, **_kwargs): def GetItem(self, *_args, **_kwargs):
val = apply(controls2c.wxListCtrl_GetItem,(self,) + _args, _kwargs) val = controls2c.wxListCtrl_GetItem(self, *_args, **_kwargs)
if val is not None: val.thisown = 1 if val is not None: val.thisown = 1
return val return val
" "
@@ -1355,17 +1355,17 @@ public:
%pragma(python) addtoclass = " %pragma(python) addtoclass = "
# Redefine some methods that SWIG gets a bit confused on... # Redefine some methods that SWIG gets a bit confused on...
def GetFirstChild(self, *_args, **_kwargs): def GetFirstChild(self, *_args, **_kwargs):
val1,val2 = apply(controls2c.wxTreeCtrl_GetFirstChild,(self,) + _args, _kwargs) val1,val2 = controls2c.wxTreeCtrl_GetFirstChild(self, *_args, **_kwargs)
val1 = wxTreeItemIdPtr(val1) val1 = wxTreeItemIdPtr(val1)
val1.thisown = 1 val1.thisown = 1
return (val1,val2) return (val1,val2)
def GetNextChild(self, *_args, **_kwargs): def GetNextChild(self, *_args, **_kwargs):
val1,val2 = apply(controls2c.wxTreeCtrl_GetNextChild,(self,) + _args, _kwargs) val1,val2 = controls2c.wxTreeCtrl_GetNextChild(self, *_args, **_kwargs)
val1 = wxTreeItemIdPtr(val1) val1 = wxTreeItemIdPtr(val1)
val1.thisown = 1 val1.thisown = 1
return (val1,val2) return (val1,val2)
def HitTest(self, *_args, **_kwargs): def HitTest(self, *_args, **_kwargs):
val1, val2 = apply(controls2c.wxTreeCtrl_HitTest,(self,) + _args, _kwargs) val1, val2 = controls2c.wxTreeCtrl_HitTest(self, *_args, **_kwargs)
val1 = wxTreeItemIdPtr(val1) val1 = wxTreeItemIdPtr(val1)
val1.thisown = 1 val1.thisown = 1
return (val1,val2) return (val1,val2)
@@ -1458,6 +1458,9 @@ public:
wxTreeCtrl* GetTreeCtrl() const; wxTreeCtrl* GetTreeCtrl() const;
wxDirFilterListCtrl* GetFilterListCtrl() const; wxDirFilterListCtrl* GetFilterListCtrl() const;
// Collapse & expand the tree, thus re-creating it from scratch:
void ReCreateTree();
// //// Helpers // //// Helpers
// void SetupSections(); // void SetupSections();
// // Parse the filter into an array of filters and an array of descriptions // // Parse the filter into an array of filters and an array of descriptions

View File

@@ -739,9 +739,9 @@ public:
%pragma(python) addtoclass = " %pragma(python) addtoclass = "
def Init(self, *_args, **_kwargs): def Init(self, *_args, **_kwargs):
if type(_args[0]) in [type(''), type(u'')]: if type(_args[0]) in [type(''), type(u'')]:
val = apply(self.Init1, _args, _kwargs) val = self.Init1(*_args, **_kwargs)
else: else:
val = apply(self.Init2, _args, _kwargs) val = self.Init2(*_args, **_kwargs)
return val return val
" "

View File

@@ -173,41 +173,41 @@ public:
%pragma(python) addtoclass = " %pragma(python) addtoclass = "
def Add(self, *args, **kw): def Add(self, *args, **kw):
if type(args[0]) == type(1): if type(args[0]) == type(1):
apply(self.AddSpacer, args, kw) self.AddSpacer(*args, **kw)
elif isinstance(args[0], wxSizerPtr): elif isinstance(args[0], wxSizerPtr):
apply(self.AddSizer, args, kw) self.AddSizer(*args, **kw)
elif isinstance(args[0], wxWindowPtr): elif isinstance(args[0], wxWindowPtr):
apply(self.AddWindow, args, kw) self.AddWindow(*args, **kw)
else: else:
raise TypeError, 'Expected int, wxSizer or wxWindow parameter' raise TypeError, 'Expected int, wxSizer or wxWindow parameter'
def Insert(self, *args, **kw): def Insert(self, *args, **kw):
if type(args[1]) == type(1): if type(args[1]) == type(1):
apply(self.InsertSpacer, args, kw) self.InsertSpacer(*args, **kw)
elif isinstance(args[1], wxSizerPtr): elif isinstance(args[1], wxSizerPtr):
apply(self.InsertSizer, args, kw) self.InsertSizer(*args, **kw)
elif isinstance(args[1], wxWindowPtr): elif isinstance(args[1], wxWindowPtr):
apply(self.InsertWindow, args, kw) self.InsertWindow(*args, **kw)
else: else:
raise TypeError, 'Expected int, wxSizer or wxWindow parameter' raise TypeError, 'Expected int, wxSizer or wxWindow parameter'
def Prepend(self, *args, **kw): def Prepend(self, *args, **kw):
if type(args[0]) == type(1): if type(args[0]) == type(1):
apply(self.PrependSpacer, args, kw) self.PrependSpacer(*args, **kw)
elif isinstance(args[0], wxSizerPtr): elif isinstance(args[0], wxSizerPtr):
apply(self.PrependSizer, args, kw) self.PrependSizer(*args, **kw)
elif isinstance(args[0], wxWindowPtr): elif isinstance(args[0], wxWindowPtr):
apply(self.PrependWindow, args, kw) self.PrependWindow(*args, **kw)
else: else:
raise TypeError, 'Expected int, wxSizer or wxWindow parameter' raise TypeError, 'Expected int, wxSizer or wxWindow parameter'
def Remove(self, *args, **kw): def Remove(self, *args, **kw):
if type(args[0]) == type(1): if type(args[0]) == type(1):
return apply(self.RemovePos, args, kw) return self.RemovePos(*args, **kw)
elif isinstance(args[0], wxSizerPtr): elif isinstance(args[0], wxSizerPtr):
return apply(self.RemoveSizer, args, kw) return self.RemoveSizer(*args, **kw)
elif isinstance(args[0], wxWindowPtr): elif isinstance(args[0], wxWindowPtr):
return apply(self.RemoveWindow, args, kw) return self.RemoveWindow(*args, **kw)
else: else:
raise TypeError, 'Expected int, wxSizer or wxWindow parameter' raise TypeError, 'Expected int, wxSizer or wxWindow parameter'
@@ -215,7 +215,7 @@ public:
for childinfo in widgets: for childinfo in widgets:
if type(childinfo) != type(()): if type(childinfo) != type(()):
childinfo = (childinfo, ) childinfo = (childinfo, )
apply(self.Add, childinfo) self.Add(*childinfo)
" "
@@ -229,11 +229,11 @@ public:
%pragma(python) addtoclass = " %pragma(python) addtoclass = "
def SetItemMinSize(self, *args): def SetItemMinSize(self, *args):
if type(args[0]) == type(1): if type(args[0]) == type(1):
apply(self.SetItemMinSizePos, args) self.SetItemMinSizePos(*args)
elif isinstance(args[0], wxSizerPtr): elif isinstance(args[0], wxSizerPtr):
apply(self.SetItemMinSizeSizer, args) self.SetItemMinSizeSizer(*args)
elif isinstance(args[0], wxWindowPtr): elif isinstance(args[0], wxWindowPtr):
apply(self.SetItemMinSizeWindow, args) self.SetItemMinSizeWindow(*args)
else: else:
raise TypeError, 'Expected int, wxSizer or wxWindow parameter' raise TypeError, 'Expected int, wxSizer or wxWindow parameter'
" "
@@ -287,25 +287,25 @@ public:
%pragma(python) addtoclass = " %pragma(python) addtoclass = "
def Show(self, *args): def Show(self, *args):
if isinstance(args[0], wxSizerPtr): if isinstance(args[0], wxSizerPtr):
apply(self.ShowSizer, args) self.ShowSizer(*args)
elif isinstance(args[0], wxWindowPtr): elif isinstance(args[0], wxWindowPtr):
apply(self.ShowWindow, args) self.ShowWindow(*args)
else: else:
raise TypeError, 'Expected wxSizer or wxWindow parameter' raise TypeError, 'Expected wxSizer or wxWindow parameter'
def Hide(self, *args): def Hide(self, *args):
if isinstance(args[0], wxSizerPtr): if isinstance(args[0], wxSizerPtr):
apply(self.HideSizer, args) self.HideSizer(*args)
elif isinstance(args[0], wxWindowPtr): elif isinstance(args[0], wxWindowPtr):
apply(self.HideWindow, args) self.HideWindow(*args)
else: else:
raise TypeError, 'Expected wxSizer or wxWindow parameter' raise TypeError, 'Expected wxSizer or wxWindow parameter'
def IsShown(self, *args): def IsShown(self, *args):
if isinstance(args[0], wxSizerPtr): if isinstance(args[0], wxSizerPtr):
return apply(self.IsShownSizer, args) return self.IsShownSizer(*args)
elif isinstance(args[0], wxWindowPtr): elif isinstance(args[0], wxWindowPtr):
return apply(self.IsShownWindow, args) return self.IsShownWindow(*args)
else: else:
raise TypeError, 'Expected wxSizer or wxWindow parameter' raise TypeError, 'Expected wxSizer or wxWindow parameter'
" "

View File

@@ -431,7 +431,7 @@ public:
%pragma(python) addtoclass = "# replaces broken shadow method %pragma(python) addtoclass = "# replaces broken shadow method
def GetCaret(self, *_args, **_kwargs): def GetCaret(self, *_args, **_kwargs):
from misc2 import wxCaretPtr from misc2 import wxCaretPtr
val = apply(windowsc.wxWindow_GetCaret,(self,) + _args, _kwargs) val = windowsc.wxWindow_GetCaret(self, *_args, **_kwargs)
if val: val = wxCaretPtr(val) if val: val = wxCaretPtr(val)
return val return val
" "
@@ -613,17 +613,17 @@ public:
%pragma(python) addtoclass = " %pragma(python) addtoclass = "
def CalcScrolledPosition(self, *args): def CalcScrolledPosition(self, *args):
if len(args) == 1: if len(args) == 1:
return apply(self.CalcScrolledPosition1, args) return self.CalcScrolledPosition1(*args)
elif len(args) == 2: elif len(args) == 2:
return apply(self.CalcScrolledPosition2, args) return self.CalcScrolledPosition2(*args)
else: else:
raise TypeError, 'Invalid parameters: only (x,y) or (point) allowed' raise TypeError, 'Invalid parameters: only (x,y) or (point) allowed'
def CalcUnscrolledPosition(self, *args): def CalcUnscrolledPosition(self, *args):
if len(args) == 1: if len(args) == 1:
return apply(self.CalcUnscrolledPosition1, args) return self.CalcUnscrolledPosition1(*args)
elif len(args) == 2: elif len(args) == 2:
return apply(self.CalcUnscrolledPosition2, args) return self.CalcUnscrolledPosition2(*args)
else: else:
raise TypeError, 'Invalid parameters: only (x,y) or (point) allowed' raise TypeError, 'Invalid parameters: only (x,y) or (point) allowed'
" "

View File

@@ -146,7 +146,7 @@ void PYTHON::cpp_member_func(char *name, char *iname, DataType *t, ParmList *l)
if (docstring && doc_entry) { if (docstring && doc_entry) {
*pyclass << tab8 << "\"\"\"" << add_docstring(doc_entry) << "\"\"\"\n"; *pyclass << tab8 << "\"\"\"" << add_docstring(doc_entry) << "\"\"\"\n";
} }
*pyclass << tab8 << "val = apply(" << module << "." << name_member(realname,class_name) << ",(self,) + _args, _kwargs)\n"; *pyclass << tab8 << "val = " << module << "." << name_member(realname,class_name) << "(self, *_args, **_kwargs)\n";
// Check to see if the return type is an object // Check to see if the return type is an object
if ((hash.lookup(t->name)) && (t->is_pointer <= 1)) { if ((hash.lookup(t->name)) && (t->is_pointer <= 1)) {
@@ -216,7 +216,7 @@ void PYTHON::cpp_constructor(char *name, char *iname, ParmList *l) {
if (docstring && doc_entry) if (docstring && doc_entry)
*construct << tab8 << "\"\"\"" << add_docstring(doc_entry) << "\"\"\"\n"; *construct << tab8 << "\"\"\"" << add_docstring(doc_entry) << "\"\"\"\n";
*construct << tab8 << "self.this = apply(" << module << "." << name_construct(realname) << ",_args,_kwargs)\n"; *construct << tab8 << "self.this = " << module << "." << name_construct(realname) << "(*_args,**_kwargs)\n";
*construct << tab8 << "self.thisown = 1\n"; *construct << tab8 << "self.thisown = 1\n";
emitAddPragmas(*construct,"__init__",tab8); emitAddPragmas(*construct,"__init__",tab8);
have_constructor = 1; have_constructor = 1;
@@ -226,8 +226,8 @@ void PYTHON::cpp_constructor(char *name, char *iname, ParmList *l) {
// function for it. // function for it.
*additional << "def " << realname << "(*_args,**_kwargs):\n"; *additional << "def " << realname << "(*_args,**_kwargs):\n";
*additional << tab4 << "val = " << class_name << "Ptr(apply(" *additional << tab4 << "val = " << class_name << "Ptr("
<< module << "." << name_construct(realname) << ",_args,_kwargs))\n" << module << "." << name_construct(realname) << "(*_args,**_kwargs))\n"
<< tab4 << "val.thisown = 1\n"; << tab4 << "val.thisown = 1\n";
emitAddPragmas(*additional, realname, tab4); emitAddPragmas(*additional, realname, tab4);
*additional << tab4 << "return val\n\n"; *additional << tab4 << "return val\n\n";
@@ -322,7 +322,7 @@ void PYTHON::cpp_close_class() {
if (!have_repr) { if (!have_repr) {
// Supply a repr method for this class // Supply a repr method for this class
repr << tab4 << "def __repr__(self):\n" repr << tab4 << "def __repr__(self):\n"
<< tab8 << "return \"<C " << class_name <<" instance at %s>\" % (self.this,)\n"; << tab8 << "return \"<%s.%s instance; proxy of C++ " << class_name <<" instance at %s>\" % (self.__class__.__module__, self.__class__.__name__, self.this)\n";
classes << repr; classes << repr;
emitAddPragmas(classes,"__class__",tab4); emitAddPragmas(classes,"__class__",tab4);

View File

@@ -1071,7 +1071,7 @@ void PYTHON::create_function(char *name, char *iname, DataType *d, ParmList *l)
func << tab4 << "\"\"\"" << add_docstring(doc_entry) << "\"\"\"\n"; func << tab4 << "\"\"\"" << add_docstring(doc_entry) << "\"\"\"\n";
} }
func << tab4 << "val = apply(" << module << "." << iname << ",_args,_kwargs)\n"; func << tab4 << "val = " << module << "." << iname << "(*_args,**_kwargs)\n";
if (munge_return) { if (munge_return) {
// If the output of this object has been remapped in any way, we're // If the output of this object has been remapped in any way, we're