[StdCmdSendToPythonConsole] make python console visible if not already visible and set keyboard focus to it when invoking the send to python console command

This commit is contained in:
mwganson
2021-12-08 18:05:49 -06:00
committed by wmayer
parent b7237f6876
commit f803c242a9

View File

@@ -22,12 +22,17 @@
#include "PreCompiled.h"
#ifndef _PreComp_
# include <QAction>
# include <QDockWidget>
#endif
#include <App/DocumentObject.h>
#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<PythonConsole*>(pc);
if (pcPython){
QDockWidget* dw = nullptr;
QWidget* par = pcPython->parentWidget();
while (par){
dw = qobject_cast<QDockWidget*>(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();