From a1fa90265a9547632231586ad5bc760d3762bdbf Mon Sep 17 00:00:00 2001 From: vsr Date: Fri, 25 Oct 2013 08:42:19 +0000 Subject: [PATCH] Add function to allow execute Python code in embeeded SALOME Python console or in ParaView Python console --- src/PVGUI/PVGUI_Module.cxx | 53 ++++++++++++++++++-------------------- src/PVGUI/PVGUI_Module.h | 3 +++ 2 files changed, 28 insertions(+), 28 deletions(-) diff --git a/src/PVGUI/PVGUI_Module.cxx b/src/PVGUI/PVGUI_Module.cxx index 5aa1d7b9..e2d8bd34 100644 --- a/src/PVGUI/PVGUI_Module.cxx +++ b/src/PVGUI/PVGUI_Module.cxx @@ -66,6 +66,7 @@ #include #include #include +#include #include #include @@ -635,15 +636,16 @@ void PVGUI_Module::onVariableChanged(pqVariableType t, const QString) { } } - -/*! - \brief Launches a tracing of current server -*/ -void PVGUI_Module::timerEvent(QTimerEvent* te ) +void PVGUI_Module::execPythonCommand(const QString& cmd, bool inSalomeConsole) { -#ifndef WNT - PyInterp_Dispatcher* aDispatcher = PyInterp_Dispatcher::Get(); - if ( !aDispatcher->IsBusy() ) { + if ( inSalomeConsole ) { + SalomeApp_Application* app = + dynamic_cast< SalomeApp_Application* >(SUIT_Session::session()->activeApplication()); + PyConsole_Console* pyConsole = app->pythonConsole(); + if (pyConsole) + pyConsole->exec(cmd); + } + else { pqPythonManager* manager = qobject_cast ( pqApplicationCore::instance()->manager( "PYTHON_MANAGER" ) ); if ( manager ) { @@ -651,13 +653,21 @@ void PVGUI_Module::timerEvent(QTimerEvent* te ) if ( pyDiag ) { pqPythonShell* shell = pyDiag->shell(); if ( shell ) { - QString script = "from paraview import smtrace\nsmtrace.start_trace()\n"; - shell->executeScript(script); - killTimer( te->timerId() ); + shell->executeScript(cmd); } } } } +} + +/*! + \brief Launches a tracing of current server +*/ +void PVGUI_Module::timerEvent(QTimerEvent* te ) +{ +#ifndef WNT + execPythonCommand("from paraview import smtrace\nsmtrace.start_trace()\n", false); + killTimer( te->timerId() ); #endif } @@ -1346,23 +1356,10 @@ void PVGUI_Module::onShowTrace() */ void PVGUI_Module::onRestartTrace() { - PyInterp_Dispatcher* aDispatcher = PyInterp_Dispatcher::Get(); - if ( !aDispatcher->IsBusy() ) { - pqPythonManager* manager = qobject_cast - ( pqApplicationCore::instance()->manager( "PYTHON_MANAGER" ) ); - if ( manager ) { - pqPythonDialog* pyDiag = manager->pythonShellDialog(); - if ( pyDiag ) { - pqPythonShell* shell = pyDiag->shell(); - if ( shell ) { - QString script = "from paraview import smtrace\n"; - script += "smtrace.stop_trace()\n"; - script += "smtrace.start_trace()\n"; - shell->executeScript(script); - } - } - } - } + QString script = "from paraview import smtrace\n"; + script += "smtrace.stop_trace()\n"; + script += "smtrace.start_trace()\n"; + execPythonCommand(script, false); } /*! diff --git a/src/PVGUI/PVGUI_Module.h b/src/PVGUI/PVGUI_Module.h index b56bf235..cf760389 100644 --- a/src/PVGUI/PVGUI_Module.h +++ b/src/PVGUI/PVGUI_Module.h @@ -217,6 +217,9 @@ private: //! restore visibility of the common dockable windows (OB, PyConsole, ... etc.) void restoreCommonWindowsState(); + //! run Python command + void execPythonCommand(const QString& cmd, bool inSalomeConsole = false); + private slots: void showHelpForProxy( const QString&, const QString& ); -- 2.39.2