Prevent issuing a print command before the previous one is finished

Fixes: lp:1765965
* https://bugs.launchpad.net/kicad/+bug/1765965
This commit is contained in:
Maciej Suminski 2018-04-23 11:17:28 +02:00
parent 3cc0554e33
commit cfa9916836
5 changed files with 74 additions and 1 deletions

View File

@ -38,7 +38,7 @@
#include <invoke_sch_dialog.h> #include <invoke_sch_dialog.h>
#include <dialog_print_using_printer_base.h> #include <dialog_print_using_printer_base.h>
#include <enabler.h>
/** /**
@ -300,6 +300,10 @@ void DIALOG_PRINT_USING_PRINTER::OnPrintButtonClick( wxCommandEvent& event )
wxPrinter printer( &printDialogData ); wxPrinter printer( &printDialogData );
SCH_PRINTOUT printout( parent, _( "Print Schematic" ) ); SCH_PRINTOUT printout( parent, _( "Print Schematic" ) );
// Disable 'Print' button to prevent issuing another print
// command before the previous one is finished (causes problems on Windows)
ENABLER printBtnDisable( *m_buttonPrint, false );
if( !printer.Print( this, &printout, true ) ) if( !printer.Print( this, &printout, true ) )
{ {
if( wxPrinter::GetLastError() == wxPRINTER_ERROR ) if( wxPrinter::GetLastError() == wxPRINTER_ERROR )

View File

@ -37,6 +37,8 @@
#include <gerber_file_image.h> #include <gerber_file_image.h>
#include <gerber_file_image_list.h> #include <gerber_file_image_list.h>
#include <enabler.h>
///@{ ///@{
/// \ingroup config /// \ingroup config
@ -403,6 +405,10 @@ void DIALOG_PRINT_USING_PRINTER::OnPrintButtonClick( wxCommandEvent& event )
wxString title = _( "Print" ); wxString title = _( "Print" );
BOARD_PRINTOUT_CONTROLLER printout( s_Parameters, m_Parent, title ); BOARD_PRINTOUT_CONTROLLER printout( s_Parameters, m_Parent, title );
// Disable 'Print' button to prevent issuing another print
// command before the previous one is finished (causes problems on Windows)
ENABLER printBtnDisable( *m_buttonPrint, false );
if( !printer.Print( this, &printout, true ) ) if( !printer.Print( this, &printout, true ) )
{ {
if( wxPrinter::GetLastError() == wxPRINTER_ERROR ) if( wxPrinter::GetLastError() == wxPRINTER_ERROR )

54
include/enabler.h Normal file
View File

@ -0,0 +1,54 @@
/*
* Copyright (C) 2018 CERN
* Author: Maciej Suminski <maciej.suminski@cern.ch>
*
* 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 3 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, see <http://www.gnu.org/licenses/>.
*/
#ifndef ENABLER_H
#define ENABLER_H
#include <wx/window.h>
/**
* Simple class to automatically enable/disable widgets.
*
* As long as an ENABLER object exists, the handled widget will be kept in the requested state.
*/
class ENABLER
{
public:
/**
* Constructor.
*
* @param aObject is the object to be temporarily enabled or disabled.
* @param aState is the requested temporary state (true for enabled, false for disabled).
*/
ENABLER( wxWindow& aObject, bool aState )
: m_object( aObject ), m_state( aState )
{
m_object.Enable( m_state );
}
~ENABLER()
{
m_object.Enable( !m_state );
}
private:
wxWindow& m_object;
bool m_state;
};
#endif /* ENABLER_H */

View File

@ -35,6 +35,7 @@
#include <dialog_print_for_modedit_base.h> #include <dialog_print_for_modedit_base.h>
#include <printout_controler.h> #include <printout_controler.h>
#include <enabler.h>
static double s_scaleList[] = static double s_scaleList[] =
{ 0, 0.5, 0.7, 1.0, 1.4, 2.0, 3.0, 4.0, 8.0, 16.0 }; { 0, 0.5, 0.7, 1.0, 1.4, 2.0, 3.0, 4.0, 8.0, 16.0 };
@ -234,6 +235,10 @@ void DIALOG_PRINT_FOR_MODEDIT::OnPrintButtonClick( wxCommandEvent& event )
BOARD_PRINTOUT_CONTROLLER printout( s_Parameters, m_parent, _( "Print Footprint" ) ); BOARD_PRINTOUT_CONTROLLER printout( s_Parameters, m_parent, _( "Print Footprint" ) );
// Disable 'Print' button to prevent issuing another print
// command before the previous one is finished (causes problems on Windows)
ENABLER printBtnDisable( *m_buttonPrint, false );
if( !printer.Print( this, &printout, true ) ) if( !printer.Print( this, &printout, true ) )
{ {
if( wxPrinter::GetLastError() == wxPRINTER_ERROR ) if( wxPrinter::GetLastError() == wxPRINTER_ERROR )

View File

@ -39,6 +39,7 @@
#include <class_board.h> #include <class_board.h>
#include <dialog_print_using_printer_base.h> #include <dialog_print_using_printer_base.h>
#include <enabler.h>
#define PEN_WIDTH_MAX_VALUE ( KiROUND( 5 * IU_PER_MM ) ) #define PEN_WIDTH_MAX_VALUE ( KiROUND( 5 * IU_PER_MM ) )
@ -494,6 +495,9 @@ void DIALOG_PRINT_USING_PRINTER::OnPrintButtonClick( wxCommandEvent& event )
wxString title = _( "Print" ); wxString title = _( "Print" );
BOARD_PRINTOUT_CONTROLLER printout( s_Parameters, m_parent, title ); BOARD_PRINTOUT_CONTROLLER printout( s_Parameters, m_parent, title );
// Disable 'Print' button to prevent issuing another print
// command before the previous one is finished (causes problems on Windows)
ENABLER printBtnDisable( *m_buttonPrint, false );
if( !printer.Print( this, &printout, true ) ) if( !printer.Print( this, &printout, true ) )
{ {