diff --git a/pcbnew/pcbnew.cpp b/pcbnew/pcbnew.cpp index c46928c3f2..8405c2b0cd 100644 --- a/pcbnew/pcbnew.cpp +++ b/pcbnew/pcbnew.cpp @@ -59,6 +59,7 @@ #include <modview_frame.h> #include <footprint_wizard_frame.h> +extern bool IsWxPythonLoaded(); // Colors for layers and items COLORS_DESIGN_SETTINGS g_ColorsSettings; @@ -285,9 +286,11 @@ static bool scriptingSetup() path_frag = wxT( "/usr/local/kicad/bin/scripting/plugins" ); #endif - if( !pcbnewInitPythonScripting( TO_UTF8( path_frag ) ) ) + pcbnewInitPythonScripting( TO_UTF8( path_frag ) ); + + if( !IsWxPythonLoaded() ) { - wxLogSysError( wxT( "pcbnewInitPythonScripting() failed." ) ); + wxLogError( wxT( "pcbnewInitPythonScripting() failed." ) ); return false; } @@ -361,6 +364,7 @@ void IFACE::OnKifaceEnd() // wxPython will do its own cleanup as part of that process. // This should only be called if python was setup correctly. - pcbnewFinishPythonScripting(); + if( IsWxPythonLoaded() ) + pcbnewFinishPythonScripting(); #endif } diff --git a/pcbnew/tool_pcb.cpp b/pcbnew/tool_pcb.cpp index 0cb40d55ae..ab14265cf6 100644 --- a/pcbnew/tool_pcb.cpp +++ b/pcbnew/tool_pcb.cpp @@ -46,6 +46,8 @@ #include <wx/wupdlock.h> +extern bool IsWxPythonLoaded(); + #define SEL_LAYER_HELP _( \ "Show active layer selections\nand select layer pair for route and place via" ) @@ -303,12 +305,15 @@ void PCB_EDIT_FRAME::ReCreateHToolbar() // Access to the scripting console #if defined(KICAD_SCRIPTING_WXPYTHON) - m_mainToolBar->AddSeparator(); + if( IsWxPythonLoaded() ) + { + m_mainToolBar->AddSeparator(); - m_mainToolBar->AddTool( ID_TOOLBARH_PCB_SCRIPTING_CONSOLE, wxEmptyString, - KiBitmap( py_script_xpm ), - _( "Show/Hide the Python Scripting console" ), - wxITEM_CHECK ); + m_mainToolBar->AddTool( ID_TOOLBARH_PCB_SCRIPTING_CONSOLE, wxEmptyString, + KiBitmap( py_script_xpm ), + _( "Show/Hide the Python Scripting console" ), + wxITEM_CHECK ); + } #endif // after adding the buttons to the toolbar, must call Realize() to reflect the changes diff --git a/scripting/python_scripting.cpp b/scripting/python_scripting.cpp index 827ab304bc..859a4d8bb7 100644 --- a/scripting/python_scripting.cpp +++ b/scripting/python_scripting.cpp @@ -55,6 +55,13 @@ extern "C" void init_pcbnew( void ); struct _inittab* SwigImportInittab; static int SwigNumModules = 0; +static bool wxPythonLoaded = false; // true if the wxPython scripting layer was successfully loaded + +bool IsWxPythonLoaded() +{ + return wxPythonLoaded; +} + /* Add a name + initfuction to our SwigImportInittab */ @@ -140,11 +147,12 @@ bool pcbnewInitPythonScripting( const char * aUserPluginsPath ) #ifdef KICAD_SCRIPTING_WXPYTHON PyEval_InitThreads(); +#ifndef __WINDOWS__ // import wxversion.py currently not working under winbuilder, and not useful. char cmd[1024]; // Make sure that that the correct version of wxPython is loaded. In systems where there // are different versions of wxPython installed this can lead to select wrong wxPython // version being selected. - snprintf( cmd, sizeof(cmd), "import wxversion; wxversion.select('%s')", WXPYTHON_VERSION ); + snprintf( cmd, sizeof(cmd), "import wxversion; wxversion.select('%s')", WXPYTHON_VERSION ); int retv = PyRun_SimpleString( cmd ); @@ -155,6 +163,7 @@ bool pcbnewInitPythonScripting( const char * aUserPluginsPath ) Py_Finalize(); return false; } +#endif // ifndef __WINDOWS__ // Load the wxPython core API. Imports the wx._core_ module and sets a // local pointer to a function table located there. The pointer is used @@ -171,8 +180,8 @@ bool pcbnewInitPythonScripting( const char * aUserPluginsPath ) // Global Interpreter Lock. g_PythonMainTState = wxPyBeginAllowThreads(); +#endif // ifdef KICAD_SCRIPTING_WXPYTHON -#endif // load pcbnew inside python, and load all the user plugins, TODO: add system wide plugins { char cmd[1024];