From 5456ada1bd38a97bcdf5fcef04506d2d440021f7 Mon Sep 17 00:00:00 2001 From: jean-pierre charras Date: Fri, 1 Nov 2013 14:02:10 +0100 Subject: [PATCH] Pcbnew, compiled with python support: Under windows, force python environment, if the folder python27_us is found in Kicad bin folder (/bin, and if python27_us environment is not fully set (i.e. if python27_us is not in the path, or if PYTHONPATH id not defined.) --- pcbnew/pcbnew.cpp | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/pcbnew/pcbnew.cpp b/pcbnew/pcbnew.cpp index 76455bc614..2d9a50d654 100644 --- a/pcbnew/pcbnew.cpp +++ b/pcbnew/pcbnew.cpp @@ -114,6 +114,35 @@ bool EDA_APP::OnInit() #ifdef KICAD_SCRIPTING msg.Empty(); #ifdef __WINDOWS__ + // force python environment under Windows: + const wxString python_us("python27_us"); + + // Build our python path inside kicad + wxString kipython = m_BinDir + python_us; + + // If our python install is existing inside kicad, use it + if( wxDirExists( kipython ) ) + { + wxString ppath; + if( !wxGetEnv( wxT( "PYTHONPATH" ), &ppath ) || !ppath.Contains( python_us ) ) + { + ppath << kipython << wxT("/pylib;"); + ppath << kipython << wxT("/lib;"); + ppath << kipython << wxT("/dll"); + wxSetEnv( wxT( "PYTHONPATH" ), ppath ); + DBG( std::cout << "set PYTHONPATH to " << TO_UTF8(ppath) << "\n"; ) + + // Add python executable path: + wxGetEnv( wxT( "PATH" ), &ppath ); + if( !ppath.Contains( python_us ) ) + { + kipython << wxT(";") << ppath; + wxSetEnv( wxT( "PATH" ), kipython ); + DBG( std::cout << "set PATH to " << TO_UTF8(kipython) << "\n"; ) + } + } + } + // TODO: make this path definable by the user, and set more than one path // (and remove the fixed paths from /scripting/kicadplugins.i)