From 56f8e10eb472d06114b3564eaaae71a1fe875145 Mon Sep 17 00:00:00 2001 From: jean-pierre charras Date: Fri, 6 Jan 2017 20:15:23 +0100 Subject: [PATCH] Footprint wizards management: Now display the list of not loadable footprint wizards in footprint wizard dialog. Not loadable wizards are Python scripts having a syntax error or are not compatible scripts due to changes in API. --- .../dialogs/dialog_footprint_wizard_list.cpp | 11 + .../dialog_footprint_wizard_list_base.cpp | 18 +- .../dialog_footprint_wizard_list_base.fbp | 189 +++++++++++++++++- .../dialog_footprint_wizard_list_base.h | 11 +- pcbnew/pcbframe.cpp | 1 - pcbnew/swig/python_scripting.cpp | 67 +++++-- pcbnew/swig/python_scripting.h | 2 +- scripting/kicadplugins.i | 28 ++- 8 files changed, 299 insertions(+), 28 deletions(-) diff --git a/pcbnew/dialogs/dialog_footprint_wizard_list.cpp b/pcbnew/dialogs/dialog_footprint_wizard_list.cpp index 466d205057..951484a578 100644 --- a/pcbnew/dialogs/dialog_footprint_wizard_list.cpp +++ b/pcbnew/dialogs/dialog_footprint_wizard_list.cpp @@ -33,6 +33,7 @@ #include #include #include +#include enum FPGeneratorRowNames { @@ -75,6 +76,7 @@ DIALOG_FOOTPRINT_WIZARD_LIST::DIALOG_FOOTPRINT_WIZARD_LIST( wxWindow* aParent ) m_footprintGeneratorsGrid->SetCellValue( ii, FP_GEN_ROW_DESCR, description ); } + //wxLogMessage( KICAD_FAILED_PLUGINS ); m_footprintGeneratorsGrid->AutoSizeColumns(); @@ -98,6 +100,15 @@ DIALOG_FOOTPRINT_WIZARD_LIST::DIALOG_FOOTPRINT_WIZARD_LIST( wxWindow* aParent ) SetSize( size ); } + + wxString not_loaded_wiz_names; + pcbnewGetUnloadableScriptNames( not_loaded_wiz_names ); + + if( not_loaded_wiz_names.IsEmpty() ) + m_bsizerNotLoaded->Show( false ); + else + m_tcNotLoaded->SetValue( not_loaded_wiz_names ); + Center(); } diff --git a/pcbnew/dialogs/dialog_footprint_wizard_list_base.cpp b/pcbnew/dialogs/dialog_footprint_wizard_list_base.cpp index eb901b1978..eb5b9b15af 100644 --- a/pcbnew/dialogs/dialog_footprint_wizard_list_base.cpp +++ b/pcbnew/dialogs/dialog_footprint_wizard_list_base.cpp @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////////////// -// C++ code generated with wxFormBuilder (version May 6 2016) +// C++ code generated with wxFormBuilder (version Dec 4 2016) // http://www.wxformbuilder.org/ // // PLEASE DO "NOT" EDIT THIS FILE! @@ -11,7 +11,7 @@ DIALOG_FOOTPRINT_WIZARD_LIST_BASE::DIALOG_FOOTPRINT_WIZARD_LIST_BASE( wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style ) : DIALOG_SHIM( parent, id, title, pos, size, style ) { - this->SetSizeHints( wxSize( 400,200 ), wxDefaultSize ); + this->SetSizeHints( wxSize( 400,300 ), wxDefaultSize ); wxBoxSizer* bSizerMain; bSizerMain = new wxBoxSizer( wxVERTICAL ); @@ -50,6 +50,20 @@ DIALOG_FOOTPRINT_WIZARD_LIST_BASE::DIALOG_FOOTPRINT_WIZARD_LIST_BASE( wxWindow* bSizerMain->Add( m_footprintGeneratorsGrid, 1, wxALL|wxEXPAND, 5 ); + m_bsizerNotLoaded = new wxBoxSizer( wxVERTICAL ); + + m_staticText1 = new wxStaticText( this, wxID_ANY, _("Not loadable:"), wxDefaultPosition, wxDefaultSize, 0 ); + m_staticText1->Wrap( -1 ); + m_bsizerNotLoaded->Add( m_staticText1, 0, wxTOP|wxRIGHT|wxLEFT, 5 ); + + m_tcNotLoaded = new wxTextCtrl( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE|wxTE_READONLY ); + m_tcNotLoaded->SetMinSize( wxSize( -1,60 ) ); + + m_bsizerNotLoaded->Add( m_tcNotLoaded, 0, wxEXPAND|wxBOTTOM|wxRIGHT|wxLEFT, 5 ); + + + bSizerMain->Add( m_bsizerNotLoaded, 0, wxEXPAND, 5 ); + m_staticline = new wxStaticLine( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLI_HORIZONTAL ); bSizerMain->Add( m_staticline, 0, wxEXPAND | wxALL, 5 ); diff --git a/pcbnew/dialogs/dialog_footprint_wizard_list_base.fbp b/pcbnew/dialogs/dialog_footprint_wizard_list_base.fbp index a59028dd93..b0f5d085c6 100644 --- a/pcbnew/dialogs/dialog_footprint_wizard_list_base.fbp +++ b/pcbnew/dialogs/dialog_footprint_wizard_list_base.fbp @@ -41,10 +41,10 @@ 0 wxID_ANY - 400,200 + 400,300 DIALOG_FOOTPRINT_WIZARD_LIST_BASE - 554,286 + 597,339 wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER DIALOG_SHIM; dialog_shim.h Footprint Generators @@ -236,6 +236,191 @@ + + 5 + wxEXPAND + 0 + + + m_bsizerNotLoaded + wxVERTICAL + protected + + 5 + wxTOP|wxRIGHT|wxLEFT + 0 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + Not loadable: + + 0 + + + 0 + + 1 + m_staticText1 + 1 + + + protected + 1 + + Resizable + 1 + + + + 0 + + + + + -1 + + + + + + + + + + + + + + + + + + + + + + + + + + + 5 + wxEXPAND|wxBOTTOM|wxRIGHT|wxLEFT + 0 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + + 0 + + 0 + + 0 + -1,60 + 1 + m_tcNotLoaded + 1 + + + protected + 1 + + Resizable + 1 + + wxTE_MULTILINE|wxTE_READONLY + + 0 + + + wxFILTER_NONE + wxDefaultValidator + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 5 wxEXPAND | wxALL diff --git a/pcbnew/dialogs/dialog_footprint_wizard_list_base.h b/pcbnew/dialogs/dialog_footprint_wizard_list_base.h index c19ce02bbe..0d8b0be783 100644 --- a/pcbnew/dialogs/dialog_footprint_wizard_list_base.h +++ b/pcbnew/dialogs/dialog_footprint_wizard_list_base.h @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////////////// -// C++ code generated with wxFormBuilder (version May 6 2016) +// C++ code generated with wxFormBuilder (version Dec 4 2016) // http://www.wxformbuilder.org/ // // PLEASE DO "NOT" EDIT THIS FILE! @@ -20,8 +20,10 @@ class DIALOG_SHIM; #include #include #include -#include +#include +#include #include +#include #include #include @@ -37,6 +39,9 @@ class DIALOG_FOOTPRINT_WIZARD_LIST_BASE : public DIALOG_SHIM protected: wxGrid* m_footprintGeneratorsGrid; + wxBoxSizer* m_bsizerNotLoaded; + wxStaticText* m_staticText1; + wxTextCtrl* m_tcNotLoaded; wxStaticLine* m_staticline; wxStdDialogButtonSizer* m_sdbSizer; wxButton* m_sdbSizerOK; @@ -48,7 +53,7 @@ class DIALOG_FOOTPRINT_WIZARD_LIST_BASE : public DIALOG_SHIM public: - DIALOG_FOOTPRINT_WIZARD_LIST_BASE( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = _("Footprint Generators"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( 554,286 ), long style = wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER ); + DIALOG_FOOTPRINT_WIZARD_LIST_BASE( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = _("Footprint Generators"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( 597,339 ), long style = wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER ); ~DIALOG_FOOTPRINT_WIZARD_LIST_BASE(); }; diff --git a/pcbnew/pcbframe.cpp b/pcbnew/pcbframe.cpp index 9e16bd1143..819a9e8221 100644 --- a/pcbnew/pcbframe.cpp +++ b/pcbnew/pcbframe.cpp @@ -485,7 +485,6 @@ PCB_EDIT_FRAME::PCB_EDIT_FRAME( KIWAY* aKiway, wxWindow* aParent ) : if( !appK2S.FileExists() ) GetMenuBar()->FindItem( ID_GEN_EXPORT_FILE_STEP )->Enable( false ); - } diff --git a/pcbnew/swig/python_scripting.cpp b/pcbnew/swig/python_scripting.cpp index 814191b713..55eb85e01b 100644 --- a/pcbnew/swig/python_scripting.cpp +++ b/pcbnew/swig/python_scripting.cpp @@ -201,6 +201,37 @@ bool pcbnewInitPythonScripting( const char * aUserScriptingPath ) } +void pcbnewGetUnloadableScriptNames( wxString& aNames ) +{ + PyLOCK lock; + PyErr_Clear(); + + PyObject* globals = PyDict_New(); + PyObject* builtins = PyImport_ImportModule( "pcbnew" ); + PyDict_SetItemString( globals, "pcbnew", builtins ); + Py_DECREF( builtins ); + + // Execute the code and get the returned data + PyObject* localDict = PyDict_New(); + PyObject* pobj = PyRun_String( "result = pcbnew.GetUnLoadableWizards()", + Py_file_input, globals, localDict); + Py_DECREF( globals ); + + if( pobj ) + { + PyObject* str = PyDict_GetItemString(localDict, "result" ); + const char* str_res = str ? PyString_AsString( str ) : 0; + aNames = FROM_UTF8( str_res ); + Py_DECREF( pobj ); + } + + Py_DECREF( localDict ); + + if( PyErr_Occurred() ) + wxLogMessage(PyErrStringWithTraceback()); +} + + void pcbnewFinishPythonScripting() { #ifdef KICAD_SCRIPTING_WXPYTHON @@ -312,13 +343,17 @@ wxArrayString PyArrayStringToWx( PyObject* aArrayString ) { wxArrayString ret; - int list_size = PyList_Size( aArrayString ); + if( !aArrayString ) + return ret; - for( int n = 0; n