From 0a044656e3243c9b43ad69781033029d7f0d1d09 Mon Sep 17 00:00:00 2001 From: Jon Evans Date: Mon, 2 Jan 2023 11:52:05 -0500 Subject: [PATCH] Disable scripting and warn when wxPython version doesn't match --- scripting/python_scripting.cpp | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) 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;