From b611da161eb978eeeaacc3d17c153f7d0a2aa5f5 Mon Sep 17 00:00:00 2001 From: Jon Evans Date: Wed, 23 Jun 2021 22:43:53 -0400 Subject: [PATCH] Ensure console can be loaded from Eeschema standalone PcbNew sets up the correct path as a side-effect of loading the action plugins. Fixes https://gitlab.com/kicad/code/kicad/-/issues/8661 --- scripting/kipython_frame.cpp | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/scripting/kipython_frame.cpp b/scripting/kipython_frame.cpp index 70361ae332..ca55df8720 100644 --- a/scripting/kipython_frame.cpp +++ b/scripting/kipython_frame.cpp @@ -32,6 +32,19 @@ void KIPYTHON_FRAME::SetupPythonEditor() { + using namespace pybind11::literals; + + // As always, first grab the GIL + PyLOCK lock; + + // Make sure the kicad_pyshell module is in the path + wxString sysPath = SCRIPTING::PyScriptingPath( false ); + auto locals = pybind11::dict( "stock_path"_a = sysPath.ToStdString() ); + + pybind11::exec( R"( +import sys +sys.path.append( stock_path ) + )", pybind11::globals(), locals ); // passing window ids instead of pointers is because wxPython is not // exposing the needed c++ apis to make that possible. @@ -39,9 +52,6 @@ void KIPYTHON_FRAME::SetupPythonEditor() pcbnew_pyshell_one_step << "import kicad_pyshell\n"; pcbnew_pyshell_one_step << "newshell = kicad_pyshell.makePcbnewShellWindow( " << GetId() << " )\n"; - // As always, first grab the GIL - PyLOCK lock; - // Execute the code to make the makeWindow function we defined above PyRun_SimpleString( pcbnew_pyshell_one_step.str().c_str() ); }