30#include <python_scripting.h>
65 PyObject* builtins = PyImport_ImportModule(
"pcbnew" );
71 PyObject* globals = PyDict_New();
72 PyDict_SetItemString( globals,
"pcbnew", builtins );
73 Py_DECREF( builtins );
77 snprintf( cmd,
sizeof(cmd),
"result = %s()", aMethodName );
80 PyObject* localDict = PyDict_New();
81 PyObject* pobj = PyRun_String( cmd, Py_file_input, globals, localDict);
86 PyObject* str = PyDict_GetItemString(localDict,
"result" );
87 const char* str_res =
nullptr;
91 PyObject* temp_bytes = PyUnicode_AsEncodedString( str,
"UTF-8",
"strict" );
93 if( temp_bytes !=
nullptr )
95 str_res = PyBytes_AS_STRING( temp_bytes );
97 Py_DECREF( temp_bytes );
101 wxLogMessage( wxS(
"cannot encode Unicode python string" ) );
112 Py_DECREF( localDict );
114 if( PyErr_Occurred() )
116 if( strcmp( aMethodName,
"pcbnew.GetWizardsBackTrace" ) == 0 )
117 aNames = PyErrStringWithTraceback();
119 wxLogMessage( PyErrStringWithTraceback() );
143 wxArrayString traces;
149 for(
unsigned ii = 0; ii < traces.Count(); ++ii )
151 if( traces[ii].Contains( wxT(
"Traceback" ) ) )
155 if( !aTrace.IsEmpty() )
156 aTrace << wxT(
"\n**********************************\n" );
160 aTrace += traces[ii] + wxT(
"\n" );
Base window classes and related definitions.
This file contains miscellaneous commonly used macros and functions.
void pcbnewGetUnloadableScriptNames(wxString &aNames)
Collect the list of python scripts which could not be loaded.
void pcbnewGetScriptsSearchPaths(wxString &aNames)
Collect the list of paths where python scripts are searched.
static void pcbnewRunPythonMethodWithReturnedString(const char *aMethodName, wxString &aNames)
Run a python method from the pcbnew module.
void pcbnewGetWizardsBackTrace(wxString &aTrace)
Return the backtrace of errors (if any) when wizard python scripts are loaded.
wxString From_UTF8(const char *cstring)
void wxStringSplit(const wxString &aText, wxArrayString &aStrings, wxChar aSplitter)
Split aString to a string list separated at aSplitter.
wxLogTrace helper definitions.