Remove the call to wxversion.py on winbuilder, because it does not work (not found, even when exists), ans it is not useful. Avoid crashes when wxPython scripting layer is not loaded, on kicad exit, and when trying to open the py console.

This commit is contained in:
jean-pierre charras 2015-07-09 18:44:23 +02:00
parent f0a1f6dd78
commit 01ae08a9a9
3 changed files with 28 additions and 10 deletions

View File

@ -59,6 +59,7 @@
#include <modview_frame.h> #include <modview_frame.h>
#include <footprint_wizard_frame.h> #include <footprint_wizard_frame.h>
extern bool IsWxPythonLoaded();
// Colors for layers and items // Colors for layers and items
COLORS_DESIGN_SETTINGS g_ColorsSettings; COLORS_DESIGN_SETTINGS g_ColorsSettings;
@ -285,9 +286,11 @@ static bool scriptingSetup()
path_frag = wxT( "/usr/local/kicad/bin/scripting/plugins" ); path_frag = wxT( "/usr/local/kicad/bin/scripting/plugins" );
#endif #endif
if( !pcbnewInitPythonScripting( TO_UTF8( path_frag ) ) ) pcbnewInitPythonScripting( TO_UTF8( path_frag ) );
if( !IsWxPythonLoaded() )
{ {
wxLogSysError( wxT( "pcbnewInitPythonScripting() failed." ) ); wxLogError( wxT( "pcbnewInitPythonScripting() failed." ) );
return false; return false;
} }
@ -361,6 +364,7 @@ void IFACE::OnKifaceEnd()
// wxPython will do its own cleanup as part of that process. // wxPython will do its own cleanup as part of that process.
// This should only be called if python was setup correctly. // This should only be called if python was setup correctly.
pcbnewFinishPythonScripting(); if( IsWxPythonLoaded() )
pcbnewFinishPythonScripting();
#endif #endif
} }

View File

@ -46,6 +46,8 @@
#include <wx/wupdlock.h> #include <wx/wupdlock.h>
extern bool IsWxPythonLoaded();
#define SEL_LAYER_HELP _( \ #define SEL_LAYER_HELP _( \
"Show active layer selections\nand select layer pair for route and place via" ) "Show active layer selections\nand select layer pair for route and place via" )
@ -303,12 +305,15 @@ void PCB_EDIT_FRAME::ReCreateHToolbar()
// Access to the scripting console // Access to the scripting console
#if defined(KICAD_SCRIPTING_WXPYTHON) #if defined(KICAD_SCRIPTING_WXPYTHON)
m_mainToolBar->AddSeparator(); if( IsWxPythonLoaded() )
{
m_mainToolBar->AddSeparator();
m_mainToolBar->AddTool( ID_TOOLBARH_PCB_SCRIPTING_CONSOLE, wxEmptyString, m_mainToolBar->AddTool( ID_TOOLBARH_PCB_SCRIPTING_CONSOLE, wxEmptyString,
KiBitmap( py_script_xpm ), KiBitmap( py_script_xpm ),
_( "Show/Hide the Python Scripting console" ), _( "Show/Hide the Python Scripting console" ),
wxITEM_CHECK ); wxITEM_CHECK );
}
#endif #endif
// after adding the buttons to the toolbar, must call Realize() to reflect the changes // after adding the buttons to the toolbar, must call Realize() to reflect the changes

View File

@ -55,6 +55,13 @@ extern "C" void init_pcbnew( void );
struct _inittab* SwigImportInittab; struct _inittab* SwigImportInittab;
static int SwigNumModules = 0; static int SwigNumModules = 0;
static bool wxPythonLoaded = false; // true if the wxPython scripting layer was successfully loaded
bool IsWxPythonLoaded()
{
return wxPythonLoaded;
}
/* Add a name + initfuction to our SwigImportInittab */ /* Add a name + initfuction to our SwigImportInittab */
@ -140,11 +147,12 @@ bool pcbnewInitPythonScripting( const char * aUserPluginsPath )
#ifdef KICAD_SCRIPTING_WXPYTHON #ifdef KICAD_SCRIPTING_WXPYTHON
PyEval_InitThreads(); PyEval_InitThreads();
#ifndef __WINDOWS__ // import wxversion.py currently not working under winbuilder, and not useful.
char cmd[1024]; char cmd[1024];
// Make sure that that the correct version of wxPython is loaded. In systems where there // Make sure that that the correct version of wxPython is loaded. In systems where there
// are different versions of wxPython installed this can lead to select wrong wxPython // are different versions of wxPython installed this can lead to select wrong wxPython
// version being selected. // version being selected.
snprintf( cmd, sizeof(cmd), "import wxversion; wxversion.select('%s')", WXPYTHON_VERSION ); snprintf( cmd, sizeof(cmd), "import wxversion; wxversion.select('%s')", WXPYTHON_VERSION );
int retv = PyRun_SimpleString( cmd ); int retv = PyRun_SimpleString( cmd );
@ -155,6 +163,7 @@ bool pcbnewInitPythonScripting( const char * aUserPluginsPath )
Py_Finalize(); Py_Finalize();
return false; return false;
} }
#endif // ifndef __WINDOWS__
// Load the wxPython core API. Imports the wx._core_ module and sets a // Load the wxPython core API. Imports the wx._core_ module and sets a
// local pointer to a function table located there. The pointer is used // local pointer to a function table located there. The pointer is used
@ -171,8 +180,8 @@ bool pcbnewInitPythonScripting( const char * aUserPluginsPath )
// Global Interpreter Lock. // Global Interpreter Lock.
g_PythonMainTState = wxPyBeginAllowThreads(); g_PythonMainTState = wxPyBeginAllowThreads();
#endif // ifdef KICAD_SCRIPTING_WXPYTHON
#endif
// load pcbnew inside python, and load all the user plugins, TODO: add system wide plugins // load pcbnew inside python, and load all the user plugins, TODO: add system wide plugins
{ {
char cmd[1024]; char cmd[1024];