From c867ed9de4ac93bafe0e9dc9e03a9767d4bd3e15 Mon Sep 17 00:00:00 2001 From: Miguel Angel Ajo Date: Sun, 17 Mar 2013 02:14:46 +0100 Subject: [PATCH] Refactoring python to wxArrayString, and better exception error reporting --- pcbnew/scripting/pcbnew_footprint_wizards.cpp | 30 +-------- scripting/python_scripting.cpp | 67 +++++++++++++++++-- scripting/python_scripting.h | 3 + 3 files changed, 66 insertions(+), 34 deletions(-) diff --git a/pcbnew/scripting/pcbnew_footprint_wizards.cpp b/pcbnew/scripting/pcbnew_footprint_wizards.cpp index acbf7c0db8..4af964c909 100644 --- a/pcbnew/scripting/pcbnew_footprint_wizards.cpp +++ b/pcbnew/scripting/pcbnew_footprint_wizards.cpp @@ -63,25 +63,9 @@ PyObject* PYTHON_FOOTPRINT_WIZARD::CallMethod( const char* aMethod, PyObject* aA if( PyErr_Occurred() ) { - wxString message; - PyObject* t; - PyObject* v; - PyObject* b; - - PyErr_Fetch( &t, &v, &b ); - message.Printf( wxT( "calling %s()\n" - "Exception: %s\n" - " : %s\n" ), - FROM_UTF8( aMethod ).c_str(), - FROM_UTF8( PyString_AsString( PyObject_Str( v ) ) ).c_str(), - FROM_UTF8( PyString_AsString( PyObject_Str( b ) ) ).c_str() - ); - - wxMessageBox( message, + wxMessageBox( PyErrStringWithTraceback(), wxT( "Exception on python footprint wizard code" ), wxICON_ERROR | wxOK ); - - PyErr_Clear(); } if( result ) @@ -140,17 +124,7 @@ wxArrayString PYTHON_FOOTPRINT_WIZARD::CallRetArrayStrMethod( const char* aMet return ret; } - int list_size = PyList_Size( result ); - - for( int n = 0; n #include #include +#include /* init functions defined by swig */ @@ -62,11 +63,11 @@ static int SwigNumModules = 0; static void swigAddModule( const char* name, void (* initfunc)() ) { - SwigImportInittab[SwigNumModules].name = (char*) name; - SwigImportInittab[SwigNumModules].initfunc = initfunc; + SwigImportInittab[SwigNumModules].name = (char*) name; + SwigImportInittab[SwigNumModules].initfunc = initfunc; SwigNumModules++; - SwigImportInittab[SwigNumModules].name = (char*) 0; - SwigImportInittab[SwigNumModules].initfunc = 0; + SwigImportInittab[SwigNumModules].name = (char*) 0; + SwigImportInittab[SwigNumModules].initfunc = 0; } @@ -165,7 +166,7 @@ bool pcbnewInitPythonScripting() { PyLOCK lock; - PyRun_SimpleString( "import sys\n" + PyRun_SimpleString( "import sys, traceback\n" "sys.path.append(\".\")\n" "import pcbnew\n" "pcbnew.LoadPlugins()" @@ -198,7 +199,7 @@ void RedirectStdio() "output = wx.PyOnDemandOutputWindow()\n" "sys.stderr = output\n"; - PyLOCK lock; + PyLOCK lock; PyRun_SimpleString( python_redirect ); } @@ -295,3 +296,57 @@ wxWindow* CreatePythonShellWindow( wxWindow* parent ) #endif + +wxArrayString PyArrayStringToWx( PyObject* aArrayString ) +{ + wxArrayString ret; + + int list_size = PyList_Size( aArrayString ); + + for( int n = 0; n