From f803c242a9993a1ba768496717637952a24163c5 Mon Sep 17 00:00:00 2001 From: mwganson Date: Wed, 8 Dec 2021 18:05:49 -0600 Subject: [PATCH] [StdCmdSendToPythonConsole] make python console visible if not already visible and set keyboard focus to it when invoking the send to python console command --- src/Gui/CommandFeat.cpp | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/src/Gui/CommandFeat.cpp b/src/Gui/CommandFeat.cpp index 6cd4089f1b..a6729776d0 100644 --- a/src/Gui/CommandFeat.cpp +++ b/src/Gui/CommandFeat.cpp @@ -22,12 +22,17 @@ #include "PreCompiled.h" +#ifndef _PreComp_ +# include +# include +#endif #include - #include "Application.h" #include "CommandT.h" +#include "DockWindowManager.h" #include "Document.h" +#include "PythonConsole.h" #include "Selection.h" #include "ViewProvider.h" #include "ViewProviderDocumentObject.h" @@ -161,6 +166,24 @@ void StdCmdSendToPythonConsole::activated(int iMsg) Gui::Command::runCommand(Gui::Command::Gui,cmd.toLatin1()); } } + //show the python console if it's not already visible, and set the keyboard focus to it + QWidget* pc = DockWindowManager::instance()->getDockWindow("Python console"); + PythonConsole *pcPython = qobject_cast(pc); + if (pcPython){ + QDockWidget* dw = nullptr; + QWidget* par = pcPython->parentWidget(); + while (par){ + dw = qobject_cast(par); + if (dw){ + break; + } + par = par->parentWidget(); + } + if (dw && !dw->toggleViewAction()->isChecked()){ + dw->toggleViewAction()->activate(QAction::Trigger); + } + pcPython->setFocus(); + } } catch (const Base::Exception& e) { e.ReportException();