From 78d96afe28b144664f15efaef0f5b74d29936b15 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 31 Mar 2016 08:28:16 +0200 Subject: [PATCH] Eeschema: enhancement on Windows: adds a show console option for BOM plugin execution (needed for instance by python plugins which are run with pythonw) --- eeschema/dialogs/dialog_bom.cpp | 155 +++++++++++++++++++------- eeschema/dialogs/dialog_bom_base.cpp | 11 +- eeschema/dialogs/dialog_bom_base.fbp | 90 ++++++++++++++- eeschema/dialogs/dialog_bom_base.h | 6 +- eeschema/dialogs/dialog_bom_help.html | 4 + eeschema/netform.cpp | 6 +- eeschema/schframe.cpp | 3 + eeschema/schframe.h | 27 ++++- 8 files changed, 253 insertions(+), 49 deletions(-) diff --git a/eeschema/dialogs/dialog_bom.cpp b/eeschema/dialogs/dialog_bom.cpp index 11ac1bf5a9..41bd13a259 100644 --- a/eeschema/dialogs/dialog_bom.cpp +++ b/eeschema/dialogs/dialog_bom.cpp @@ -34,6 +34,7 @@ #include #include #include +#include #include #include @@ -55,6 +56,24 @@ const char * s_bomHelpInfo = using namespace T_BOMCFG_T; +/** + * Structure BOM_PLUGIN + * holds data of the BOM plugin. + */ +struct BOM_PLUGIN +{ + wxString Name; + wxString Command; + wxArrayString Options; +}; + +/** + * Define wxArray of BOM_PLUGIN. + */ +WX_DECLARE_OBJARRAY( BOM_PLUGIN, BOM_PLUGIN_ARRAY ); +#include +WX_DEFINE_OBJARRAY( BOM_PLUGIN_ARRAY ); + /** * Class BOM_CFG_READER_PARSER * holds data and functions pertinent to parsing a S-expression file @@ -62,10 +81,10 @@ using namespace T_BOMCFG_T; */ class BOM_CFG_READER_PARSER : public DIALOG_BOM_CFG_LEXER { - wxArrayString* m_pluginsList; + BOM_PLUGIN_ARRAY* m_pluginsList; public: - BOM_CFG_READER_PARSER( wxArrayString* aPlugins, + BOM_CFG_READER_PARSER( BOM_PLUGIN_ARRAY* aPlugins, const char* aData, const wxString& aSource ); void Parse() throw( PARSE_ERROR, IO_ERROR ); @@ -75,7 +94,7 @@ private: // PCB_PLOT_PARAMS_PARSER -BOM_CFG_READER_PARSER::BOM_CFG_READER_PARSER( wxArrayString* aPlugins, +BOM_CFG_READER_PARSER::BOM_CFG_READER_PARSER( BOM_PLUGIN_ARRAY* aPlugins, const char* aLine, const wxString& aSource ) : DIALOG_BOM_CFG_LEXER( aLine, aSource ) @@ -114,10 +133,10 @@ void BOM_CFG_READER_PARSER::Parse() throw( PARSE_ERROR, IO_ERROR ) void BOM_CFG_READER_PARSER::parsePlugin() throw( IO_ERROR, PARSE_ERROR ) { - wxString title, command; + BOM_PLUGIN plugin; NeedSYMBOLorNUMBER(); - title = FromUTF8(); + plugin.Name = FromUTF8(); T token; while( ( token = NextTok() ) != T_RIGHT ) @@ -132,12 +151,14 @@ void BOM_CFG_READER_PARSER::parsePlugin() throw( IO_ERROR, PARSE_ERROR ) case T_cmd: NeedSYMBOLorNUMBER(); - command = FromUTF8(); + plugin.Command = FromUTF8(); NeedRIGHT(); break; case T_opts: - while( ( token = NextTok() ) != T_RIGHT && token != T_EOF ); + NeedSYMBOLorNUMBER(); + plugin.Options.Add( FromUTF8() ); + NeedRIGHT(); break; default: @@ -146,23 +167,16 @@ void BOM_CFG_READER_PARSER::parsePlugin() throw( IO_ERROR, PARSE_ERROR ) } } - if( ! title.IsEmpty() ) - { - m_pluginsList->Add( title ); - m_pluginsList->Add( command ); - } + if( ! plugin.Name.IsEmpty() ) + m_pluginsList->Add( plugin ); } -// The main dialog frame tu run scripts to build bom +// The main dialog frame to run scripts to build bom class DIALOG_BOM : public DIALOG_BOM_BASE { private: SCH_EDIT_FRAME* m_parent; - // The list of scripts (or plugins): - // a script descr uses 2 lines: - // the first is the title - // the second is the command line - wxArrayString m_plugins; + BOM_PLUGIN_ARRAY m_plugins; wxConfigBase* m_config; // to store the "plugins" public: @@ -180,6 +194,7 @@ private: void OnEditPlugin( wxCommandEvent& event ); void OnCommandLineEdited( wxCommandEvent& event ); void OnNameEdited( wxCommandEvent& event ); + void OnShowConsoleChanged( wxCommandEvent& event ); void pluginInit(); void installPluginsList(); @@ -218,6 +233,10 @@ DIALOG_BOM::DIALOG_BOM( SCH_EDIT_FRAME* parent ) : m_config = Kiface().KifaceSettings(); installPluginsList(); +#ifdef __WINDOWS__ + m_checkBoxShowConsole->Show( true ); +#endif + GetSizer()->Fit( this ); Centre(); } @@ -228,18 +247,27 @@ DIALOG_BOM::~DIALOG_BOM() // the config stores only one string. // plugins are saved inside a S expr: // ( plugins - // ( plugin "plugin name" (cmd "command line") ) + // ( plugin "plugin name 1" (cmd "command line 1") ) + // ( plugin "plugin name 2" (cmd "command line 2") (opts "option1") (opts "option2") ) // .... // ) STRING_FORMATTER writer; writer.Print( 0, "(plugins" ); - for( unsigned ii = 0; ii < m_plugins.GetCount(); ii += 2 ) + for( unsigned ii = 0; ii < m_plugins.GetCount(); ii++ ) { - writer.Print( 1, "(plugin %s (cmd %s))", - writer.Quotew( m_plugins[ii] ).c_str(), - writer.Quotew( m_plugins[ii+1] ).c_str() ); + writer.Print( 1, "(plugin %s (cmd %s)", + writer.Quotew( m_plugins.Item( ii ).Name ).c_str(), + writer.Quotew( m_plugins.Item( ii ).Command ).c_str() ); + + for( unsigned jj = 0; jj < m_plugins.Item( ii ).Options.GetCount(); jj++ ) + { + writer.Print( 1, "(opts %s)", + writer.Quotew( m_plugins.Item( ii ).Options.Item( jj ) ).c_str() ); + } + + writer.Print( 0, ")" ); } writer.Print( 0, ")" ); @@ -277,12 +305,12 @@ void DIALOG_BOM::installPluginsList() } // Populate list box - for( unsigned ii = 0; ii < m_plugins.GetCount(); ii+=2 ) + for( unsigned ii = 0; ii < m_plugins.GetCount(); ii++ ) { - m_lbPlugins->Append( m_plugins[ii] ); + m_lbPlugins->Append( m_plugins.Item( ii ).Name ); - if( active_plugin_name == m_plugins[ii] ) - m_lbPlugins->SetSelection( ii/2 ); + if( active_plugin_name == m_plugins.Item( ii ).Name ) + m_lbPlugins->SetSelection( ii ); } pluginInit(); @@ -305,8 +333,15 @@ void DIALOG_BOM::pluginInit() return; } - m_textCtrlName->SetValue( m_plugins[2 * ii] ); - m_textCtrlCommand->SetValue( m_plugins[(2 * ii)+1] ); + m_textCtrlName->SetValue( m_plugins.Item( ii ).Name ); + m_textCtrlCommand->SetValue( m_plugins.Item( ii ).Command ); + +#ifdef __WINDOWS__ + if( m_plugins.Item( ii ).Options.Index( wxT( "show_console" ) ) == wxNOT_FOUND ) + m_checkBoxShowConsole->SetValue( false ); + else + m_checkBoxShowConsole->SetValue( true ); +#endif wxString pluginName = getPluginFileName( m_textCtrlCommand->GetValue() ); @@ -392,6 +427,12 @@ void DIALOG_BOM::OnRunPlugin( wxCommandEvent& event ) wxString reportmsg; WX_STRING_REPORTER reporter( &reportmsg ); m_parent->SetNetListerCommand( m_textCtrlCommand->GetValue() ); + +#ifdef __WINDOWS__ + if( m_checkBoxShowConsole->IsChecked() ) + m_parent->SetExecFlags( wxEXEC_SHOW_CONSOLE ); +#endif + m_parent->CreateNetlist( -1, fullfilename, 0, &reporter ); m_Messages->SetValue( reportmsg ); @@ -417,7 +458,7 @@ void DIALOG_BOM::OnRemovePlugin( wxCommandEvent& event ) m_lbPlugins->Delete( ii ); - m_plugins.RemoveAt( 2*ii, 2 ); // Remove title and command line + m_plugins.RemoveAt( ii ); // Select the next item, if exists if( (int)m_lbPlugins->GetCount() >= ii ) @@ -436,6 +477,7 @@ void DIALOG_BOM::OnRemovePlugin( wxCommandEvent& event ) void DIALOG_BOM::OnAddPlugin( wxCommandEvent& event ) { wxString cmdLine = choosePlugin(); + BOM_PLUGIN newPlugin; if( cmdLine.IsEmpty() ) return; @@ -451,18 +493,19 @@ void DIALOG_BOM::OnAddPlugin( wxCommandEvent& event ) return; // Verify if it does not exists - for( unsigned ii = 0; ii < m_plugins.GetCount(); ii += 2 ) + for( unsigned ii = 0; ii < m_plugins.GetCount(); ii++ ) { - if( name == m_plugins[ii] ) + if( name == m_plugins.Item( ii ).Name ) { wxMessageBox( _("This name already exists. Abort") ); return; } } - // Eppend the new plugin - m_plugins.Add( name ); - m_plugins.Add( wxEmptyString ); + // Append the new plugin + newPlugin.Name = name; + newPlugin.Command = wxEmptyString; + m_plugins.Add( newPlugin ); m_lbPlugins->SetSelection( m_lbPlugins->GetCount() - 1 ); m_lbPlugins->Append( name ); m_lbPlugins->SetSelection( m_lbPlugins->GetCount() - 1 ); @@ -497,7 +540,7 @@ wxString DIALOG_BOM::choosePlugin() // Creates a default command line, // suitable to run the external tool xslproc or python // The default command line depending on plugin extension, currently - // "xsl" or "exe" or "py" + // "xsl" or "exe" or "py" or "pyw" wxString cmdLine; wxFileName fn( fullFileName ); wxString ext = fn.GetExt(); @@ -508,6 +551,12 @@ wxString DIALOG_BOM::choosePlugin() cmdLine.Printf(wxT("\"%s\" < \"%%I\" > \"%%O\""), GetChars( fullFileName ) ); else if( ext == wxT("py" ) || ext.IsEmpty() ) cmdLine.Printf(wxT("python \"%s\" \"%%I\" \"%%O\""), GetChars( fullFileName ) ); + else if( ext == wxT("pyw" ) || ext.IsEmpty() ) +#ifdef __WINDOWS__ + cmdLine.Printf(wxT("pythonw \"%s\" \"%%I\" \"%%O\""), GetChars( fullFileName ) ); +#else + cmdLine.Printf(wxT("python \"%s\" \"%%I\" \"%%O\""), GetChars( fullFileName ) ); +#endif else cmdLine.Printf(wxT("\"%s\""), GetChars( fullFileName ) ); @@ -520,13 +569,17 @@ wxString DIALOG_BOM::getPluginFileName( const wxString& aCommand ) wxString pluginName; // Try to find the plugin name. - // This is possible if the name ends by .py or .xsl + // This is possible if the name ends by .py or .pyw or .xsl or .exe int pos = -1; - if( (pos = aCommand.Find( wxT(".py") )) != wxNOT_FOUND ) + if( (pos = aCommand.Find( wxT(".pyw") )) != wxNOT_FOUND ) + pos += 3; + else if( (pos = aCommand.Find( wxT(".py") )) != wxNOT_FOUND ) pos += 2; else if( (pos = aCommand.Find( wxT(".xsl") )) != wxNOT_FOUND ) pos += 3; + else if( (pos = aCommand.Find( wxT(".exe") )) != wxNOT_FOUND ) + pos += 3; // the end of plugin name is at position pos. if( pos > 0 ) @@ -604,7 +657,7 @@ void DIALOG_BOM::OnCommandLineEdited( wxCommandEvent& event ) if( ii < 0 ) return; - m_plugins[(2 * ii)+1] = m_textCtrlCommand->GetValue(); + m_plugins.Item( ii ).Command = m_textCtrlCommand->GetValue(); } void DIALOG_BOM::OnNameEdited( wxCommandEvent& event ) @@ -614,6 +667,26 @@ void DIALOG_BOM::OnNameEdited( wxCommandEvent& event ) if( ii < 0 ) return; - m_plugins[2 * ii] = m_textCtrlName->GetValue(); - m_lbPlugins->SetString( ii, m_plugins[2 * ii] ); + m_plugins.Item( ii ).Name = m_textCtrlName->GetValue(); + m_lbPlugins->SetString( ii, m_plugins.Item( ii ).Name ); +} + +void DIALOG_BOM::OnShowConsoleChanged( wxCommandEvent& event ) +{ +#ifdef __WINDOWS__ + int ii = m_lbPlugins->GetSelection(); + + if( ii < 0 ) + return; + + if( m_checkBoxShowConsole->IsChecked() ) + { + if( m_plugins.Item( ii ).Options.Index( wxT( "show_console" ) ) == wxNOT_FOUND ) + m_plugins.Item( ii ).Options.Add( wxT( "show_console" ) ); + } + else + { + m_plugins.Item( ii ).Options.Remove( wxT( "show_console" ) ); + } +#endif } diff --git a/eeschema/dialogs/dialog_bom_base.cpp b/eeschema/dialogs/dialog_bom_base.cpp index a8dca761d6..d53d16263a 100644 --- a/eeschema/dialogs/dialog_bom_base.cpp +++ b/eeschema/dialogs/dialog_bom_base.cpp @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////////////// -// C++ code generated with wxFormBuilder (version Mar 28 2015) +// C++ code generated with wxFormBuilder (version Mar 22 2016) // http://www.wxformbuilder.org/ // // PLEASE DO "NOT" EDIT THIS FILE! @@ -19,6 +19,7 @@ BEGIN_EVENT_TABLE( DIALOG_BOM_BASE, DIALOG_SHIM ) EVT_BUTTON( ID_REMOVEL_PLUGIN, DIALOG_BOM_BASE::_wxFB_OnRemovePlugin ) EVT_BUTTON( wxID_ANY, DIALOG_BOM_BASE::_wxFB_OnEditPlugin ) EVT_TEXT( ID_CMDLINE, DIALOG_BOM_BASE::_wxFB_OnCommandLineEdited ) + EVT_CHECKBOX( wxID_ANY, DIALOG_BOM_BASE::_wxFB_OnShowConsoleChanged ) END_EVENT_TABLE() DIALOG_BOM_BASE::DIALOG_BOM_BASE( wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style ) : DIALOG_SHIM( parent, id, title, pos, size, style ) @@ -46,7 +47,6 @@ DIALOG_BOM_BASE::DIALOG_BOM_BASE( wxWindow* parent, wxWindowID id, const wxStrin bLeftSizer->Add( m_staticTextName, 0, wxRIGHT|wxLEFT, 5 ); m_textCtrlName = new wxTextCtrl( this, IN_NAMELINE, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 ); - m_textCtrlName->SetMaxLength( 0 ); bLeftSizer->Add( m_textCtrlName, 0, wxEXPAND|wxBOTTOM|wxRIGHT|wxLEFT, 5 ); @@ -91,11 +91,16 @@ DIALOG_BOM_BASE::DIALOG_BOM_BASE( wxWindow* parent, wxWindowID id, const wxStrin bbottomSizer->Add( m_staticTextCmd, 0, wxRIGHT|wxLEFT, 5 ); m_textCtrlCommand = new wxTextCtrl( this, ID_CMDLINE, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 ); - m_textCtrlCommand->SetMaxLength( 0 ); m_textCtrlCommand->SetMinSize( wxSize( 380,-1 ) ); bbottomSizer->Add( m_textCtrlCommand, 0, wxEXPAND|wxBOTTOM|wxRIGHT|wxLEFT, 5 ); + m_checkBoxShowConsole = new wxCheckBox( this, wxID_ANY, _("Show console window"), wxDefaultPosition, wxDefaultSize, 0 ); + m_checkBoxShowConsole->Hide(); + m_checkBoxShowConsole->SetToolTip( _("By default, command line runs with hidden console window and output is redirected to \"Plugin info\" field. Set this option to show the window of the running command.") ); + + bbottomSizer->Add( m_checkBoxShowConsole, 0, wxBOTTOM|wxLEFT, 5 ); + bMainSizer->Add( bbottomSizer, 0, wxEXPAND, 5 ); diff --git a/eeschema/dialogs/dialog_bom_base.fbp b/eeschema/dialogs/dialog_bom_base.fbp index f00eec7598..4a7064be63 100644 --- a/eeschema/dialogs/dialog_bom_base.fbp +++ b/eeschema/dialogs/dialog_bom_base.fbp @@ -1263,6 +1263,94 @@ + + 5 + wxBOTTOM|wxLEFT + 0 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 1 + wxID_ANY + Show console window + + 0 + + + 0 + + 1 + m_checkBoxShowConsole + 1 + + + protected + 1 + + Resizable + 1 + + + + 0 + By default, command line runs with hidden console window and output is redirected to "Plugin info" field. Set this option to show the window of the running command. + + wxFILTER_NONE + wxDefaultValidator + + + + + + OnShowConsoleChanged + + + + + + + + + + + + + + + + + + + + + + + + @@ -1383,7 +1471,7 @@ 0 - + 0 0 diff --git a/eeschema/dialogs/dialog_bom_base.h b/eeschema/dialogs/dialog_bom_base.h index 55a540bf11..9c35265f59 100644 --- a/eeschema/dialogs/dialog_bom_base.h +++ b/eeschema/dialogs/dialog_bom_base.h @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////////////// -// C++ code generated with wxFormBuilder (version Mar 28 2015) +// C++ code generated with wxFormBuilder (version Mar 22 2016) // http://www.wxformbuilder.org/ // // PLEASE DO "NOT" EDIT THIS FILE! @@ -25,6 +25,7 @@ class DIALOG_SHIM; #include #include #include +#include #include /////////////////////////////////////////////////////////////////////////// @@ -47,6 +48,7 @@ class DIALOG_BOM_BASE : public DIALOG_SHIM void _wxFB_OnRemovePlugin( wxCommandEvent& event ){ OnRemovePlugin( event ); } void _wxFB_OnEditPlugin( wxCommandEvent& event ){ OnEditPlugin( event ); } void _wxFB_OnCommandLineEdited( wxCommandEvent& event ){ OnCommandLineEdited( event ); } + void _wxFB_OnShowConsoleChanged( wxCommandEvent& event ){ OnShowConsoleChanged( event ); } protected: @@ -73,6 +75,7 @@ class DIALOG_BOM_BASE : public DIALOG_SHIM wxButton* m_buttonEdit; wxStaticText* m_staticTextCmd; wxTextCtrl* m_textCtrlCommand; + wxCheckBox* m_checkBoxShowConsole; wxStaticText* m_staticTextInfo; wxTextCtrl* m_Messages; @@ -86,6 +89,7 @@ class DIALOG_BOM_BASE : public DIALOG_SHIM virtual void OnRemovePlugin( wxCommandEvent& event ) { event.Skip(); } virtual void OnEditPlugin( wxCommandEvent& event ) { event.Skip(); } virtual void OnCommandLineEdited( wxCommandEvent& event ) { event.Skip(); } + virtual void OnShowConsoleChanged( wxCommandEvent& event ) { event.Skip(); } public: diff --git a/eeschema/dialogs/dialog_bom_help.html b/eeschema/dialogs/dialog_bom_help.html index a254d88421..cd6169a2cf 100644 --- a/eeschema/dialogs/dialog_bom_help.html +++ b/eeschema/dialogs/dialog_bom_help.html @@ -109,6 +109,10 @@ information:

command line to launch the converter (usually a script).

+Note (Windows only):

+

+By default, command line runs with hidden console window and output is redirected to "Plugin info" field. To show the window of the running command, set the checkbox "Show console window".

+

Once you click on the generate button the following will happen:

    diff --git a/eeschema/netform.cpp b/eeschema/netform.cpp index 4939476c65..6b41c02e1e 100644 --- a/eeschema/netform.cpp +++ b/eeschema/netform.cpp @@ -104,7 +104,7 @@ bool SCH_EDIT_FRAME::WriteNetListFile( NETLIST_OBJECT_LIST* aConnectedItemsList, if( aReporter ) { wxArrayString output, errors; - int diag = wxExecute( commandLine, output, errors, wxEXEC_SYNC ); + int diag = wxExecute( commandLine, output, errors, m_exec_flags ); wxString msg; @@ -142,7 +142,9 @@ bool SCH_EDIT_FRAME::WriteNetListFile( NETLIST_OBJECT_LIST* aConnectedItemsList, } } else - ProcessExecute( commandLine, wxEXEC_SYNC ); + ProcessExecute( commandLine, m_exec_flags ); + + DefaultExecFlags(); // Reset flags to default after executing } return res; diff --git a/eeschema/schframe.cpp b/eeschema/schframe.cpp index ecd775f411..ecdc7fd796 100644 --- a/eeschema/schframe.cpp +++ b/eeschema/schframe.cpp @@ -420,6 +420,9 @@ SCH_EDIT_FRAME::SCH_EDIT_FRAME( KIWAY* aKiway, wxWindow* aParent ): GetScreen()->SetZoom( BestZoom() ); Zoom_Automatique( false ); + + // Net list generator + DefaultExecFlags(); } diff --git a/eeschema/schframe.h b/eeschema/schframe.h index daf348f1bb..9f87accc2a 100644 --- a/eeschema/schframe.h +++ b/eeschema/schframe.h @@ -145,6 +145,8 @@ private: ///< simulator (gnucap, spice, ...) wxString m_netListerCommand; ///< Command line to call a custom net list ///< generator. + int m_exec_flags; ///< Flags of the wxExecute() function + ///< to call a custom net list generator. bool m_forceHVLines; ///< force H or V directions for wires, bus, line @@ -522,7 +524,7 @@ public: bool CreateNetlist( int aFormat, const wxString& aFullFileName, unsigned aNetlistOptions, - REPORTER* aReporter = NULL ); + REPORTER* aReporter = NULL ); /** * Function WriteNetListFile @@ -1353,6 +1355,29 @@ public: void SetNetListerCommand( const wxString& aCommand ) { m_netListerCommand = aCommand; } + /** + * Function DefaultExecFlags + * resets the execution flags to defaults for external netlist and + * bom generators. + */ + void DefaultExecFlags() { m_exec_flags = wxEXEC_SYNC; } + + /** + * Function SetExecFlags + * sets (adds) specified flags for next execution of external + * generator of the netlist or bom. + * @param aFlags = wxEXEC_* flags, see wxExecute docs. + */ + void SetExecFlags( const int aFlags ) { m_exec_flags |= aFlags; } + + /** + * Function ClearExecFlags + * clears (removes) specified flags that not needed for next execution + * of external generator of the netlist or bom. + * @param aFlags = wxEXEC_* flags, see wxExecute docs. + */ + void ClearExecFlags( const int aFlags ) { m_exec_flags &= ~( aFlags ); } + wxString GetNetListerCommand() const { return m_netListerCommand; } DECLARE_EVENT_TABLE()