Browse Source

Pcbnew: Fix a crash when reloading python scripts, when Kicad uses wxPython.

also, refresh the board editor action plugins menu, when reloading python scripts from the footprint wizard selector.
pull/3/merge
jean-pierre charras 9 years ago
parent
commit
a7c4c8c7f2
  1. 12
      include/wxPcbStruct.h
  2. 11
      pcbnew/dialogs/dialog_footprint_wizard_list.cpp
  3. 24
      pcbnew/footprint_wizard_frame.cpp
  4. 7
      pcbnew/footprint_wizard_frame.h
  5. 28
      pcbnew/pcbframe.cpp
  6. 11
      pcbnew/swig/pcbnew_action_plugins.cpp
  7. 6
      pcbnew/swig/python_scripting.h

12
include/wxPcbStruct.h

@ -139,9 +139,8 @@ protected:
void OnActionPluginRefresh( wxCommandEvent& aEvent);
#endif
// Has meaning only if DKICAD_SCRIPTING_WXPYTHON option is on
/**
/** Has meaning only if KICAD_SCRIPTING_WXPYTHON option is
* not defined
* @return the frame name identifier for the python console frame
*/
static const wxChar * pythonConsoleNameId()
@ -249,6 +248,13 @@ public:
void OnQuit( wxCommandEvent& event );
/**
* Reload the Python plugins if they are newer than
* the already loaded, and load new plugins if any
* Do nothing if KICAD_SCRIPTING is not defined
*/
void PythonPluginsReload();
/**
* Function GetAutoSaveFilePrefix
*

11
pcbnew/dialogs/dialog_footprint_wizard_list.cpp

@ -33,6 +33,7 @@
#include <kiface_i.h>
#include <dialog_footprint_wizard_list.h>
#include <class_footprint_wizard.h>
#include <footprint_wizard_frame.h>
#if defined(KICAD_SCRIPTING) || defined(KICAD_SCRIPTING_WXPYTHON)
#include <python_scripting.h>
@ -150,13 +151,9 @@ void DIALOG_FOOTPRINT_WIZARD_LIST::initLists()
void DIALOG_FOOTPRINT_WIZARD_LIST::onUpdatePythonModulesClick( wxCommandEvent& event )
{
#if defined(KICAD_SCRIPTING) || defined(KICAD_SCRIPTING_WXPYTHON)
char cmd[1024];
snprintf( cmd, sizeof(cmd),
"pcbnew.LoadPlugins(\"%s\")", TO_UTF8( PyScriptingPath() ) );
PyLOCK lock;
// ReRun the Python method pcbnew.LoadPlugins (already called when starting Pcbnew)
PyRun_SimpleString( cmd );
#if defined(KICAD_SCRIPTING)
FOOTPRINT_WIZARD_FRAME* fpw_frame = static_cast<FOOTPRINT_WIZARD_FRAME*>( GetParent() );
fpw_frame->PythonPluginsReload();
initLists();
#endif

24
pcbnew/footprint_wizard_frame.cpp

@ -720,6 +720,30 @@ void FOOTPRINT_WIZARD_FRAME::ReCreateVToolbar()
// Currently, there is no vertical toolbar
}
#if defined(KICAD_SCRIPTING)
#include <python_scripting.h>
void FOOTPRINT_WIZARD_FRAME::PythonPluginsReload()
{
// Reload the Python plugins
// Because the board editor has also a plugin python menu,
// call PCB_EDIT_FRAME::PythonPluginsReload() if the board editor
// is running
PCB_EDIT_FRAME* brd_frame =
static_cast<PCB_BASE_FRAME*>( Kiway().Player( FRAME_PCB, false ) );
if( brd_frame )
brd_frame->PythonPluginsReload();
else
{
char cmd[1024];
snprintf( cmd, sizeof(cmd),
"pcbnew.LoadPlugins(\"%s\")", TO_UTF8( PyScriptingPath() ) );
PyLOCK lock;
// ReRun the Python method pcbnew.LoadPlugins (already called when starting Pcbnew)
PyRun_SimpleString( cmd );
}
}
#endif
// frame to display messages from footprint builder scripts
FOOTPRINT_WIZARD_MESSAGES::FOOTPRINT_WIZARD_MESSAGES( FOOTPRINT_WIZARD_FRAME* aParent, wxConfigBase* aCfg ) :

7
pcbnew/footprint_wizard_frame.h

@ -74,6 +74,13 @@ public:
MODULE* GetBuiltFootprint();
/**
* Reload the Python plugins if they are newer than
* the already loaded, and load new plugins if any
* Do nothing if KICAD_SCRIPTING is not defined
*/
void PythonPluginsReload();
private:
void OnSize( wxSizeEvent& event ) override;

28
pcbnew/pcbframe.cpp

@ -1,10 +1,10 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2013 Jean-Pierre Charras, jp.charras at wanadoo.fr
* Copyright (C) 2017 Jean-Pierre Charras, jp.charras at wanadoo.fr
* Copyright (C) 2013 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
* Copyright (C) 2013-2016 Wayne Stambaugh <stambaughw@verizon.net>
* Copyright (C) 2013-2016 KiCad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 2013-2017 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@ -1056,7 +1056,6 @@ void PCB_EDIT_FRAME::ScriptingConsoleEnableDisable( wxCommandEvent& aEvent )
else
wxMessageBox( wxT( "Error: unable to create the Python Console" ) );
}
#endif
@ -1159,3 +1158,26 @@ void PCB_EDIT_FRAME::OnFlipPcbView( wxCommandEvent& evt )
view->RecacheAllItems();
Refresh();
}
void PCB_EDIT_FRAME::PythonPluginsReload()
{
// Reload plugin list: reload Python plugins if they are newer than
// the already loaded, and load new plugins
#if defined(KICAD_SCRIPTING)
//Reload plugin list: reload Python plugins if they are newer than
// the already loaded, and load new plugins
char cmd[1024];
snprintf( cmd, sizeof(cmd),
"pcbnew.LoadPlugins(\"%s\")", TO_UTF8( PyScriptingPath() ) );
PyLOCK lock;
// ReRun the Python method pcbnew.LoadPlugins (already called when starting Pcbnew)
PyRun_SimpleString( cmd );
#if defined(KICAD_SCRIPTING_ACTION_MENU)
RebuildActionPluginMenus();
#endif
#endif
}

11
pcbnew/swig/pcbnew_action_plugins.cpp

@ -199,16 +199,7 @@ void PCB_EDIT_FRAME::OnActionPlugin( wxCommandEvent& aEvent )
void PCB_EDIT_FRAME::OnActionPluginRefresh( wxCommandEvent& aEvent )
{
char cmd[1024];
snprintf( cmd, sizeof(cmd),
"pcbnew.LoadPlugins(\"%s\")", TO_UTF8( PyScriptingPath() ) );
PyLOCK lock;
// ReRun the Python method pcbnew.LoadPlugins (already called when starting Pcbnew)
PyRun_SimpleString( cmd );
RebuildActionPluginMenus();
PythonPluginsReload();
}

6
pcbnew/swig/python_scripting.h

@ -73,10 +73,14 @@ void pcbnewGetScriptsSearchPaths( wxString& aNames );
void pcbnewGetWizardsBackTrace( wxString& aNames );
#ifdef KICAD_SCRIPTING_WXPYTHON
void RedirectStdio();
wxWindow* CreatePythonShellWindow( wxWindow* parent, const wxString& aFramenameId );
#endif
#if 0 && defined (KICAD_SCRIPTING_WXPYTHON)
// This definition of PyLOCK crashed Pcbnew under some conditions (JPC),
// especially reloading plugins
class PyLOCK
{
wxPyBlock_t b;

Loading…
Cancel
Save