|
|
|
@ -9,12 +9,12 @@ |
|
|
|
PYTHON_FOOTPRINT_WIZARD::PYTHON_FOOTPRINT_WIZARD(PyObject *aWizard) |
|
|
|
{ |
|
|
|
this->m_PyWizard= aWizard; |
|
|
|
Py_XINCREF(aWizard); |
|
|
|
Py_XINCREF( aWizard ); |
|
|
|
} |
|
|
|
|
|
|
|
PYTHON_FOOTPRINT_WIZARD::~PYTHON_FOOTPRINT_WIZARD() |
|
|
|
{ |
|
|
|
Py_XDECREF(this->m_PyWizard); |
|
|
|
Py_XDECREF( this->m_PyWizard ); |
|
|
|
} |
|
|
|
|
|
|
|
PyObject* PYTHON_FOOTPRINT_WIZARD::CallMethod(const char* aMethod, PyObject *aArglist) |
|
|
|
@ -22,85 +22,86 @@ PyObject* PYTHON_FOOTPRINT_WIZARD::CallMethod(const char* aMethod, PyObject *aAr |
|
|
|
PyObject *pFunc; |
|
|
|
|
|
|
|
/* pFunc is a new reference to the desired method */ |
|
|
|
pFunc = PyObject_GetAttrString(this->m_PyWizard, aMethod); |
|
|
|
pFunc = PyObject_GetAttrString( this->m_PyWizard, aMethod ); |
|
|
|
|
|
|
|
if (pFunc && PyCallable_Check(pFunc)) |
|
|
|
if ( pFunc && PyCallable_Check( pFunc ) ) |
|
|
|
{ |
|
|
|
PyObject *result; |
|
|
|
|
|
|
|
result = PyObject_CallObject(pFunc, aArglist); |
|
|
|
result = PyObject_CallObject( pFunc, aArglist ); |
|
|
|
|
|
|
|
if (PyErr_Occurred()) |
|
|
|
if ( PyErr_Occurred() ) |
|
|
|
{ |
|
|
|
PyObject *t, *v, *b; |
|
|
|
PyErr_Fetch(&t, &v, &b); |
|
|
|
printf ("calling %s()\n",aMethod); |
|
|
|
printf ("Exception: %s\n",PyString_AsString(PyObject_Str(v))); |
|
|
|
printf (" : %s\n",PyString_AsString(PyObject_Str(b))); |
|
|
|
PyErr_Fetch( &t, &v, &b ); |
|
|
|
printf ( "calling %s()\n", aMethod ); |
|
|
|
printf ( "Exception: %s\n", PyString_AsString( PyObject_Str(v) ) ); |
|
|
|
printf ( " : %s\n", PyString_AsString( PyObject_Str(b) ) ); |
|
|
|
} |
|
|
|
|
|
|
|
if (result) |
|
|
|
if ( result ) |
|
|
|
{ |
|
|
|
Py_XDECREF(pFunc); |
|
|
|
return result; |
|
|
|
Py_XDECREF( pFunc ); |
|
|
|
return result; |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
printf("method not found, or not callable: %s\n",aMethod); |
|
|
|
printf( "method not found, or not callable: %s\n", aMethod ); |
|
|
|
} |
|
|
|
|
|
|
|
if (pFunc) Py_XDECREF(pFunc); |
|
|
|
if ( pFunc ) |
|
|
|
Py_XDECREF( pFunc ); |
|
|
|
|
|
|
|
return NULL; |
|
|
|
} |
|
|
|
|
|
|
|
wxString PYTHON_FOOTPRINT_WIZARD::CallRetStrMethod(const char* aMethod, PyObject *aArglist) |
|
|
|
wxString PYTHON_FOOTPRINT_WIZARD::CallRetStrMethod( const char* aMethod, PyObject *aArglist ) |
|
|
|
{ |
|
|
|
wxString ret; |
|
|
|
|
|
|
|
ret.Clear(); |
|
|
|
PyObject *result = CallMethod(aMethod,aArglist); |
|
|
|
if (result) |
|
|
|
PyObject *result = CallMethod( aMethod, aArglist ); |
|
|
|
if ( result ) |
|
|
|
{ |
|
|
|
const char *str_res = PyString_AsString(result); |
|
|
|
ret = wxString::FromUTF8(str_res); |
|
|
|
Py_DECREF(result); |
|
|
|
const char *str_res = PyString_AsString( result ); |
|
|
|
ret = wxString::FromUTF8( str_res ); |
|
|
|
Py_DECREF( result ); |
|
|
|
} |
|
|
|
return ret; |
|
|
|
} |
|
|
|
|
|
|
|
wxArrayString PYTHON_FOOTPRINT_WIZARD::CallRetArrayStrMethod |
|
|
|
(const char *aMethod, PyObject *aArglist) |
|
|
|
( const char *aMethod, PyObject *aArglist ) |
|
|
|
{ |
|
|
|
PyObject *result, *element; |
|
|
|
wxArrayString ret; |
|
|
|
wxString str_item; |
|
|
|
|
|
|
|
result = CallMethod(aMethod,aArglist); |
|
|
|
result = CallMethod( aMethod, aArglist ); |
|
|
|
|
|
|
|
if (result) |
|
|
|
if ( result ) |
|
|
|
{ |
|
|
|
if (!PyList_Check(result)) |
|
|
|
if ( !PyList_Check(result) ) |
|
|
|
{ |
|
|
|
Py_DECREF(result); |
|
|
|
ret.Add(wxT("PYTHON_FOOTPRINT_WIZARD::CallRetArrayStrMethod, " |
|
|
|
"result is not a list"),1); |
|
|
|
Py_DECREF( result ); |
|
|
|
ret.Add( wxT("PYTHON_FOOTPRINT_WIZARD::CallRetArrayStrMethod, " |
|
|
|
"result is not a list"),1 ); |
|
|
|
return ret; |
|
|
|
} |
|
|
|
int list_size = PyList_Size(result); |
|
|
|
int list_size = PyList_Size( result ); |
|
|
|
|
|
|
|
for (int n=0;n<list_size;n++) |
|
|
|
for ( int n=0; n<list_size; n++ ) |
|
|
|
{ |
|
|
|
element = PyList_GetItem(result,n); |
|
|
|
element = PyList_GetItem( result, n ); |
|
|
|
|
|
|
|
const char *str_res = PyString_AsString(element); |
|
|
|
str_item = wxString::FromUTF8(str_res); |
|
|
|
ret.Add(str_item,1); |
|
|
|
const char *str_res = PyString_AsString( element ); |
|
|
|
str_item = wxString::FromUTF8( str_res ); |
|
|
|
ret.Add( str_item, 1 ); |
|
|
|
} |
|
|
|
|
|
|
|
Py_DECREF(result); |
|
|
|
Py_DECREF( result ); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -111,17 +112,17 @@ wxArrayString PYTHON_FOOTPRINT_WIZARD::CallRetArrayStrMethod |
|
|
|
|
|
|
|
wxString PYTHON_FOOTPRINT_WIZARD::GetName() |
|
|
|
{ |
|
|
|
return CallRetStrMethod("GetName"); |
|
|
|
return CallRetStrMethod( "GetName" ); |
|
|
|
} |
|
|
|
|
|
|
|
wxString PYTHON_FOOTPRINT_WIZARD::GetImage() |
|
|
|
{ |
|
|
|
return CallRetStrMethod("GetImage"); |
|
|
|
return CallRetStrMethod( "GetImage" ); |
|
|
|
} |
|
|
|
|
|
|
|
wxString PYTHON_FOOTPRINT_WIZARD::GetDescription() |
|
|
|
{ |
|
|
|
return CallRetStrMethod("GetDescription"); |
|
|
|
return CallRetStrMethod( "GetDescription" ); |
|
|
|
} |
|
|
|
|
|
|
|
int PYTHON_FOOTPRINT_WIZARD::GetNumParameterPages() |
|
|
|
@ -130,52 +131,53 @@ int PYTHON_FOOTPRINT_WIZARD::GetNumParameterPages() |
|
|
|
PyObject *result; |
|
|
|
|
|
|
|
/* Time to call the callback */ |
|
|
|
result = CallMethod("GetNumParameterPages",NULL); |
|
|
|
result = CallMethod( "GetNumParameterPages" , NULL ); |
|
|
|
|
|
|
|
if (result) |
|
|
|
{ |
|
|
|
if (!PyInt_Check(result)) return -1; |
|
|
|
ret = PyInt_AsLong(result); |
|
|
|
Py_DECREF(result); |
|
|
|
if ( !PyInt_Check( result ) ) |
|
|
|
return -1; |
|
|
|
ret = PyInt_AsLong( result ); |
|
|
|
Py_DECREF( result ); |
|
|
|
} |
|
|
|
return ret; |
|
|
|
} |
|
|
|
|
|
|
|
wxString PYTHON_FOOTPRINT_WIZARD::GetParameterPageName(int aPage) |
|
|
|
wxString PYTHON_FOOTPRINT_WIZARD::GetParameterPageName( int aPage ) |
|
|
|
{ |
|
|
|
wxString ret; |
|
|
|
PyObject *arglist; |
|
|
|
PyObject *result; |
|
|
|
|
|
|
|
/* Time to call the callback */ |
|
|
|
arglist = Py_BuildValue("(i)", aPage); |
|
|
|
result = CallMethod("GetParameterPageName",arglist); |
|
|
|
Py_DECREF(arglist); |
|
|
|
arglist = Py_BuildValue( "(i)", aPage ); |
|
|
|
result = CallMethod( "GetParameterPageName", arglist ); |
|
|
|
Py_DECREF( arglist ); |
|
|
|
|
|
|
|
if (result) |
|
|
|
if ( result ) |
|
|
|
{ |
|
|
|
const char *str_res = PyString_AsString(result); |
|
|
|
ret = wxString::FromUTF8(str_res); |
|
|
|
Py_DECREF(result); |
|
|
|
const char *str_res = PyString_AsString( result ); |
|
|
|
ret = wxString::FromUTF8( str_res ); |
|
|
|
Py_DECREF( result ); |
|
|
|
} |
|
|
|
return ret; |
|
|
|
} |
|
|
|
|
|
|
|
wxArrayString PYTHON_FOOTPRINT_WIZARD::GetParameterNames(int aPage) |
|
|
|
wxArrayString PYTHON_FOOTPRINT_WIZARD::GetParameterNames( int aPage ) |
|
|
|
{ |
|
|
|
|
|
|
|
PyObject *arglist; |
|
|
|
wxArrayString ret; |
|
|
|
|
|
|
|
arglist = Py_BuildValue("(i)", aPage); |
|
|
|
ret = CallRetArrayStrMethod("GetParameterNames",arglist); |
|
|
|
Py_DECREF(arglist); |
|
|
|
arglist = Py_BuildValue( "(i)", aPage ); |
|
|
|
ret = CallRetArrayStrMethod( "GetParameterNames", arglist ); |
|
|
|
Py_DECREF( arglist ); |
|
|
|
|
|
|
|
for (unsigned i=0;i<ret.GetCount();i++) |
|
|
|
for ( unsigned i=0; i<ret.GetCount(); i++ ) |
|
|
|
{ |
|
|
|
wxString rest; |
|
|
|
wxString item = ret[i]; |
|
|
|
if (item.StartsWith(wxT("*"),&rest)) |
|
|
|
if ( item.StartsWith( wxT("*"), &rest ) ) |
|
|
|
{ |
|
|
|
ret[i]=rest; |
|
|
|
} |
|
|
|
@ -185,27 +187,27 @@ wxArrayString PYTHON_FOOTPRINT_WIZARD::GetParameterNames(int aPage) |
|
|
|
return ret; |
|
|
|
} |
|
|
|
|
|
|
|
wxArrayString PYTHON_FOOTPRINT_WIZARD::GetParameterTypes(int aPage) |
|
|
|
wxArrayString PYTHON_FOOTPRINT_WIZARD::GetParameterTypes( int aPage ) |
|
|
|
{ |
|
|
|
|
|
|
|
PyObject *arglist; |
|
|
|
wxArrayString ret; |
|
|
|
|
|
|
|
arglist = Py_BuildValue("(i)", aPage); |
|
|
|
ret = CallRetArrayStrMethod("GetParameterNames",arglist); |
|
|
|
arglist = Py_BuildValue( "(i)", aPage ); |
|
|
|
ret = CallRetArrayStrMethod( "GetParameterNames", arglist ); |
|
|
|
Py_DECREF(arglist); |
|
|
|
|
|
|
|
for (unsigned i=0;i<ret.GetCount();i++) |
|
|
|
for ( unsigned i=0; i<ret.GetCount(); i++ ) |
|
|
|
{ |
|
|
|
wxString rest; |
|
|
|
wxString item = ret[i]; |
|
|
|
if (item.StartsWith(wxT("*"),&rest)) |
|
|
|
if ( item.StartsWith( wxT("*"), &rest ) ) |
|
|
|
{ |
|
|
|
ret[i]=wxT("UNITS"); /* units */ |
|
|
|
ret[i]=wxT( "UNITS" ); /* units */ |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
ret[i]=wxT("IU"); /* internal units */ |
|
|
|
ret[i]=wxT( "IU" ); /* internal units */ |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@ -215,52 +217,50 @@ wxArrayString PYTHON_FOOTPRINT_WIZARD::GetParameterTypes(int aPage) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
wxArrayString PYTHON_FOOTPRINT_WIZARD::GetParameterValues(int aPage) |
|
|
|
wxArrayString PYTHON_FOOTPRINT_WIZARD::GetParameterValues( int aPage ) |
|
|
|
{ |
|
|
|
PyObject *arglist; |
|
|
|
wxArrayString ret; |
|
|
|
|
|
|
|
arglist = Py_BuildValue("(i)", aPage); |
|
|
|
ret = CallRetArrayStrMethod("GetParameterValues",arglist); |
|
|
|
Py_DECREF(arglist); |
|
|
|
arglist = Py_BuildValue( "(i)", aPage ); |
|
|
|
ret = CallRetArrayStrMethod( "GetParameterValues", arglist ); |
|
|
|
Py_DECREF( arglist ); |
|
|
|
|
|
|
|
return ret; |
|
|
|
} |
|
|
|
|
|
|
|
wxArrayString PYTHON_FOOTPRINT_WIZARD::GetParameterErrors(int aPage) |
|
|
|
wxArrayString PYTHON_FOOTPRINT_WIZARD::GetParameterErrors( int aPage ) |
|
|
|
{ |
|
|
|
PyObject *arglist; |
|
|
|
wxArrayString ret; |
|
|
|
|
|
|
|
arglist = Py_BuildValue("(i)", aPage); |
|
|
|
ret = CallRetArrayStrMethod("GetParameterErrors",arglist); |
|
|
|
Py_DECREF(arglist); |
|
|
|
arglist = Py_BuildValue( "(i)", aPage ); |
|
|
|
ret = CallRetArrayStrMethod( "GetParameterErrors", arglist ); |
|
|
|
Py_DECREF( arglist ); |
|
|
|
|
|
|
|
return ret; |
|
|
|
} |
|
|
|
|
|
|
|
wxString PYTHON_FOOTPRINT_WIZARD::SetParameterValues(int aPage,wxArrayString& aValues) |
|
|
|
wxString PYTHON_FOOTPRINT_WIZARD::SetParameterValues( int aPage, wxArrayString& aValues ) |
|
|
|
{ |
|
|
|
|
|
|
|
int len = aValues.size(); |
|
|
|
PyObject *py_list; |
|
|
|
|
|
|
|
py_list = PyList_New(len); |
|
|
|
py_list = PyList_New( len ); |
|
|
|
|
|
|
|
for (int i=0;i<len;i++) |
|
|
|
for ( int i=0; i<len ; i++ ) |
|
|
|
{ |
|
|
|
wxString str = aValues[i]; |
|
|
|
PyObject *py_str = PyString_FromString((const char*)str.mb_str()); |
|
|
|
PyList_SetItem(py_list, i, py_str); |
|
|
|
PyObject *py_str = PyString_FromString( (const char*)str.mb_str() ); |
|
|
|
PyList_SetItem( py_list, i, py_str ); |
|
|
|
} |
|
|
|
|
|
|
|
PyObject *arglist; |
|
|
|
|
|
|
|
arglist = Py_BuildValue("(i,O)", aPage,py_list); |
|
|
|
wxString res = CallRetStrMethod("SetParameterValues",arglist); |
|
|
|
Py_DECREF(arglist); |
|
|
|
|
|
|
|
|
|
|
|
arglist = Py_BuildValue( "(i,O)", aPage, py_list ); |
|
|
|
wxString res = CallRetStrMethod( "SetParameterValues", arglist ); |
|
|
|
Py_DECREF( arglist ); |
|
|
|
|
|
|
|
return res; |
|
|
|
} |
|
|
|
@ -271,24 +271,25 @@ MODULE *PyModule_to_MODULE(PyObject *obj0); |
|
|
|
MODULE *PYTHON_FOOTPRINT_WIZARD::GetModule() |
|
|
|
{ |
|
|
|
PyObject *result, *obj; |
|
|
|
result = CallMethod("GetModule",NULL); |
|
|
|
if (!result) return NULL; |
|
|
|
|
|
|
|
|
|
|
|
obj = PyObject_GetAttrString(result, "this"); |
|
|
|
if (PyErr_Occurred()) |
|
|
|
{ |
|
|
|
/*
|
|
|
|
PyObject *t, *v, *b; |
|
|
|
PyErr_Fetch(&t, &v, &b); |
|
|
|
printf ("calling GetModule()\n"); |
|
|
|
printf ("Exception: %s\n",PyString_AsString(PyObject_Str(v))); |
|
|
|
printf (" : %s\n",PyString_AsString(PyObject_Str(b))); |
|
|
|
*/ |
|
|
|
PyErr_Print(); |
|
|
|
} |
|
|
|
|
|
|
|
result = CallMethod( "GetModule", NULL ); |
|
|
|
|
|
|
|
if (!result) |
|
|
|
return NULL; |
|
|
|
|
|
|
|
obj = PyObject_GetAttrString( result, "this" ); |
|
|
|
|
|
|
|
if (PyErr_Occurred()) |
|
|
|
{ |
|
|
|
/*
|
|
|
|
PyObject *t, *v, *b; |
|
|
|
PyErr_Fetch(&t, &v, &b); |
|
|
|
printf ("calling GetModule()\n"); |
|
|
|
printf ("Exception: %s\n",PyString_AsString(PyObject_Str(v))); |
|
|
|
printf (" : %s\n",PyString_AsString(PyObject_Str(b))); |
|
|
|
*/ |
|
|
|
PyErr_Print(); |
|
|
|
} |
|
|
|
|
|
|
|
return PyModule_to_MODULE(obj); |
|
|
|
} |
|
|
|
|
|
|
|
@ -297,9 +298,9 @@ void PYTHON_FOOTPRINT_WIZARDS::register_wizard(PyObject* aPyWizard) |
|
|
|
{ |
|
|
|
PYTHON_FOOTPRINT_WIZARD *fw; |
|
|
|
|
|
|
|
fw = new PYTHON_FOOTPRINT_WIZARD(aPyWizard); |
|
|
|
fw = new PYTHON_FOOTPRINT_WIZARD( aPyWizard ); |
|
|
|
|
|
|
|
printf("Registered python footprint wizard '%s'\n", |
|
|
|
printf( "Registered python footprint wizard '%s'\n", |
|
|
|
(const char*)fw->GetName().mb_str() |
|
|
|
); |
|
|
|
|
|
|
|
@ -308,7 +309,6 @@ void PYTHON_FOOTPRINT_WIZARDS::register_wizard(PyObject* aPyWizard) |
|
|
|
|
|
|
|
fw->register_wizard(); |
|
|
|
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
/* just to test if it works correctly */ |
|
|
|
int pages = fw->GetNumParameterPages(); |
|
|
|
@ -321,9 +321,6 @@ void PYTHON_FOOTPRINT_WIZARDS::register_wizard(PyObject* aPyWizard) |
|
|
|
} |
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|