dialog_footprint_wizard_list.cpp: allows updating (on request) python modules from this dialog.

This option reloads modules which are more recent than already loaded modules, and load new modules.
This commit is contained in:
jean-pierre charras 2017-01-09 14:44:07 +01:00
parent 9684031bc8
commit 4f46f79cf0
9 changed files with 260 additions and 85 deletions

View File

@ -76,6 +76,26 @@ int FOOTPRINT_WIZARDS::GetWizardsCount()
void FOOTPRINT_WIZARDS::register_wizard( FOOTPRINT_WIZARD* aWizard )
{
// Search for this entry do not register twice this wizard):
for( int ii = 0; ii < GetWizardsCount(); ii++ )
{
if( aWizard == GetWizard( ii ) ) // Already registered
return;
}
// Search for a wizard with the same name, and remove it if found
for( int ii = 0; ii < GetWizardsCount(); ii++ )
{
FOOTPRINT_WIZARD* wizard = GetWizard( ii );
if( wizard->GetName() == aWizard->GetName() )
{
m_FootprintWizards.erase( m_FootprintWizards.begin() + ii );
delete wizard;
break;
}
}
m_FootprintWizards.push_back( aWizard );
}
@ -84,13 +104,13 @@ bool FOOTPRINT_WIZARDS::deregister_object( void* aObject )
{
int max = GetWizardsCount();
for( int i = 0; i<max; i++ )
for( int ii = 0; ii < max; ii++ )
{
FOOTPRINT_WIZARD* wizard = GetWizard( i );
FOOTPRINT_WIZARD* wizard = GetWizard( ii );
if( wizard->GetObject() == aObject )
{
m_FootprintWizards.erase( m_FootprintWizards.begin() + i );
m_FootprintWizards.erase( m_FootprintWizards.begin() + ii );
delete wizard;
return true;
}

View File

@ -182,7 +182,9 @@ public:
* Function register_wizard
* A footprint wizard calls this static method when it wants to register itself
* into the system wizards
*
* Note: if it is already registered, this function do nothing
* if n existing wizard with the same name exists, this existing wizard will be
* unregistered.
* @param aWizard is the footprint wizard to be registered
*/
static void register_wizard( FOOTPRINT_WIZARD* aWizard );

View File

@ -56,19 +56,52 @@ enum FPGeneratorRowNames
DIALOG_FOOTPRINT_WIZARD_LIST::DIALOG_FOOTPRINT_WIZARD_LIST( wxWindow* aParent )
: DIALOG_FOOTPRINT_WIZARD_LIST_BASE( aParent )
{
int n_wizards = FOOTPRINT_WIZARDS::GetWizardsCount();
m_config = Kiface().KifaceSettings();
initLists();
if( m_config )
{
wxSize size;
m_config->Read( FPWIZARTDLIST_WIDTH_KEY, &size.x, -1 );
m_config->Read( FPWIZARTDLIST_HEIGHT_KEY, &size.y, -1 );
SetSize( size );
}
m_sdbSizerOK->SetDefault();
FinishDialogSettings();
Center();
}
DIALOG_FOOTPRINT_WIZARD_LIST::~DIALOG_FOOTPRINT_WIZARD_LIST()
{
if( m_config && !IsIconized() )
{
m_config->Write( FPWIZARTDLIST_WIDTH_KEY, GetSize().x );
m_config->Write( FPWIZARTDLIST_HEIGHT_KEY, GetSize().y );
}
}
void DIALOG_FOOTPRINT_WIZARD_LIST::initLists()
{
// Current wizard selection, empty or first
m_footprintWizard = NULL;
int n_wizards = FOOTPRINT_WIZARDS::GetWizardsCount();
if( n_wizards )
m_footprintWizard = FOOTPRINT_WIZARDS::GetWizard( 0 );
// Choose selection mode and insert the needed rows
m_footprintGeneratorsGrid->SetSelectionMode( wxGrid::wxGridSelectRows );
m_footprintGeneratorsGrid->InsertRows( 0, n_wizards, true );
int curr_row_cnt = m_footprintGeneratorsGrid->GetNumberRows();
m_footprintGeneratorsGrid->DeleteRows( 0, curr_row_cnt );
m_footprintGeneratorsGrid->InsertRows( 0, n_wizards );
// Put all wizards in the list
for( int ii = 0; ii < n_wizards; ii++ )
@ -99,15 +132,6 @@ DIALOG_FOOTPRINT_WIZARD_LIST::DIALOG_FOOTPRINT_WIZARD_LIST( wxWindow* aParent )
m_footprintGeneratorsGrid->ClearSelection();
m_footprintGeneratorsGrid->SelectRow( 0, false );
if( m_config )
{
wxSize size;
m_config->Read( FPWIZARTDLIST_WIDTH_KEY, &size.x, -1 );
m_config->Read( FPWIZARTDLIST_HEIGHT_KEY, &size.y, -1 );
SetSize( size );
}
// Display info about scripts: Search paths
wxString message;
pcbnewGetScriptsSearchPaths( message );
@ -121,23 +145,22 @@ DIALOG_FOOTPRINT_WIZARD_LIST::DIALOG_FOOTPRINT_WIZARD_LIST( wxWindow* aParent )
}
else
m_tcNotLoaded->SetValue( message );
m_sdbSizerOK->SetDefault();
FinishDialogSettings();
Center();
}
DIALOG_FOOTPRINT_WIZARD_LIST::~DIALOG_FOOTPRINT_WIZARD_LIST()
void DIALOG_FOOTPRINT_WIZARD_LIST::onUpdatePythonModulesClick( wxCommandEvent& event )
{
if( m_config && !IsIconized() )
{
m_config->Write( FPWIZARTDLIST_WIDTH_KEY, GetSize().x );
m_config->Write( FPWIZARTDLIST_HEIGHT_KEY, GetSize().y );
}
}
#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 );
initLists();
#endif
}
void DIALOG_FOOTPRINT_WIZARD_LIST::OnCellFpGeneratorClick( wxGridEvent& event )

View File

@ -41,9 +41,11 @@ public:
FOOTPRINT_WIZARD* GetWizard();
private:
void initLists();
void OnCellFpGeneratorClick( wxGridEvent& event ) override;
void OnCellFpGeneratorDoubleClick( wxGridEvent& event ) override;
void onShowTrace( wxCommandEvent& event ) override;
void onUpdatePythonModulesClick( wxCommandEvent& event ) override;
};
#endif // _DIALOG_FOOTPRINT_WIZARD_LIST_H_

View File

@ -1,5 +1,5 @@
///////////////////////////////////////////////////////////////////////////
// C++ code generated with wxFormBuilder (version Dec 4 2016)
// C++ code generated with wxFormBuilder (version May 6 2016)
// http://www.wxformbuilder.org/
//
// PLEASE DO "NOT" EDIT THIS FILE!
@ -92,6 +92,18 @@ DIALOG_FOOTPRINT_WIZARD_LIST_BASE::DIALOG_FOOTPRINT_WIZARD_LIST_BASE( wxWindow*
bSizerMain->Add( m_notebook, 1, wxEXPAND | wxALL, 5 );
wxBoxSizer* bSizerLower;
bSizerLower = new wxBoxSizer( wxHORIZONTAL );
bSizerLower->Add( 0, 0, 1, wxEXPAND, 5 );
m_buttonUpdateModules = new wxButton( this, wxID_ANY, _("Update Python Modules"), wxDefaultPosition, wxDefaultSize, 0 );
bSizerLower->Add( m_buttonUpdateModules, 0, wxALL, 5 );
bSizerLower->Add( 0, 0, 0, wxRIGHT|wxLEFT, 5 );
m_sdbSizer = new wxStdDialogButtonSizer();
m_sdbSizerOK = new wxButton( this, wxID_OK );
m_sdbSizer->AddButton( m_sdbSizerOK );
@ -99,7 +111,10 @@ DIALOG_FOOTPRINT_WIZARD_LIST_BASE::DIALOG_FOOTPRINT_WIZARD_LIST_BASE( wxWindow*
m_sdbSizer->AddButton( m_sdbSizerCancel );
m_sdbSizer->Realize();
bSizerMain->Add( m_sdbSizer, 0, wxALL|wxALIGN_RIGHT, 5 );
bSizerLower->Add( m_sdbSizer, 0, wxALL|wxALIGN_RIGHT, 5 );
bSizerMain->Add( bSizerLower, 0, wxEXPAND, 5 );
this->SetSizer( bSizerMain );
@ -111,6 +126,7 @@ DIALOG_FOOTPRINT_WIZARD_LIST_BASE::DIALOG_FOOTPRINT_WIZARD_LIST_BASE( wxWindow*
m_footprintGeneratorsGrid->Connect( wxEVT_GRID_CELL_LEFT_CLICK, wxGridEventHandler( DIALOG_FOOTPRINT_WIZARD_LIST_BASE::OnCellFpGeneratorClick ), NULL, this );
m_footprintGeneratorsGrid->Connect( wxEVT_GRID_CELL_LEFT_DCLICK, wxGridEventHandler( DIALOG_FOOTPRINT_WIZARD_LIST_BASE::OnCellFpGeneratorDoubleClick ), NULL, this );
m_buttonShowTrace->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_FOOTPRINT_WIZARD_LIST_BASE::onShowTrace ), NULL, this );
m_buttonUpdateModules->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_FOOTPRINT_WIZARD_LIST_BASE::onUpdatePythonModulesClick ), NULL, this );
}
DIALOG_FOOTPRINT_WIZARD_LIST_BASE::~DIALOG_FOOTPRINT_WIZARD_LIST_BASE()
@ -119,6 +135,7 @@ DIALOG_FOOTPRINT_WIZARD_LIST_BASE::~DIALOG_FOOTPRINT_WIZARD_LIST_BASE()
m_footprintGeneratorsGrid->Disconnect( wxEVT_GRID_CELL_LEFT_CLICK, wxGridEventHandler( DIALOG_FOOTPRINT_WIZARD_LIST_BASE::OnCellFpGeneratorClick ), NULL, this );
m_footprintGeneratorsGrid->Disconnect( wxEVT_GRID_CELL_LEFT_DCLICK, wxGridEventHandler( DIALOG_FOOTPRINT_WIZARD_LIST_BASE::OnCellFpGeneratorDoubleClick ), NULL, this );
m_buttonShowTrace->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_FOOTPRINT_WIZARD_LIST_BASE::onShowTrace ), NULL, this );
m_buttonUpdateModules->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_FOOTPRINT_WIZARD_LIST_BASE::onUpdatePythonModulesClick ), NULL, this );
}

View File

@ -930,28 +930,147 @@
</object>
<object class="sizeritem" expanded="1">
<property name="border">5</property>
<property name="flag">wxALL|wxALIGN_RIGHT</property>
<property name="flag">wxEXPAND</property>
<property name="proportion">0</property>
<object class="wxStdDialogButtonSizer" expanded="1">
<property name="Apply">0</property>
<property name="Cancel">1</property>
<property name="ContextHelp">0</property>
<property name="Help">0</property>
<property name="No">0</property>
<property name="OK">1</property>
<property name="Save">0</property>
<property name="Yes">0</property>
<object class="wxBoxSizer" expanded="1">
<property name="minimum_size"></property>
<property name="name">m_sdbSizer</property>
<property name="permission">protected</property>
<event name="OnApplyButtonClick"></event>
<event name="OnCancelButtonClick"></event>
<event name="OnContextHelpButtonClick"></event>
<event name="OnHelpButtonClick"></event>
<event name="OnNoButtonClick"></event>
<event name="OnOKButtonClick"></event>
<event name="OnSaveButtonClick"></event>
<event name="OnYesButtonClick"></event>
<property name="name">bSizerLower</property>
<property name="orient">wxHORIZONTAL</property>
<property name="permission">none</property>
<object class="sizeritem" expanded="1">
<property name="border">5</property>
<property name="flag">wxEXPAND</property>
<property name="proportion">1</property>
<object class="spacer" expanded="1">
<property name="height">0</property>
<property name="permission">protected</property>
<property name="width">0</property>
</object>
</object>
<object class="sizeritem" expanded="1">
<property name="border">5</property>
<property name="flag">wxALL</property>
<property name="proportion">0</property>
<object class="wxButton" expanded="1">
<property name="BottomDockable">1</property>
<property name="LeftDockable">1</property>
<property name="RightDockable">1</property>
<property name="TopDockable">1</property>
<property name="aui_layer"></property>
<property name="aui_name"></property>
<property name="aui_position"></property>
<property name="aui_row"></property>
<property name="best_size"></property>
<property name="bg"></property>
<property name="caption"></property>
<property name="caption_visible">1</property>
<property name="center_pane">0</property>
<property name="close_button">1</property>
<property name="context_help"></property>
<property name="context_menu">1</property>
<property name="default">0</property>
<property name="default_pane">0</property>
<property name="dock">Dock</property>
<property name="dock_fixed">0</property>
<property name="docking">Left</property>
<property name="enabled">1</property>
<property name="fg"></property>
<property name="floatable">1</property>
<property name="font"></property>
<property name="gripper">0</property>
<property name="hidden">0</property>
<property name="id">wxID_ANY</property>
<property name="label">Update Python Modules</property>
<property name="max_size"></property>
<property name="maximize_button">0</property>
<property name="maximum_size"></property>
<property name="min_size"></property>
<property name="minimize_button">0</property>
<property name="minimum_size"></property>
<property name="moveable">1</property>
<property name="name">m_buttonUpdateModules</property>
<property name="pane_border">1</property>
<property name="pane_position"></property>
<property name="pane_size"></property>
<property name="permission">protected</property>
<property name="pin_button">1</property>
<property name="pos"></property>
<property name="resize">Resizable</property>
<property name="show">1</property>
<property name="size"></property>
<property name="style"></property>
<property name="subclass"></property>
<property name="toolbar_pane">0</property>
<property name="tooltip"></property>
<property name="validator_data_type"></property>
<property name="validator_style">wxFILTER_NONE</property>
<property name="validator_type">wxDefaultValidator</property>
<property name="validator_variable"></property>
<property name="window_extra_style"></property>
<property name="window_name"></property>
<property name="window_style"></property>
<event name="OnButtonClick">onUpdatePythonModulesClick</event>
<event name="OnChar"></event>
<event name="OnEnterWindow"></event>
<event name="OnEraseBackground"></event>
<event name="OnKeyDown"></event>
<event name="OnKeyUp"></event>
<event name="OnKillFocus"></event>
<event name="OnLeaveWindow"></event>
<event name="OnLeftDClick"></event>
<event name="OnLeftDown"></event>
<event name="OnLeftUp"></event>
<event name="OnMiddleDClick"></event>
<event name="OnMiddleDown"></event>
<event name="OnMiddleUp"></event>
<event name="OnMotion"></event>
<event name="OnMouseEvents"></event>
<event name="OnMouseWheel"></event>
<event name="OnPaint"></event>
<event name="OnRightDClick"></event>
<event name="OnRightDown"></event>
<event name="OnRightUp"></event>
<event name="OnSetFocus"></event>
<event name="OnSize"></event>
<event name="OnUpdateUI"></event>
</object>
</object>
<object class="sizeritem" expanded="1">
<property name="border">5</property>
<property name="flag">wxRIGHT|wxLEFT</property>
<property name="proportion">0</property>
<object class="spacer" expanded="1">
<property name="height">0</property>
<property name="permission">protected</property>
<property name="width">0</property>
</object>
</object>
<object class="sizeritem" expanded="1">
<property name="border">5</property>
<property name="flag">wxALL|wxALIGN_RIGHT</property>
<property name="proportion">0</property>
<object class="wxStdDialogButtonSizer" expanded="1">
<property name="Apply">0</property>
<property name="Cancel">1</property>
<property name="ContextHelp">0</property>
<property name="Help">0</property>
<property name="No">0</property>
<property name="OK">1</property>
<property name="Save">0</property>
<property name="Yes">0</property>
<property name="minimum_size"></property>
<property name="name">m_sdbSizer</property>
<property name="permission">protected</property>
<event name="OnApplyButtonClick"></event>
<event name="OnCancelButtonClick"></event>
<event name="OnContextHelpButtonClick"></event>
<event name="OnHelpButtonClick"></event>
<event name="OnNoButtonClick"></event>
<event name="OnOKButtonClick"></event>
<event name="OnSaveButtonClick"></event>
<event name="OnYesButtonClick"></event>
</object>
</object>
</object>
</object>
</object>

View File

@ -1,5 +1,5 @@
///////////////////////////////////////////////////////////////////////////
// C++ code generated with wxFormBuilder (version Dec 4 2016)
// C++ code generated with wxFormBuilder (version May 6 2016)
// http://www.wxformbuilder.org/
//
// PLEASE DO "NOT" EDIT THIS FILE!
@ -51,6 +51,7 @@ class DIALOG_FOOTPRINT_WIZARD_LIST_BASE : public DIALOG_SHIM
wxStaticText* m_staticText11;
wxTextCtrl* m_tcNotLoaded;
wxButton* m_buttonShowTrace;
wxButton* m_buttonUpdateModules;
wxStdDialogButtonSizer* m_sdbSizer;
wxButton* m_sdbSizerOK;
wxButton* m_sdbSizerCancel;
@ -59,6 +60,7 @@ class DIALOG_FOOTPRINT_WIZARD_LIST_BASE : public DIALOG_SHIM
virtual void OnCellFpGeneratorClick( wxGridEvent& event ) { event.Skip(); }
virtual void OnCellFpGeneratorDoubleClick( wxGridEvent& event ) { event.Skip(); }
virtual void onShowTrace( wxCommandEvent& event ) { event.Skip(); }
virtual void onUpdatePythonModulesClick( wxCommandEvent& event ) { event.Skip(); }
public:

View File

@ -448,7 +448,6 @@ wxString PyScriptingPath()
#endif
wxFileName scriptPath( path );
scriptPath.MakeAbsolute();
return scriptPath.GetFullPath();

View File

@ -54,8 +54,10 @@
KICAD_PLUGINS={} # the list of loaded footprint wizards
""" the list of not loaded python scripts (due to a synthax error in python script)
this is the python script full filenames, separated by '\n'
""" the list of not loaded python scripts
(usually because there is a syntax error in python script)
this is the python script full filenames list.
filenames are separated by '\n'
"""
NOT_LOADED_WIZARDS=""
@ -81,29 +83,6 @@ def GetWizardsBackTrace():
global FULL_BACK_TRACE
return FULL_BACK_TRACE
def ReloadPlugin(name):
if not KICAD_PLUGINS.has_key(name):
return False
KICAD_PLUGINS[name]["object"].deregister()
mod = reload(KICAD_PLUGINS[name]["module"])
KICAD_PLUGINS[name]["object"]= mod.register()
def ReloadPlugins():
import os.path
for k in KICAD_PLUGINS.keys():
plugin = KICAD_PLUGINS[k]
filename = plugin["filename"]
mtime = plugin["modification_time"]
now_mtime = os.path.getmtime(filename)
if mtime!=now_mtime:
# /* print filename, " is modified, reloading" */
KICAD_PLUGINS[k]["modification_time"]=now_mtime
ReloadPlugin(k)
def LoadPlugins(bundlepath=None):
"""
@ -169,9 +148,11 @@ def LoadPlugins(bundlepath=None):
PLUGIN_DIRECTORIES_SEARCH += plugins_dir
global FULL_BACK_TRACE
FULL_BACK_TRACE=""
FULL_BACK_TRACE="" # clear any existing trace
failed_wizards_list=""
global KICAD_PLUGINS
for plugins_dir in plugin_directories:
if not os.path.isdir(plugins_dir):
continue
@ -187,14 +168,22 @@ def LoadPlugins(bundlepath=None):
try: # If there is an error loading the script, skip it
module_filename = plugins_dir + "/" + module
mod = __import__(module[:-3], locals(), globals())
mtime = os.path.getmtime(module_filename)
if hasattr(mod,'register'):
KICAD_PLUGINS[module]={"filename":module_filename,
"modification_time":mtime,
"object":mod.register(),
"module":mod}
if KICAD_PLUGINS.has_key(module):
plugin = KICAD_PLUGINS[module]
if not plugin["modification_time"] == mtime:
mod = reload(plugin["module"])
plugin["modification_time"] = mtime
else:
mod = plugin["module"]
else:
mod = __import__(module[:-3], locals(), globals() )
KICAD_PLUGINS[module]={"filename":module_filename,
"modification_time":mtime,
"module":mod}
except:
if failed_wizards_list != "" :
failed_wizards_list += "\n"
@ -213,6 +202,7 @@ class KiCadPlugin:
def register(self):
if isinstance(self,FilePlugin):
pass # register to file plugins in C++
if isinstance(self,FootprintWizardPlugin):
PYTHON_FOOTPRINT_WIZARDS.register_wizard(self)
return
@ -224,13 +214,14 @@ class KiCadPlugin:
def deregister(self):
if isinstance(self,FilePlugin):
pass # register to file plugins in C++
pass # deregister to file plugins in C++
if isinstance(self,FootprintWizardPlugin):
PYTHON_FOOTPRINT_WIZARDS.deregister_wizard(self)
return
if isinstance(self,ActionPlugin):
pass # register to action plugins in C++
pass # deregister to action plugins in C++
return