From a5308e5f5ca8fb881976e6cb1daa842da34c458d Mon Sep 17 00:00:00 2001 From: david-beinder Date: Fri, 2 Jul 2021 21:05:16 +0200 Subject: [PATCH] Fix python console toggle to work across pcbnew/eeschema --- common/eda_draw_frame.cpp | 6 ++++++ common/tool/editor_conditions.cpp | 15 +++++++++++++++ eeschema/sch_edit_frame.cpp | 4 ++++ include/eda_draw_frame.h | 5 +++++ include/tool/editor_conditions.h | 14 +++++++++++--- pcbnew/pcb_edit_frame.cpp | 17 +++-------------- pcbnew/pcb_edit_frame.h | 19 ------------------- 7 files changed, 44 insertions(+), 36 deletions(-) diff --git a/common/eda_draw_frame.cpp b/common/eda_draw_frame.cpp index a5b07c8392..80d943c010 100644 --- a/common/eda_draw_frame.cpp +++ b/common/eda_draw_frame.cpp @@ -234,7 +234,13 @@ void EDA_DRAW_FRAME::ScriptingConsoleEnableDisable() } frame->Show( !frame->IsVisible() ); +} + +bool EDA_DRAW_FRAME::IsScriptingConsoleVisible() +{ + KIWAY_PLAYER* frame = Kiway().Player( FRAME_PYTHON, false ); + return frame && frame->IsVisible(); } diff --git a/common/tool/editor_conditions.cpp b/common/tool/editor_conditions.cpp index dcd2cc6d72..b09d4271eb 100644 --- a/common/tool/editor_conditions.cpp +++ b/common/tool/editor_conditions.cpp @@ -104,6 +104,16 @@ SELECTION_CONDITION EDITOR_CONDITIONS::FullscreenCursor() } +SELECTION_CONDITION EDITOR_CONDITIONS::ScriptingConsoleVisible() +{ + EDA_DRAW_FRAME* drwFrame = dynamic_cast( m_frame ); + + wxASSERT( drwFrame ); + + return std::bind( &EDITOR_CONDITIONS::consoleVisibleFunc, _1, drwFrame ); +} + + bool EDITOR_CONDITIONS::contentModifiedFunc( const SELECTION& aSelection, EDA_BASE_FRAME* aFrame ) { return aFrame->IsContentModified(); @@ -159,3 +169,8 @@ bool EDITOR_CONDITIONS::cursorFunc( const SELECTION& aSelection, EDA_DRAW_FRAME* return aFrame->GetGalDisplayOptions().m_fullscreenCursor; } + +bool EDITOR_CONDITIONS::consoleVisibleFunc( const SELECTION& aSelection, EDA_DRAW_FRAME* aFrame ) +{ + return aFrame->IsScriptingConsoleVisible(); +} diff --git a/eeschema/sch_edit_frame.cpp b/eeschema/sch_edit_frame.cpp index cd07dcb3c4..8a1907482a 100644 --- a/eeschema/sch_edit_frame.cpp +++ b/eeschema/sch_edit_frame.cpp @@ -45,6 +45,7 @@ #include #include #include +#include #include #include #include @@ -412,6 +413,9 @@ void SCH_EDIT_FRAME::setupUIConditions() mgr->SetConditions( ACTIONS::zoomTool, CHECK( cond.CurrentTool( ACTIONS::zoomTool ) ) ); mgr->SetConditions( ACTIONS::selectionTool, CHECK( cond.CurrentTool( ACTIONS::selectionTool ) ) ); + if( SCRIPTING::IsWxAvailable() ) + mgr->SetConditions( EE_ACTIONS::showPythonConsole, CHECK( cond.ScriptingConsoleVisible() ) ); + auto showHiddenPinsCond = [this] ( const SELECTION& ) { diff --git a/include/eda_draw_frame.h b/include/eda_draw_frame.h index f72678a09c..00bba67bd9 100644 --- a/include/eda_draw_frame.h +++ b/include/eda_draw_frame.h @@ -97,6 +97,11 @@ public: */ void ScriptingConsoleEnableDisable(); + /** + * Gets the current visibility of the scripting console window + */ + bool IsScriptingConsoleVisible(); + wxFindReplaceData& GetFindReplaceData() { return *m_findReplaceData; } wxArrayString& GetFindHistoryList() { return m_findStringHistoryList; } diff --git a/include/tool/editor_conditions.h b/include/tool/editor_conditions.h index 6c565f44a0..11a893f65b 100644 --- a/include/tool/editor_conditions.h +++ b/include/tool/editor_conditions.h @@ -118,6 +118,15 @@ public: */ SELECTION_CONDITION FullscreenCursor(); + /** + * Create a functor testing if the python scripting console window is visible. + * + * @note This requires the frame passed into the constructor be be derived from EDA_DRAW_FRAME. + * + * @return Functor testing if the python scripting console window is visible + */ + SELECTION_CONDITION ScriptingConsoleVisible(); + protected: ///< Helper function used by ContentModified(). static bool contentModifiedFunc( const SELECTION& aSelection, EDA_BASE_FRAME* aFrame ); @@ -147,9 +156,8 @@ protected: ///< Helper function used by FullscreenCursor(). static bool cursorFunc( const SELECTION& aSelection, EDA_DRAW_FRAME* aFrame ); - ///< Helper function used by CanvasType(). - static bool canvasTypeFunc( const SELECTION& aSelection, EDA_DRAW_FRAME* aFrame, - EDA_DRAW_PANEL_GAL::GAL_TYPE aType ); + ///< Helper function used by ScriptingConsoleVisible(). + static bool consoleVisibleFunc( const SELECTION& aSelection, EDA_DRAW_FRAME* aFrame ); ///< The frame to apply the conditions to. EDA_BASE_FRAME* m_frame; diff --git a/pcbnew/pcb_edit_frame.cpp b/pcbnew/pcb_edit_frame.cpp index 28f5a38413..6c1c32c62c 100644 --- a/pcbnew/pcb_edit_frame.cpp +++ b/pcbnew/pcb_edit_frame.cpp @@ -551,20 +551,9 @@ void PCB_EDIT_FRAME::setupUIConditions() mgr->SetConditions( PCB_ACTIONS::viaDisplayMode, CHECK( !cond.ViaFillDisplay() ) ); mgr->SetConditions( PCB_ACTIONS::trackDisplayMode, CHECK( !cond.TrackFillDisplay() ) ); - auto pythonConsoleCond = - [] ( const SELECTION& ) - { - if( SCRIPTING::IsWxAvailable() ) - { - wxWindow* console = PCB_EDIT_FRAME::findPythonConsole(); - return console && console->IsShown(); - } - - return false; - }; - - mgr->SetConditions( PCB_ACTIONS::showPythonConsole, CHECK( pythonConsoleCond ) ); - + if( SCRIPTING::IsWxAvailable() ) + mgr->SetConditions( PCB_ACTIONS::showPythonConsole, CHECK( cond.ScriptingConsoleVisible() ) ); + auto enableZoneControlConition = [this] ( const SELECTION& ) { diff --git a/pcbnew/pcb_edit_frame.h b/pcbnew/pcb_edit_frame.h index 9b6646531a..89e3fea57c 100644 --- a/pcbnew/pcb_edit_frame.h +++ b/pcbnew/pcb_edit_frame.h @@ -707,25 +707,6 @@ protected: */ void OnActionPluginButton( wxCommandEvent& aEvent ); - - /** - * Has meaning only if KICAD_SCRIPTING_WXPYTHON option is not defined. - * - * @return the frame name identifier for the python console frame. - */ - static const wxChar * pythonConsoleNameId() - { - return wxT( "PythonConsole" ); - } - - /** - * @return a pointer to the python console frame, or NULL if not exist - */ - static wxWindow * findPythonConsole() - { - return FindWindowByName( pythonConsoleNameId() ); - } - /** * Update the state of the GUI after a new board is loaded or created. */