From 8b060799ebcde69dab29565ca5dd63d36c6ac87b Mon Sep 17 00:00:00 2001 From: Seth Hillbrand Date: Thu, 24 Jan 2019 19:36:05 -0800 Subject: [PATCH] python: Fix Phoenix app setting Phoenix doesn't have the same initialization as wxpython3 and so the namespace doesn't get the wxApp() initialized to the existing instance. In python, this is worked around by starting a new wxApp. Unfortunately, this appears to overwrite the existing global instance variable. The issue _appears_ to be in Phoenix but for now we work around it by saving and resetting the instance pointer in the main app. The downside is that Python likely won't be able to respond to events from C++ Fixes: lp:1809913 * https://bugs.launchpad.net/kicad/+bug/1809913 --- pcbnew/swig/python_scripting.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/pcbnew/swig/python_scripting.cpp b/pcbnew/swig/python_scripting.cpp index 17c3ee083c..66aca2e78b 100644 --- a/pcbnew/swig/python_scripting.cpp +++ b/pcbnew/swig/python_scripting.cpp @@ -366,9 +366,16 @@ wxWindow* CreatePythonShellWindow( wxWindow* parent, const wxString& aFramenameI PyDict_SetItemString( globals, "__builtins__", builtins ); Py_DECREF( builtins ); + auto app_ptr = wxTheApp; // Execute the code to make the makeWindow function we defined above PyObject* result = PyRun_String( pcbnew_pyshell_one_step.str().c_str(), Py_file_input, globals, globals ); +#ifdef KICAD_SCRIPTING_WXPYTHON_PHOENIX + // This absolutely ugly hack is to work around the pyshell re-writing the global + // wxApp variable. Once we can initialize Phoenix to access the appropriate instance + // of wx, we can remove this line + wxApp::SetInstance( app_ptr ); +#endif // Was there an exception? if( !result ) {