kicad-developers team mailing list archive
-
kicad-developers team
-
Mailing list archive
-
Message #09362
[PATCH] Log of opened and closed applications in KiCad launcher
Hi,
we have been doing some changes in the launcher, to make it more aware
of what's happening with its children applications.
In particular, we have added a log of the opened and closed
applications. When the launcher starts another KiCad application a
message will be logged to the message area in the window. When the
application is closed, the launcher will be notified and it will show
another message. And since a picture is worth a thousand words, I'm
attaching a screenshot to complement the explanation.
This patch implies some changes in the way children applications are
spawned. In particular:
* We modified ProcessExecute at common.cpp to always use wxExecute. It
was only used in Windows compilations but it works perfectly in Linux
too, and should work in OS X also. I guess
* ExecuteFile at gestfich.cpp and ProcessExecute at common.cpp now
receive a callback as a parameter and return an identifier of the
process or 0 in case of error.
Do you think this is useful in upstream KiCad? Also feel free to comment
on the patch or suggest changes.
Best regards,
--
Jacobo Aragunde
Software Engineer at Igalia
=== modified file 'common/common.cpp'
--- common/common.cpp 2012-09-02 16:38:52 +0000
+++ common/common.cpp 2013-01-14 11:38:10 +0000
@@ -313,15 +313,9 @@
}
-bool ProcessExecute( const wxString& aCommandLine, int aFlags )
+int ProcessExecute( const wxString& aCommandLine, int aFlags, wxProcess *callback )
{
-#ifdef __WINDOWS__
- int pid = wxExecute( aCommandLine );
- return pid ? true : false;
-#else
- wxProcess* process = wxProcess::Open( aCommandLine, aFlags );
- return (process != NULL) ? true : false;
-#endif
+ return wxExecute( aCommandLine, aFlags, callback );
}
=== modified file 'common/gestfich.cpp'
--- common/gestfich.cpp 2012-10-18 19:31:40 +0000
+++ common/gestfich.cpp 2013-01-14 11:38:10 +0000
@@ -415,7 +415,8 @@
}
-int ExecuteFile( wxWindow* frame, const wxString& ExecFile, const wxString& param )
+int ExecuteFile( wxWindow* frame, const wxString& ExecFile, const wxString& param,
+ wxProcess *callback )
{
wxString FullFileName;
@@ -425,19 +426,18 @@
#ifdef __WXMAC__
if( wxFileExists( FullFileName ) || wxDir::Exists( FullFileName ) )
{
- ProcessExecute( wxGetApp().GetExecutablePath() + wxT("/") + ExecFile + wxT(" ") + param );
+ return ProcessExecute( wxGetApp().GetExecutablePath() + wxT("/") + ExecFile + wxT(" ") + param,
+ wxEXEC_ASYNC, callback );
} else {
- ProcessExecute( wxT("/usr/bin/open ") + param );
+ return ProcessExecute( wxT("/usr/bin/open ") + param, wxEXEC_ASYNC, callback );
}
- return 0;
#else
if( wxFileExists( FullFileName ) )
{
if( !param.IsEmpty() )
FullFileName += wxT( " " ) + param;
- ProcessExecute( FullFileName );
- return 0;
+ return ProcessExecute( FullFileName, wxEXEC_ASYNC, callback );
}
#endif
wxString msg;
=== modified file 'include/common.h'
--- include/common.h 2012-09-02 16:38:52 +0000
+++ include/common.h 2013-01-14 11:38:10 +0000
@@ -555,9 +555,13 @@
* @param aCommandLine The process and any arguments to it all in a single
* string.
* @param aFlags The same args as allowed for wxExecute()
- * @return bool - true if success, else false
+ * @param callback wxProcess implementing OnTerminate to be run when the
+ child process finishes
+ * @return int - pid of process, 0 in case of error (like return values of
+ * wxExecute())
*/
-bool ProcessExecute( const wxString& aCommandLine, int aFlags = wxEXEC_ASYNC );
+int ProcessExecute( const wxString& aCommandLine, int aFlags = wxEXEC_ASYNC,
+ wxProcess *callback = NULL );
/*******************/
=== modified file 'include/gestfich.h'
--- include/gestfich.h 2011-11-08 16:37:25 +0000
+++ include/gestfich.h 2013-01-14 11:38:10 +0000
@@ -10,6 +10,7 @@
#define __INCLUDE__GESTFICH_H__ 1
#include <wx/filename.h>
+#include <wx/process.h>
/* Forward class declarations. */
@@ -79,7 +80,7 @@
* calls the executable file \a ExecFile with the command line parameters \a param.
*/
int ExecuteFile( wxWindow* frame, const wxString& ExecFile,
- const wxString& param = wxEmptyString );
+ const wxString& param = wxEmptyString, wxProcess *callback = NULL );
/**
* Function AddDelimiterString
=== modified file 'kicad/class_treeproject_item.cpp'
--- kicad/class_treeproject_item.cpp 2013-01-03 19:25:12 +0000
+++ kicad/class_treeproject_item.cpp 2013-01-14 11:38:10 +0000
@@ -34,6 +34,7 @@
#include <macros.h>
#include <kicad.h>
+#include <appl_wxstruct.h>
#include <tree_project_frame.h>
#include <class_treeprojectfiles.h>
#include <class_treeproject_item.h>
@@ -188,6 +189,7 @@
wxString sep = wxFileName().GetPathSeparator();
wxString FullFileName = GetFileName();
wxTreeItemId id = GetId();
+ KICAD_MANAGER_FRAME* mainFrame = (KICAD_MANAGER_FRAME*) wxGetApp().GetTopWindow();
AddDelimiterString( FullFileName );
@@ -201,16 +203,16 @@
break;
case TREE_SCHEMA:
- ExecuteFile( m_parent, EESCHEMA_EXE, FullFileName );
+ mainFrame->Execute( m_parent, EESCHEMA_EXE, FullFileName );
break;
case TREE_LEGACY_PCB:
case TREE_SEXP_PCB:
- ExecuteFile( m_parent, PCBNEW_EXE, FullFileName );
+ mainFrame->Execute( m_parent, PCBNEW_EXE, FullFileName );
break;
case TREE_GERBER:
- ExecuteFile( m_parent, GERBVIEW_EXE, FullFileName );
+ mainFrame->Execute( m_parent, GERBVIEW_EXE, FullFileName );
break;
case TREE_PDF:
@@ -218,7 +220,7 @@
break;
case TREE_NET:
- ExecuteFile( m_parent, CVPCB_EXE, FullFileName );
+ mainFrame->Execute( m_parent, CVPCB_EXE, FullFileName );
break;
case TREE_TXT:
@@ -226,7 +228,7 @@
wxString editorname = wxGetApp().GetEditorName();
if( !editorname.IsEmpty() )
- ExecuteFile( m_parent, editorname, FullFileName );
+ mainFrame->Execute( m_parent, editorname, FullFileName );
break;
}
@@ -235,4 +237,5 @@
OpenFile( FullFileName );
break;
}
+
}
=== modified file 'kicad/kicad.h'
--- kicad/kicad.h 2013-01-02 21:49:56 +0000
+++ kicad/kicad.h 2013-01-14 11:38:10 +0000
@@ -1,6 +1,31 @@
-/***********/
-/* kicad.h */
-/***********/
+/**
+ * @file kicad/kicad.h
+ * @brief KICAD_MANAGER_FRAME is the KiCad main frame.
+ */
+
+/*
+ * This program source code file is part of KiCad, a free EDA CAD application.
+ *
+ * Copyright (C) 2013 CERN (www.cern.ch)
+ * Copyright (C) 2004-2012 KiCad Developers, see change_log.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
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, you may find one here:
+ * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
+ * or you may search the http://www.gnu.org website for the version 2 license,
+ * or you may write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
#ifndef KICAD_H
#define KICAD_H
@@ -10,6 +35,7 @@
#include <wx/treectrl.h>
#include <wx/dragimag.h>
#include <wx/filename.h>
+#include <wx/process.h>
#include <id.h>
#include <wxstruct.h>
@@ -182,6 +208,29 @@
*/
void SaveSettings();
+ /**
+ * Function Execute
+ * opens another KiCad application and logs a message.
+ * @param frame = owner frame.
+ * @param execFile = name of the executable file.
+ * @param param = parameters to be passed to the executable.
+ */
+ void Execute( wxWindow* frame, const wxString& execFile, const wxString& param = wxEmptyString );
+
+ class PROCESS_TERMINATE_EVENT_HANDLER : public wxProcess
+ {
+ private:
+ wxString appName;
+
+ public:
+ PROCESS_TERMINATE_EVENT_HANDLER( const wxString& appName ) :
+ appName(appName)
+ {
+ }
+
+ void OnTerminate( int pid, int status );
+ };
+
#ifdef KICAD_USE_FILES_WATCHER
/**
* Called by sending a event with id = ID_INIT_WATCHED_PATHS
=== modified file 'kicad/mainframe.cpp'
--- kicad/mainframe.cpp 2013-01-01 14:06:49 +0000
+++ kicad/mainframe.cpp 2013-01-14 11:38:10 +0000
@@ -7,6 +7,7 @@
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2012 Jean-Pierre Charras, jaen-pierre.charras@xxxxxxxxxxxxxxxxxx
+ * Copyright (C) 2013 CERN (www.cern.ch)
* Copyright (C) 2004-2012 KiCad Developers, see change_log.txt for contributors.
*
* This program is free software; you can redistribute it and/or
@@ -186,15 +187,48 @@
}
+void KICAD_MANAGER_FRAME::PROCESS_TERMINATE_EVENT_HANDLER::OnTerminate( int pid, int status ) {
+
+ wxString msg;
+
+ msg.Printf( appName + _( " closed [%d]\n" ), pid );
+ ( (KICAD_MANAGER_FRAME*) wxGetApp().GetTopWindow() )->PrintMsg( msg );
+
+ delete this;
+}
+
+
+void KICAD_MANAGER_FRAME::Execute( wxWindow* frame, const wxString& execFile,
+ const wxString& param )
+{
+
+ PROCESS_TERMINATE_EVENT_HANDLER* callback;
+ long pid;
+ wxString msg;
+
+ callback = new PROCESS_TERMINATE_EVENT_HANDLER( execFile );
+ pid = ExecuteFile( frame, execFile, param, callback );
+
+ if( pid > 0 ) {
+ msg.Printf( execFile + _( " opened [%ld]\n" ), pid );
+ PrintMsg( msg );
+ }
+ else
+ {
+ delete callback;
+ }
+}
+
+
void KICAD_MANAGER_FRAME::OnRunBitmapConverter( wxCommandEvent& event )
{
- ExecuteFile( this, BITMAPCONVERTER_EXE, wxEmptyString );
+ Execute( this, BITMAPCONVERTER_EXE );
}
void KICAD_MANAGER_FRAME::OnRunPcbCalculator( wxCommandEvent& event )
{
- ExecuteFile( this, PCB_CALCULATOR_EXE, wxEmptyString );
+ Execute( this, PCB_CALCULATOR_EXE );
}
@@ -207,9 +241,9 @@
kicad_board.SetExt( KiCadPcbFileExtension );
if( !legacy_board.FileExists() || kicad_board.FileExists() )
- ExecuteFile( this, PCBNEW_EXE, QuoteFullPath( kicad_board ) );
+ Execute( this, PCBNEW_EXE, QuoteFullPath( kicad_board ) );
else
- ExecuteFile( this, PCBNEW_EXE, QuoteFullPath( legacy_board ) );
+ Execute( this, PCBNEW_EXE, QuoteFullPath( legacy_board ) );
}
@@ -218,26 +252,25 @@
wxFileName fn( m_ProjectFileName );
fn.SetExt( NetlistFileExtension );
- ExecuteFile( this, CVPCB_EXE, QuoteFullPath( fn ) );
+ Execute( this, CVPCB_EXE, QuoteFullPath( fn ) );
}
-
void KICAD_MANAGER_FRAME::OnRunEeschema( wxCommandEvent& event )
{
wxFileName fn( m_ProjectFileName );
fn.SetExt( SchematicFileExtension );
- ExecuteFile( this, EESCHEMA_EXE, QuoteFullPath( fn ) );
+ Execute( this, EESCHEMA_EXE, QuoteFullPath( fn ) );
+
}
-
void KICAD_MANAGER_FRAME::OnRunGerbview( wxCommandEvent& event )
{
wxFileName fn( m_ProjectFileName );
wxString path = wxT( "\"" );
path += fn.GetPath( wxPATH_GET_SEPARATOR | wxPATH_GET_VOLUME ) + wxT( "\"" );
- ExecuteFile( this, GERBVIEW_EXE, path );
+ Execute( this, GERBVIEW_EXE, path );
}
@@ -246,7 +279,7 @@
wxString editorname = wxGetApp().GetEditorName();
if( !editorname.IsEmpty() )
- ExecuteFile( this, editorname, wxEmptyString );
+ Execute( this, editorname, wxEmptyString );
}
@@ -271,7 +304,7 @@
filename += dlg.GetPath() + wxT( "\"" );
if( !dlg.GetPath().IsEmpty() && !wxGetApp().GetEditorName().IsEmpty() )
- ExecuteFile( this, wxGetApp().GetEditorName(), filename );
+ Execute( this, wxGetApp().GetEditorName(), filename );
}
Attachment:
kicad-launcher.jpg
Description: JPEG image
Follow ups