From 688dbe5de12c716c8577593790875e837b122b76 Mon Sep 17 00:00:00 2001 From: jean-pierre charras Date: Tue, 17 Jun 2014 20:31:27 +0200 Subject: [PATCH] Minor cosmetic enhancement, and try to fix an issue with accelerator keys and the Python scripting console --- include/wxPcbStruct.h | 8 ++-- pcbnew/menubar_pcbframe.cpp | 4 +- pcbnew/pcbframe.cpp | 50 +++++++++++------------ pcbnew/tool_pcb.cpp | 10 ++--- pcbnew/toolbars_update_user_interface.cpp | 6 +++ 5 files changed, 42 insertions(+), 36 deletions(-) diff --git a/include/wxPcbStruct.h b/include/wxPcbStruct.h index b9321922a8..b7e23b9b48 100644 --- a/include/wxPcbStruct.h +++ b/include/wxPcbStruct.h @@ -105,9 +105,7 @@ class PCB_EDIT_FRAME : public PCB_BASE_FRAME protected: #ifdef KICAD_SCRIPTING_WXPYTHON - // Panel used to let user talk with internal scripting - wxWindow* m_pythonPanel; - bool m_pythonPanelHidden; + bool m_pythonPanelShow; ///< Visibility flag for Python Console #endif PCB_LAYER_WIDGET* m_Layers; @@ -1524,7 +1522,9 @@ public: * Function ScriptingConsoleEnableDisable * enables or disabled the scripting console */ - void ScriptingConsoleEnableDisable( wxCommandEvent& event ); + void ScriptingConsoleEnableDisable( wxCommandEvent& aEvent ); + + void OnUpdateScriptingConsoleState( wxUpdateUIEvent& aEvent ); void OnSelectAutoPlaceMode( wxCommandEvent& aEvent ); diff --git a/pcbnew/menubar_pcbframe.cpp b/pcbnew/menubar_pcbframe.cpp index b95b8529fe..649694ac4f 100644 --- a/pcbnew/menubar_pcbframe.cpp +++ b/pcbnew/menubar_pcbframe.cpp @@ -534,8 +534,8 @@ void PCB_EDIT_FRAME::ReCreateMenuBar() #if defined(KICAD_SCRIPTING_WXPYTHON) AddMenuItem( toolsMenu, ID_TOOLBARH_PCB_SCRIPTING_CONSOLE, _( "&Scripting Console" ), - _( "Show/Hide the Scripting console" ), - KiBitmap( book_xpm ) ); + _( "Show/Hide the Python Scripting console" ), + KiBitmap( py_script_xpm ) ); #endif wxMenu* designRulesMenu = new wxMenu; diff --git a/pcbnew/pcbframe.cpp b/pcbnew/pcbframe.cpp index d9f4791969..9401749085 100644 --- a/pcbnew/pcbframe.cpp +++ b/pcbnew/pcbframe.cpp @@ -72,6 +72,8 @@ #if defined(KICAD_SCRIPTING) || defined(KICAD_SCRIPTING_WXPYTHON) #include +// The name of the pane info handling the python console: +#define PYTHONCONSOLE_STRID wxT( "PythonPanel" ) #endif #include @@ -203,6 +205,8 @@ BEGIN_EVENT_TABLE( PCB_EDIT_FRAME, PCB_BASE_FRAME ) EVT_TOOL( ID_TOOLBARH_PCB_FREEROUTE_ACCESS, PCB_EDIT_FRAME::Access_to_External_Tool ) #ifdef KICAD_SCRIPTING_WXPYTHON EVT_TOOL( ID_TOOLBARH_PCB_SCRIPTING_CONSOLE, PCB_EDIT_FRAME::ScriptingConsoleEnableDisable ) + EVT_UPDATE_UI( ID_TOOLBARH_PCB_SCRIPTING_CONSOLE, + PCB_EDIT_FRAME::OnUpdateScriptingConsoleState ) #endif // Option toolbar EVT_TOOL( ID_TB_OPTIONS_DRC_OFF, @@ -319,10 +323,6 @@ PCB_EDIT_FRAME::PCB_EDIT_FRAME( KIWAY* aKiway, wxWindow* aParent ) : m_rotationAngle = 900; -#ifdef KICAD_SCRIPTING_WXPYTHON - m_pythonPanel = NULL; -#endif - for ( int i = 0; i < 10; i++ ) m_Macros[i].m_Record.clear(); @@ -415,7 +415,8 @@ PCB_EDIT_FRAME::PCB_EDIT_FRAME( KIWAY* aKiway, wxWindow* aParent ) : if( m_microWaveToolBar ) // The auxiliary vertical right toolbar (currently microwave tools) m_auimgr.AddPane( m_microWaveToolBar, - wxAuiPaneInfo( vert ).Name( wxT( "m_microWaveToolBar" ) ).Right().Layer( 1 ).Position(1).Hide() ); + wxAuiPaneInfo( vert ).Name( wxT( "m_microWaveToolBar" ) ). + Right().Layer( 1 ).Position(1).Hide() ); if( m_drawToolBar ) // The main right vertical toolbar m_auimgr.AddPane( m_drawToolBar, @@ -448,18 +449,25 @@ PCB_EDIT_FRAME::PCB_EDIT_FRAME( KIWAY* aKiway, wxWindow* aParent ) : #if defined(KICAD_SCRIPTING_WXPYTHON) // Add the scripting panel - EDA_PANEINFO pythonAuiInfo; - pythonAuiInfo.ScriptingToolbarPane(); - pythonAuiInfo.Caption( wxT( "Python Scripting" ) ); - pythonAuiInfo.MinSize( wxSize( 200, 100 ) ); - pythonAuiInfo.BestSize( wxSize( GetClientSize().x/2, 200 ) ); - pythonAuiInfo.Hide(); + EDA_PANEINFO pythonAuiPane; + pythonAuiPane.ScriptingToolbarPane(); + pythonAuiPane.Caption( wxT( "Python Scripting" ) ); + pythonAuiPane.MinSize( 300, 100 ); + pythonAuiPane.BestSize( 600, 200 ); - m_pythonPanel = CreatePythonShellWindow( this ); - m_auimgr.AddPane( m_pythonPanel, - pythonAuiInfo.Name( wxT( "PythonPanel" ) ).Bottom().Layer(9) ); + // The console is not dockable. Reasons: + // * When docked there is an issue with accelerator keys used in the main menu: + // these keys are not sent to the console, even if it has the focus + // * The console is more easy to move, resize, ... if it is not dockable + pythonAuiPane.Float().Dockable( false ); + + pythonAuiPane.Hide(); + m_pythonPanelShow = false; + + wxWindow *pythonPanel = CreatePythonShellWindow( this ); + m_auimgr.AddPane( pythonPanel, + pythonAuiPane.Name( PYTHONCONSOLE_STRID ).Bottom().Layer(9) ); - m_pythonPanelHidden = true; #endif ReFillLayerWidget(); // this is near end because contents establish size @@ -1093,16 +1101,8 @@ void PCB_EDIT_FRAME::UpdateTitle() #if defined(KICAD_SCRIPTING_WXPYTHON) void PCB_EDIT_FRAME::ScriptingConsoleEnableDisable( wxCommandEvent& aEvent ) { - if ( m_pythonPanelHidden ) - { - m_auimgr.GetPane( m_pythonPanel ).Show(); - m_pythonPanelHidden = false; - } - else - { - m_auimgr.GetPane( m_pythonPanel ).Hide(); - m_pythonPanelHidden = true; - } + m_pythonPanelShow = ! m_pythonPanelShow; + m_auimgr.GetPane( PYTHONCONSOLE_STRID ).Show( m_pythonPanelShow ); m_auimgr.Update(); diff --git a/pcbnew/tool_pcb.cpp b/pcbnew/tool_pcb.cpp index 90c2cf6ee8..ab77b42d1f 100644 --- a/pcbnew/tool_pcb.cpp +++ b/pcbnew/tool_pcb.cpp @@ -307,16 +307,16 @@ void PCB_EDIT_FRAME::ReCreateHToolbar() KiBitmap( web_support_xpm ), _( "Fast access to the Web Based FreeROUTE advanced router" ) ); - m_mainToolBar->AddSeparator(); - // Access to the scripting console #ifdef KICAD_SCRIPTING_WXPYTHON + m_mainToolBar->AddSeparator(); + m_mainToolBar->AddTool( ID_TOOLBARH_PCB_SCRIPTING_CONSOLE, wxEmptyString, KiBitmap( py_script_xpm ), - _( "Show/Hide the Scripting console" ) ); - - m_mainToolBar->AddSeparator(); + _( "Show/Hide the Python Scripting console" ), + wxITEM_CHECK ); #endif + // after adding the buttons to the toolbar, must call Realize() to reflect the changes m_mainToolBar->Realize(); } diff --git a/pcbnew/toolbars_update_user_interface.cpp b/pcbnew/toolbars_update_user_interface.cpp index b94bc75d59..a33915fe4b 100644 --- a/pcbnew/toolbars_update_user_interface.cpp +++ b/pcbnew/toolbars_update_user_interface.cpp @@ -109,6 +109,12 @@ void PCB_EDIT_FRAME::OnUpdateLayerSelectBox( wxUpdateUIEvent& aEvent ) m_SelLayerBox->SetLayerSelection( GetActiveLayer() ); } +#ifdef KICAD_SCRIPTING_WXPYTHON +void PCB_EDIT_FRAME::OnUpdateScriptingConsoleState( wxUpdateUIEvent& aEvent ) +{ + aEvent.Check( m_pythonPanelShow ); +} +#endif void PCB_EDIT_FRAME::OnUpdateZoneDisplayStyle( wxUpdateUIEvent& aEvent ) {