KiCad PCB EDA Suite
python_scripting.cpp File Reference

methods to add scripting capabilities inside pcbnew More...

#include <cstdlib>
#include <cstring>
#include <python_scripting.h>
#include <sstream>
#include <eda_base_frame.h>
#include <gal/color4d.h>
#include <trace_helpers.h>
#include <kicad_string.h>
#include <macros.h>
#include <paths.h>
#include <pgm_base.h>
#include <settings/settings_manager.h>
#include <kiplatform/environment.h>
#include <wx/app.h>
#include <config.h>

Go to the source code of this file.

Macros

#define EXTRA_PYTHON_MODULES   10
 

Functions

void init_kicad (void)
 
void init_pcbnew (void)
 
bool IsWxPythonLoaded ()
 
static void swigAddModule (const char *name, void(*initfunc)())
 Add a name + initfuction to our SwigImportInittab. More...
 
static void swigAddBuiltin ()
 Add the builtin python modules. More...
 
static void swigAddModules ()
 Add the internal modules to the python scripting so they will be available to the scripts. More...
 
static void swigSwitchPythonBuiltin ()
 Switch the python module table to the Pcbnew built one. More...
 
bool pcbnewInitPythonScripting (const char *aStockScriptingPath, const char *aUserScriptingPath)
 Initialize the python environment and publish the Pcbnew interface inside it. More...
 
static void pcbnewRunPythonMethodWithReturnedString (const char *aMethodName, wxString &aNames)
 Run a python method from the pcbnew module. More...
 
void pcbnewGetUnloadableScriptNames (wxString &aNames)
 Collect the list of python scripts which could not be loaded. More...
 
void pcbnewGetScriptsSearchPaths (wxString &aNames)
 Collect the list of paths where python scripts are searched. More...
 
void pcbnewGetWizardsBackTrace (wxString &aTrace)
 Return the backtrace of errors (if any) when wizard python scripts are loaded. More...
 
void pcbnewFinishPythonScripting ()
 
wxString PyEscapeString (const wxString &aSource)
 
void pcbnewUpdatePythonEnvVar (const wxString &aVar, const wxString &aValue)
 Set an environment variable in the current Python interpreter. More...
 
wxString PyStringToWx (PyObject *aString)
 
wxArrayString PyArrayStringToWx (PyObject *aArrayString)
 
wxString PyErrStringWithTraceback ()
 
wxString PyScriptingPath (bool aUserPath)
 Find the Python scripting path. More...
 
wxString PyPluginsPath (bool aUserPath)
 

Variables

struct _inittab * SwigImportInittab
 
static int SwigNumModules = 0
 
static bool wxPythonLoaded = false
 True if the wxPython scripting layer was successfully loaded. More...
 
PyThreadState * g_PythonMainTState
 

Detailed Description

methods to add scripting capabilities inside pcbnew

Definition in file python_scripting.cpp.

Macro Definition Documentation

◆ EXTRA_PYTHON_MODULES

#define EXTRA_PYTHON_MODULES   10

Definition at line 61 of file python_scripting.cpp.

Function Documentation

◆ init_kicad()

void init_kicad ( void  )

◆ init_pcbnew()

void init_pcbnew ( void  )

Referenced by swigAddModules().

◆ IsWxPythonLoaded()

bool IsWxPythonLoaded ( )

Definition at line 77 of file python_scripting.cpp.

78 {
79  return wxPythonLoaded;
80 }
static bool wxPythonLoaded
True if the wxPython scripting layer was successfully loaded.

References wxPythonLoaded.

Referenced by PCB::IFACE::OnKifaceEnd(), PCB_EDIT_FRAME::ReCreateHToolbar(), and PCB_EDIT_FRAME::setupUIConditions().

◆ pcbnewFinishPythonScripting()

void pcbnewFinishPythonScripting ( )

Definition at line 365 of file python_scripting.cpp.

366 {
367 #ifdef KICAD_SCRIPTING_WXPYTHON
368  PyEval_RestoreThread( g_PythonMainTState );
369 #endif
370  Py_Finalize();
371 }
PyThreadState * g_PythonMainTState

References g_PythonMainTState.

Referenced by PCB::IFACE::OnKifaceEnd().

◆ pcbnewGetScriptsSearchPaths()

void pcbnewGetScriptsSearchPaths ( wxString &  aNames)

Collect the list of paths where python scripts are searched.

Parameters
aNamesis a wxString which will contain the paths (separated by '
')

Definition at line 331 of file python_scripting.cpp.

332 {
333  pcbnewRunPythonMethodWithReturnedString( "pcbnew.GetWizardsSearchPaths", aNames );
334 }
static void pcbnewRunPythonMethodWithReturnedString(const char *aMethodName, wxString &aNames)
Run a python method from the pcbnew module.

References pcbnewRunPythonMethodWithReturnedString().

◆ pcbnewGetUnloadableScriptNames()

void pcbnewGetUnloadableScriptNames ( wxString &  aNames)

Collect the list of python scripts which could not be loaded.

Parameters
aNamesis a wxString which will contain the filenames (separated by '
')

Definition at line 325 of file python_scripting.cpp.

326 {
327  pcbnewRunPythonMethodWithReturnedString( "pcbnew.GetUnLoadableWizards", aNames );
328 }
static void pcbnewRunPythonMethodWithReturnedString(const char *aMethodName, wxString &aNames)
Run a python method from the pcbnew module.

References pcbnewRunPythonMethodWithReturnedString().

◆ pcbnewGetWizardsBackTrace()

void pcbnewGetWizardsBackTrace ( wxString &  aNames)

Return the backtrace of errors (if any) when wizard python scripts are loaded.

Parameters
aNamesis a wxString which will contain the trace

Definition at line 337 of file python_scripting.cpp.

338 {
339  pcbnewRunPythonMethodWithReturnedString( "pcbnew.GetWizardsBackTrace", aTrace );
340 
341  // Filter message before displaying them
342  // a trace starts by "Traceback" and is followed by 2 useless lines
343  // for our purpose
344  wxArrayString traces;
345  wxStringSplit( aTrace, traces, '\n' );
346 
347  // Build the filtered message (remove useless lines)
348  aTrace.Clear();
349 
350  for( unsigned ii = 0; ii < traces.Count(); ++ii )
351  {
352  if( traces[ii].Contains( "Traceback" ) )
353  {
354  ii += 2; // Skip this line and next lines which are related to pcbnew.py module
355 
356  if( !aTrace.IsEmpty() ) // Add separator for the next trace block
357  aTrace << "\n**********************************\n";
358  }
359  else
360  aTrace += traces[ii] + "\n";
361  }
362 }
static void pcbnewRunPythonMethodWithReturnedString(const char *aMethodName, wxString &aNames)
Run a python method from the pcbnew module.
void wxStringSplit(const wxString &aText, wxArrayString &aStrings, wxChar aSplitter)
Split aString to a string list separated at aSplitter.
Definition: string.cpp:827

References pcbnewRunPythonMethodWithReturnedString(), and wxStringSplit().

◆ pcbnewInitPythonScripting()

bool pcbnewInitPythonScripting ( const char *  aStockScriptingPath,
const char *  aUserScriptingPath 
)

Initialize the python environment and publish the Pcbnew interface inside it.

Initialize the Python engine inside pcbnew.

This initializes all the wxPython interface and returns the python thread control structure

Definition at line 162 of file python_scripting.cpp.

163 {
164  int retv;
165  char cmd[1024];
166 
167  swigAddBuiltin(); // add builtin functions
168  swigAddModules(); // add our own modules
169  swigSwitchPythonBuiltin(); // switch the python builtin modules to our new list
170 
171 #ifdef _MSC_VER
172  // Under vcpkg/msvc, we need to explicitly set the python home
173  // or else it'll start consuming system python registry keys and the like instead
174  // We are going to follow the "unix" layout for the msvc/vcpkg distributions so exes in /root/bin
175  // And the python lib in /root/lib/python3(/Lib,/DLLs)
176  wxFileName pyHome;
177 
178  pyHome.Assign( Pgm().GetExecutablePath() );
179 
180  pyHome.Normalize();
181 
182  // MUST be called before Py_Initialize so it will to create valid default lib paths
183  if( !wxGetEnv( wxT( "KICAD_RUN_FROM_BUILD_DIR" ), nullptr ) )
184  {
185  Py_SetPythonHome( pyHome.GetFullPath().c_str() );
186  }
187 #endif
188 
189  Py_Initialize();
190  PySys_SetArgv( Pgm().App().argc, Pgm().App().argv );
191 
192 #ifdef KICAD_SCRIPTING_WXPYTHON
193 
194 #if PY_VERSION_HEX < 0x03070000 // PyEval_InitThreads() is called by Py_Initialize() starting with version 3.7
195  PyEval_InitThreads();
196 #endif // if PY_VERSION_HEX < 0x03070000
197 
198 #ifndef KICAD_SCRIPTING_WXPYTHON_PHOENIX
199 #ifndef __WINDOWS__ // import wxversion.py currently not working under winbuilder, and not useful.
200  // Make sure that that the correct version of wxPython is loaded. In systems where there
201  // are different versions of wxPython installed this can lead to select wrong wxPython
202  // version being selected.
203  snprintf( cmd, sizeof( cmd ), "import wxversion; wxversion.select( '%s' )", WXPYTHON_VERSION );
204 
205  retv = PyRun_SimpleString( cmd );
206 
207  if( retv != 0 )
208  {
209  wxLogError( "Python error %d occurred running command:\n\n`%s`", retv, cmd );
210  return false;
211  }
212 #endif // ifndef __WINDOWS__
213 
214  // Load the wxPython core API. Imports the wx._core_ module and sets a
215  // local pointer to a function table located there. The pointer is used
216  // internally by the rest of the API functions.
217  if( !wxPyCoreAPI_IMPORT() )
218  {
219  wxLogError( "***** Error importing the wxPython API! *****" );
220  PyErr_Print();
221  Py_Finalize();
222  return false;
223  }
224 #endif // ifndef KICAD_SCRIPTING_WXPYTHON_PHOENIX
225 
226 #if defined( DEBUG )
227  RedirectStdio();
228 #endif
229 
230  wxPythonLoaded = true;
231 
232  // Save the current Python thread state and release the
233  // Global Interpreter Lock.
234  g_PythonMainTState = PyEval_SaveThread();
235 
236 #endif // ifdef KICAD_SCRIPTING_WXPYTHON
237 
238  // Load pcbnew inside Python and load all the user plugins and package-based plugins
239  {
240  PyLOCK lock;
241 
242  // Load os so that we can modify the environment variables through python
243  snprintf( cmd, sizeof( cmd ), "import sys, os, traceback\n"
244  "sys.path.append(\".\")\n"
245  "import pcbnew\n"
246  "pcbnew.LoadPlugins(\"%s\", \"%s\")",
247  aStockScriptingPath, aUserScriptingPath );
248  retv = PyRun_SimpleString( cmd );
249 
250  if( retv != 0 )
251  wxLogError( "Python error %d occurred running command:\n\n`%s`", retv, cmd );
252  }
253 
254  return true;
255 }
static void swigAddBuiltin()
Add the builtin python modules.
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Definition: single_top.cpp:106
static void swigAddModules()
Add the internal modules to the python scripting so they will be available to the scripts.
static void swigSwitchPythonBuiltin()
Switch the python module table to the Pcbnew built one.
static bool wxPythonLoaded
True if the wxPython scripting layer was successfully loaded.
PyThreadState * g_PythonMainTState

References g_PythonMainTState, Pgm(), swigAddBuiltin(), swigAddModules(), swigSwitchPythonBuiltin(), and wxPythonLoaded.

◆ pcbnewRunPythonMethodWithReturnedString()

static void pcbnewRunPythonMethodWithReturnedString ( const char *  aMethodName,
wxString &  aNames 
)
static

Run a python method from the pcbnew module.

Parameters
aMethodNameis the name of the method (like "pcbnew.myfunction" )
aNameswill contain the returned string

Definition at line 264 of file python_scripting.cpp.

265 {
266  aNames.Clear();
267 
268  PyLOCK lock;
269  PyErr_Clear();
270 
271  PyObject* builtins = PyImport_ImportModule( "pcbnew" );
272  wxASSERT( builtins );
273 
274  if( !builtins ) // Something is wrong in pcbnew.py module (incorrect version?)
275  return;
276 
277  PyObject* globals = PyDict_New();
278  PyDict_SetItemString( globals, "pcbnew", builtins );
279  Py_DECREF( builtins );
280 
281  // Build the python code
282  char cmd[1024];
283  snprintf( cmd, sizeof(cmd), "result = %s()", aMethodName );
284 
285  // Execute the python code and get the returned data
286  PyObject* localDict = PyDict_New();
287  PyObject* pobj = PyRun_String( cmd, Py_file_input, globals, localDict);
288  Py_DECREF( globals );
289 
290  if( pobj )
291  {
292  PyObject* str = PyDict_GetItemString(localDict, "result" );
293 #if PY_MAJOR_VERSION >= 3
294  const char* str_res = NULL;
295 
296  if(str)
297  {
298  PyObject* temp_bytes = PyUnicode_AsEncodedString( str, "UTF-8", "strict" );
299 
300  if( temp_bytes != NULL )
301  {
302  str_res = PyBytes_AS_STRING( temp_bytes );
303  str_res = strdup( str_res );
304  Py_DECREF( temp_bytes );
305  }
306  else
307  {
308  wxLogMessage( "cannot encode unicode python string" );
309  }
310  }
311 #else
312  const char* str_res = str ? PyString_AsString( str ) : 0;
313 #endif
314  aNames = FROM_UTF8( str_res );
315  Py_DECREF( pobj );
316  }
317 
318  Py_DECREF( localDict );
319 
320  if( PyErr_Occurred() )
321  wxLogMessage( PyErrStringWithTraceback() );
322 }
static wxString FROM_UTF8(const char *cstring)
Convert a UTF8 encoded C string to a wxString for all wxWidgets build modes.
Definition: macros.h:110
#define NULL
wxString PyErrStringWithTraceback()

References FROM_UTF8(), NULL, and PyErrStringWithTraceback().

Referenced by pcbnewGetScriptsSearchPaths(), pcbnewGetUnloadableScriptNames(), and pcbnewGetWizardsBackTrace().

◆ pcbnewUpdatePythonEnvVar()

void pcbnewUpdatePythonEnvVar ( const wxString &  aVar,
const wxString &  aValue 
)

Set an environment variable in the current Python interpreter.

Parameters
aVaris the variable to set
aValueis the value to give it

Definition at line 394 of file python_scripting.cpp.

395 {
396  char cmd[1024];
397 
398  // Ensure the interpreter is initalized before we try to interact with it
399  if( !Py_IsInitialized() )
400  return;
401 
402  wxLogTrace( traceEnvVars, "pcbnewUpdatePythonEnvVar: Updating Python variable %s = %s",
403  aVar, aValue );
404 
405  wxString escapedVar = PyEscapeString( aVar );
406  wxString escapedVal = PyEscapeString( aValue );
407 
408  snprintf( cmd, sizeof( cmd ),
409  "# coding=utf-8\n" // The values could potentially be UTF8
410  "os.environ[\"%s\"]=\"%s\"\n",
411  TO_UTF8( escapedVar ),
412  TO_UTF8( escapedVal ) );
413 
414  PyLOCK lock;
415 
416  int retv = PyRun_SimpleString( cmd );
417 
418  if( retv != 0 )
419  wxLogError( "Python error %d occurred running command:\n\n`%s`", retv, cmd );
420 }
#define TO_UTF8(wxstring)
Convert a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Definition: macros.h:96
const wxChar *const traceEnvVars
Flag to enable debug output of environment variable operations.
wxString PyEscapeString(const wxString &aSource)

References PyEscapeString(), TO_UTF8, and traceEnvVars.

Referenced by PCB_EDIT_FRAME::PythonSyncEnvironmentVariables(), and PCB_EDIT_FRAME::PythonSyncProjectName().

◆ PyArrayStringToWx()

wxArrayString PyArrayStringToWx ( PyObject *  aArrayString)

Definition at line 572 of file python_scripting.cpp.

573 {
574  wxArrayString ret;
575 
576  if( !aArrayString )
577  return ret;
578 
579  int list_size = PyList_Size( aArrayString );
580 
581  for( int n = 0; n < list_size; n++ )
582  {
583  PyObject* element = PyList_GetItem( aArrayString, n );
584 
585  if( element )
586  {
587 #if PY_MAJOR_VERSION >= 3
588  const char* str_res = NULL;
589  PyObject* temp_bytes = PyUnicode_AsEncodedString( element, "UTF-8", "strict" );
590 
591  if( temp_bytes != NULL )
592  {
593  str_res = PyBytes_AS_STRING( temp_bytes );
594  ret.Add( FROM_UTF8( str_res ), 1 );
595  Py_DECREF( temp_bytes );
596  }
597  else
598  {
599  wxLogMessage( "cannot encode unicode python string" );
600  }
601 #else
602  ret.Add( FROM_UTF8( PyString_AsString( element ) ), 1 );
603 #endif
604  }
605  }
606 
607  return ret;
608 }
static wxString FROM_UTF8(const char *cstring)
Convert a UTF8 encoded C string to a wxString for all wxWidgets build modes.
Definition: macros.h:110
#define NULL

References FROM_UTF8(), and NULL.

Referenced by PYTHON_FOOTPRINT_WIZARD::CallRetArrayStrMethod(), and PyErrStringWithTraceback().

◆ PyErrStringWithTraceback()

wxString PyErrStringWithTraceback ( )

Definition at line 611 of file python_scripting.cpp.

612 {
613  wxString err;
614 
615  if( !PyErr_Occurred() )
616  return err;
617 
618  PyObject* type;
619  PyObject* value;
620  PyObject* traceback;
621 
622  PyErr_Fetch( &type, &value, &traceback );
623 
624  PyErr_NormalizeException( &type, &value, &traceback );
625 
626  if( traceback == NULL )
627  {
628  traceback = Py_None;
629  Py_INCREF( traceback );
630  }
631 
632 #if PY_MAJOR_VERSION >= 3
633  PyException_SetTraceback( value, traceback );
634 
635  PyObject* tracebackModuleString = PyUnicode_FromString( "traceback" );
636 #else
637  PyObject* tracebackModuleString = PyString_FromString( "traceback" );
638 #endif
639  PyObject* tracebackModule = PyImport_Import( tracebackModuleString );
640  Py_DECREF( tracebackModuleString );
641 
642  PyObject* formatException = PyObject_GetAttrString( tracebackModule,
643  "format_exception" );
644  Py_DECREF( tracebackModule );
645 
646  PyObject* args = Py_BuildValue( "(O,O,O)", type, value, traceback );
647  PyObject* result = PyObject_CallObject( formatException, args );
648  Py_XDECREF( formatException );
649  Py_XDECREF( args );
650  Py_XDECREF( type );
651  Py_XDECREF( value );
652  Py_XDECREF( traceback );
653 
654  wxArrayString res = PyArrayStringToWx( result );
655 
656  for( unsigned i = 0; i<res.Count(); i++ )
657  {
658  err += res[i] + wxT( "\n" );
659  }
660 
661  PyErr_Clear();
662 
663  return err;
664 }
#define NULL
wxArrayString PyArrayStringToWx(PyObject *aArrayString)

References NULL, and PyArrayStringToWx().

Referenced by PYTHON_ACTION_PLUGIN::CallMethod(), PYTHON_FOOTPRINT_WIZARD::CallMethod(), and pcbnewRunPythonMethodWithReturnedString().

◆ PyEscapeString()

wxString PyEscapeString ( const wxString &  aSource)

Definition at line 374 of file python_scripting.cpp.

375 {
376  wxString converted;
377 
378  for( wxUniChar c: aSource )
379  {
380  if( c == '\\' )
381  converted += "\\\\";
382  else if( c == '\'' )
383  converted += "\\\'";
384  else if( c == '\"' )
385  converted += "\\\"";
386  else
387  converted += c;
388  }
389 
390  return converted;
391 }

Referenced by pcbnewUpdatePythonEnvVar().

◆ PyPluginsPath()

wxString PyPluginsPath ( bool  aUserPath)

Definition at line 697 of file python_scripting.cpp.

698 {
699  // Note we are using unix path separator, because window separator sometimes
700  // creates issues when passing a command string to a python method by PyRun_SimpleString
701  return PyScriptingPath( aUserPath ) + '/' + "plugins";
702 }
wxString PyScriptingPath(bool aUserPath)
Find the Python scripting path.

References PyScriptingPath().

Referenced by PCB_EDIT_FRAME::PythonPluginsShowFolder().

◆ PyScriptingPath()

wxString PyScriptingPath ( bool  aUserPath)

Find the Python scripting path.

Definition at line 670 of file python_scripting.cpp.

671 {
672  wxString path;
673 
674  //@todo This should this be a user configurable variable eg KISCRIPT?
675  if( aUserPath )
676  {
678  }
679  else
680  {
682  }
683 
684  wxFileName scriptPath( path );
685  scriptPath.MakeAbsolute();
686 
687  // Convert '\' to '/' in path, because later python script read \n or \r
688  // as escaped sequence, and create issues, when calling it by PyRun_SimpleString() method.
689  // It can happen on Windows.
690  path = scriptPath.GetFullPath();
691  path.Replace( '\\', '/' );
692 
693  return path;
694 }
static wxString GetUserScriptingPath()
Gets the user path for python scripts.
Definition: paths.cpp:75
static wxString GetStockScriptingPath()
Gets the stock (install) scripting path.
Definition: paths.cpp:181

References PATHS::GetStockScriptingPath(), PATHS::GetUserScriptingPath(), and path.

Referenced by PyPluginsPath(), and PythonPluginsReloadBase().

◆ PyStringToWx()

wxString PyStringToWx ( PyObject *  aString)

Definition at line 542 of file python_scripting.cpp.

543 {
544  wxString ret;
545 
546  if( !aString )
547  return ret;
548 
549 #if PY_MAJOR_VERSION >= 3
550  const char* str_res = NULL;
551  PyObject* temp_bytes = PyUnicode_AsEncodedString( aString, "UTF-8", "strict" );
552 
553  if( temp_bytes != NULL )
554  {
555  str_res = PyBytes_AS_STRING( temp_bytes );
556  ret = FROM_UTF8( str_res );
557  Py_DECREF( temp_bytes );
558  }
559  else
560  {
561  wxLogMessage( "cannot encode unicode python string" );
562  }
563 #else
564  const char* str_res = PyString_AsString( aString );
565  ret = FROM_UTF8( str_res );
566 #endif
567 
568  return ret;
569 }
static wxString FROM_UTF8(const char *cstring)
Convert a UTF8 encoded C string to a wxString for all wxWidgets build modes.
Definition: macros.h:110
#define NULL

References FROM_UTF8(), and NULL.

Referenced by PYTHON_ACTION_PLUGIN::CallRetStrMethod(), PYTHON_FOOTPRINT_WIZARD::CallRetStrMethod(), and PYTHON_FOOTPRINT_WIZARD::GetParameterPageName().

◆ swigAddBuiltin()

static void swigAddBuiltin ( )
static

Add the builtin python modules.

Definition at line 104 of file python_scripting.cpp.

105 {
106  int i = 0;
107 
108  /* discover the length of the pyimport inittab */
109  while( PyImport_Inittab[i].name )
110  i++;
111 
112  /* allocate memory for the python module table */
113  SwigImportInittab = (struct _inittab*) malloc(
114  sizeof( struct _inittab ) * ( i + EXTRA_PYTHON_MODULES ) );
115 
116  /* copy all pre-existing python modules into our newly created table */
117  i = 0;
118 
119  while( PyImport_Inittab[i].name )
120  {
121  swigAddModule( PyImport_Inittab[i].name, PyImport_Inittab[i].initfunc );
122  i++;
123  }
124 }
#define EXTRA_PYTHON_MODULES
static void swigAddModule(const char *name, void(*initfunc)())
Add a name + initfuction to our SwigImportInittab.
const char * name
Definition: DXF_plotter.cpp:59
struct _inittab * SwigImportInittab

References EXTRA_PYTHON_MODULES, name, swigAddModule(), and SwigImportInittab.

Referenced by pcbnewInitPythonScripting().

◆ swigAddModule()

static void swigAddModule ( const char *  name,
void(*)()  initfunc 
)
static

Add a name + initfuction to our SwigImportInittab.

Definition at line 90 of file python_scripting.cpp.

92 {
93  SwigImportInittab[SwigNumModules].name = (char*) name;
94  SwigImportInittab[SwigNumModules].initfunc = initfunc;
96  SwigImportInittab[SwigNumModules].name = (char*) 0;
97  SwigImportInittab[SwigNumModules].initfunc = 0;
98 }
const char * name
Definition: DXF_plotter.cpp:59
struct _inittab * SwigImportInittab
static int SwigNumModules

References name, SwigImportInittab, and SwigNumModules.

Referenced by swigAddBuiltin(), and swigAddModules().

◆ swigAddModules()

static void swigAddModules ( )
static

Add the internal modules to the python scripting so they will be available to the scripts.

Definition at line 130 of file python_scripting.cpp.

131 {
132 #if PY_MAJOR_VERSION >= 3
133  swigAddModule( "_pcbnew", PyInit__pcbnew );
134 #else
135  swigAddModule( "_pcbnew", init_pcbnew );
136 #endif
137 
138  // finally it seems better to include all in just one module
139  // but in case we needed to include any other modules,
140  // it must be done like this:
141  // swigAddModule( "_kicad", init_kicad );
142 }
static void swigAddModule(const char *name, void(*initfunc)())
Add a name + initfuction to our SwigImportInittab.
void init_pcbnew(void)

References init_pcbnew(), and swigAddModule().

Referenced by pcbnewInitPythonScripting().

◆ swigSwitchPythonBuiltin()

static void swigSwitchPythonBuiltin ( )
static

Switch the python module table to the Pcbnew built one.

Definition at line 148 of file python_scripting.cpp.

149 {
150  PyImport_Inittab = SwigImportInittab;
151 }
struct _inittab * SwigImportInittab

References SwigImportInittab.

Referenced by pcbnewInitPythonScripting().

Variable Documentation

◆ g_PythonMainTState

PyThreadState* g_PythonMainTState

Definition at line 154 of file python_scripting.cpp.

Referenced by pcbnewFinishPythonScripting(), and pcbnewInitPythonScripting().

◆ SwigImportInittab

struct _inittab* SwigImportInittab

Definition at line 70 of file python_scripting.cpp.

Referenced by swigAddBuiltin(), swigAddModule(), and swigSwitchPythonBuiltin().

◆ SwigNumModules

int SwigNumModules = 0
static

Definition at line 71 of file python_scripting.cpp.

Referenced by swigAddModule().

◆ wxPythonLoaded

bool wxPythonLoaded = false
static

True if the wxPython scripting layer was successfully loaded.

Definition at line 74 of file python_scripting.cpp.

Referenced by IsWxPythonLoaded(), and pcbnewInitPythonScripting().