]> SALOME platform Git repositories - modules/paravis.git/commitdiff
Salome HOME
Add function to allow execute Python code in embeeded SALOME Python console or in...
authorvsr <vsr@opencascade.com>
Fri, 25 Oct 2013 08:42:19 +0000 (08:42 +0000)
committervsr <vsr@opencascade.com>
Fri, 25 Oct 2013 08:42:19 +0000 (08:42 +0000)
src/PVGUI/PVGUI_Module.cxx
src/PVGUI/PVGUI_Module.h

index 5aa1d7b914e741670b4ac31e978f03d2b39f4bec..e2d8bd34a72211aea4a7e160e3a20cff4afc6ee9 100644 (file)
@@ -66,6 +66,7 @@
 #include <SALOME_ListIO.hxx>
 #include <SALOMEDS_Tool.hxx>
 #include <PyInterp_Dispatcher.h>
+#include <PyConsole_Console.h>
 
 #include <QtxActionMenuMgr.h>
 #include <QtxActionToolMgr.h>
@@ -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<pqPythonManager*>
       ( 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<pqPythonManager*>
-       ( 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);
 }
 
 /*!
index b56bf235423f093b3f7e8280067d8718dfe76a04..cf760389b9a19a71246f7817d7f34918f12b4551 100644 (file)
@@ -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& );