diff --git a/scripting/python_scripting.cpp b/scripting/python_scripting.cpp index a5b5a9fa48..2a4e255a23 100644 --- a/scripting/python_scripting.cpp +++ b/scripting/python_scripting.cpp @@ -50,6 +50,7 @@ #include #include +#include #include @@ -83,6 +84,39 @@ SCRIPTING::~SCRIPTING() bool SCRIPTING::IsWxAvailable() { #ifdef KICAD_SCRIPTING_WXPYTHON + PyLOCK lock; + using namespace pybind11::literals; + + pybind11::dict locals; + + pybind11::exec( R"( +from wx import version +wx_version = version() + )", pybind11::globals(), locals ); + + // e.g. "4.0.7 gtk3 (phoenix) wxWidgets 3.0.4" + wxString version( locals["wx_version"].cast().c_str(), wxConvUTF8 ); + + int idx = version.Find( wxT( "wxWidgets " ) ); + + if( idx == wxNOT_FOUND ) + { + wxLogError( wxT( "Could not determine wxPython version. " + "Python plugins will not be available." ) ); + return false; + } + + version = version.Mid( idx + 10 ); + wxString wxVersion = wxGetLibraryVersionInfo().GetVersionString(); + + if( wxVersion.Cmp( version ) != 0 ) + { + wxString msg = wxT( "The wxPython library was compiled against wxWidgets %s but KiCad is " + "using %s. Python plugins will not be available." ); + wxLogError( wxString::Format( msg, version, wxVersion ) ); + return false; + } + return true; #else return false;