diff --git a/common/confirm.cpp b/common/confirm.cpp index d8da3bca1f..c6526526f5 100644 --- a/common/confirm.cpp +++ b/common/confirm.cpp @@ -39,6 +39,9 @@ static std::unordered_map doNotShowAgainDlgs; bool IsGUI() { + if( !wxTheApp ) + return false; + #if wxCHECK_VERSION( 3, 1, 6 ) return wxTheApp->IsGUI(); #else diff --git a/common/eda_base_frame.cpp b/common/eda_base_frame.cpp index 853a620f4c..1111765423 100644 --- a/common/eda_base_frame.cpp +++ b/common/eda_base_frame.cpp @@ -1219,7 +1219,7 @@ bool EDA_BASE_FRAME::IsWritable( const wxFileName& aFileName, bool aVerbose ) if( !msg.IsEmpty() ) { if( aVerbose ) - wxMessageBox( msg ); + DisplayErrorMessage( this, msg ); return false; } @@ -1230,6 +1230,9 @@ bool EDA_BASE_FRAME::IsWritable( const wxFileName& aFileName, bool aVerbose ) void EDA_BASE_FRAME::CheckForAutoSaveFile( const wxFileName& aFileName ) { + if( !IsGUI() ) + return; + wxCHECK_RET( aFileName.IsOk(), wxT( "Invalid file name!" ) ); wxFileName autoSaveFileName = aFileName; diff --git a/common/eda_draw_frame.cpp b/common/eda_draw_frame.cpp index 3173e3fb0f..4e75a3510e 100644 --- a/common/eda_draw_frame.cpp +++ b/common/eda_draw_frame.cpp @@ -428,7 +428,7 @@ void EDA_DRAW_FRAME::OnUpdateSelectZoom( wxUpdateUIEvent& aEvent ) void EDA_DRAW_FRAME::PrintPage( const RENDER_SETTINGS* aSettings ) { - wxMessageBox( wxT("EDA_DRAW_FRAME::PrintPage() error") ); + DisplayErrorMessage( this, wxT("EDA_DRAW_FRAME::PrintPage() error") ); } diff --git a/common/filename_resolver.cpp b/common/filename_resolver.cpp index fdcfea210d..06d405c84a 100644 --- a/common/filename_resolver.cpp +++ b/common/filename_resolver.cpp @@ -488,8 +488,7 @@ bool FILENAME_RESOLVER::addPath( const SEARCH_PATH& aPath ) msg.append( wxT( "\n" ) ); msg.append( _( "Existing path:" ) + wxS( " " ) ); msg.append( sPL->m_Pathvar ); - DisplayErrorMessage( nullptr, msg ); - + DisplayErrorMessage( nullptr, _( "Bad alias (duplicate name)" ), msg ); return false; } diff --git a/eeschema/files-io.cpp b/eeschema/files-io.cpp index 7ad6591581..cbc4a4fb53 100644 --- a/eeschema/files-io.cpp +++ b/eeschema/files-io.cpp @@ -1395,6 +1395,9 @@ bool SCH_EDIT_FRAME::updateAutoSaveFile() void SCH_EDIT_FRAME::CheckForAutoSaveFile( const wxFileName& aFileName ) { + if( !IsGUI() ) + return; + wxCHECK_RET( aFileName.IsOk(), wxT( "Invalid file name!" ) ); wxLogTrace( traceAutoSave, diff --git a/eeschema/sch_base_frame.cpp b/eeschema/sch_base_frame.cpp index 3bd0272c21..d98b78c8f1 100644 --- a/eeschema/sch_base_frame.cpp +++ b/eeschema/sch_base_frame.cpp @@ -227,7 +227,7 @@ bool SCH_BASE_FRAME::saveSymbolLibTables( bool aGlobal, bool aProject ) { success = false; msg.Printf( _( "Error saving global symbol library table:\n%s" ), ioe.What() ); - wxMessageBox( msg, _( "File Save Error" ), wxOK | wxICON_ERROR ); + DisplayErrorMessage( this, msg ); } } @@ -244,7 +244,7 @@ bool SCH_BASE_FRAME::saveSymbolLibTables( bool aGlobal, bool aProject ) success = false; msg.Printf( _( "Error saving project-specific symbol library table:\n%s" ), ioe.What() ); - wxMessageBox( msg, _( "File Save Error" ), wxOK | wxICON_ERROR ); + DisplayErrorMessage( this, msg ); } } diff --git a/include/confirm.h b/include/confirm.h index 5fe5d75c70..c78d88d06c 100644 --- a/include/confirm.h +++ b/include/confirm.h @@ -194,4 +194,11 @@ int OKOrCancelDialog( wxWindow* aParent, const wxString& aWarning, const wxStrin int SelectSingleOption( wxWindow* aParent, const wxString& aTitle, const wxString& aMessage, const wxArrayString& aOptions ); +/** + * Determine if the application is running with a GUI + * + * @return true if there is a GUI and false otherwise + */ +bool IsGUI(); + #endif /* __INCLUDE__CONFIRM_H__ */ diff --git a/pcbnew/files.cpp b/pcbnew/files.cpp index 21c4c5feb7..b47a5e8304 100644 --- a/pcbnew/files.cpp +++ b/pcbnew/files.cpp @@ -576,12 +576,11 @@ int PCB_EDIT_FRAME::inferLegacyEdgeClearance( BOARD* aBoard ) if( mixed ) { // If they had different widths then we can't ensure that fills will be the same. - wxMessageBox( _( "If the zones on this board are refilled the Copper Edge Clearance " + DisplayInfoMessage( this, _( "If the zones on this board are refilled the Copper Edge Clearance " "setting will be used (see Board Setup > Design Rules > Constraints).\n" "This may result in different fills from previous KiCad versions which " "used the line thicknesses of the board boundary on the Edge Cuts " - "layer." ), - _( "Edge Clearance Warning" ), wxOK | wxICON_WARNING, this ); + "layer." ) ); } return std::max( 0, edgeWidth / 2 ); diff --git a/pcbnew/footprint_edit_frame.cpp b/pcbnew/footprint_edit_frame.cpp index 1996fb2194..0cb5afef4c 100644 --- a/pcbnew/footprint_edit_frame.cpp +++ b/pcbnew/footprint_edit_frame.cpp @@ -1267,7 +1267,7 @@ void FOOTPRINT_EDIT_FRAME::OnSaveFootprintAsPng( wxCommandEvent& event ) if( id.empty() ) { - wxMessageBox( _( "No footprint selected." ) ); + DisplayErrorMessage( this, _( "No footprint selected." ) ); return; } diff --git a/pcbnew/footprint_libraries_utils.cpp b/pcbnew/footprint_libraries_utils.cpp index 692e546431..386d19226e 100644 --- a/pcbnew/footprint_libraries_utils.cpp +++ b/pcbnew/footprint_libraries_utils.cpp @@ -364,7 +364,7 @@ void FOOTPRINT_EDIT_FRAME::ExportFootprint( FOOTPRINT* aFootprint ) if( fp == nullptr ) { - wxMessageBox( wxString::Format( _( "Insufficient permissions to write file '%s'." ), + DisplayErrorMessage( this, wxString::Format( _( "Insufficient permissions to write file '%s'." ), dlg.GetPath() ) ); return; } diff --git a/pcbnew/netlist_reader/netlist.cpp b/pcbnew/netlist_reader/netlist.cpp index 29def232ea..8682b1e005 100644 --- a/pcbnew/netlist_reader/netlist.cpp +++ b/pcbnew/netlist_reader/netlist.cpp @@ -27,6 +27,7 @@ #include using namespace std::placeholders; +#include #include #include #include @@ -44,7 +45,6 @@ using namespace std::placeholders; #include #include #include // LAST_PATH_TYPE -#include bool PCB_EDIT_FRAME::ReadNetlistFromFile( const wxString &aFilename, NETLIST& aNetlist, @@ -60,7 +60,7 @@ bool PCB_EDIT_FRAME::ReadNetlistFromFile( const wxString &aFilename, NETLIST& aN if( !netlistReader.get() ) { msg.Printf( _( "Cannot open netlist file '%s'." ), aFilename ); - wxMessageBox( msg, _( "Netlist Load Error." ), wxOK | wxICON_ERROR, this ); + DisplayErrorMessage( this, msg ); return false; } @@ -71,7 +71,7 @@ bool PCB_EDIT_FRAME::ReadNetlistFromFile( const wxString &aFilename, NETLIST& aN catch( const IO_ERROR& ioe ) { msg.Printf( _( "Error loading netlist.\n%s" ), ioe.What().GetData() ); - wxMessageBox( msg, _( "Netlist Load Error" ), wxOK | wxICON_ERROR ); + DisplayErrorMessage( this, msg ); return false; } diff --git a/pcbnew/pcb_edit_frame.cpp b/pcbnew/pcb_edit_frame.cpp index 682bd57143..3836af5b80 100644 --- a/pcbnew/pcb_edit_frame.cpp +++ b/pcbnew/pcb_edit_frame.cpp @@ -1824,7 +1824,7 @@ void PCB_EDIT_FRAME::RunEeschema() else { msg.Printf( _( "Schematic file '%s' not found." ), schematic.GetFullPath() ); - wxMessageBox( msg, _( "KiCad Error" ), wxOK | wxICON_ERROR, this ); + DisplayErrorMessage( this, msg ); return; } } @@ -1853,8 +1853,7 @@ void PCB_EDIT_FRAME::RunEeschema() } catch( const IO_ERROR& err ) { - wxMessageBox( _( "Eeschema failed to load." ) + wxS( "\n" ) + err.What(), - _( "KiCad Error" ), wxOK | wxICON_ERROR, this ); + DisplayErrorMessage( this, _( "Eeschema failed to load." ) + wxS( "\n" ) + err.What() ); return; } } diff --git a/pcbnew/plugins/kicad/pcb_plugin.cpp b/pcbnew/plugins/kicad/pcb_plugin.cpp index b0ebd48735..15332d3887 100644 --- a/pcbnew/plugins/kicad/pcb_plugin.cpp +++ b/pcbnew/plugins/kicad/pcb_plugin.cpp @@ -2569,7 +2569,7 @@ void PCB_PLUGIN::FootprintSave( const wxString& aLibraryPath, const FOOTPRINT* a "Would you like to create it?"), aLibraryPath ); - if( wxMessageBox( msg, _( "Library Not Found"), wxYES_NO | wxICON_QUESTION ) != wxYES ) + if( !IsGUI() || wxMessageBox( msg, _( "Library Not Found"), wxYES_NO | wxICON_QUESTION ) != wxYES ) return; // Save throws its own IO_ERROR on failure, so no need to recreate here