Salome HOME
According to cotech80 PyConsoleBase->PyConsole and PyConsole->SalomePyConsole
[modules/gui.git] / src / PyConsole / PyConsole_Interp.cxx
index 10e6fa0e623c7dfb1483e5f68a5f155516ccb648..ca459b5827d8334d8d4c801a3fd546ab8fbeb669 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2013  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2015  CEA/DEN, EDF R&D, OPEN CASCADE
 //
 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
@@ -6,7 +6,7 @@
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
 // License as published by the Free Software Foundation; either
-// version 2.1 of the License.
+// version 2.1 of the License, or (at your option) any later version.
 //
 // This library is distributed in the hope that it will be useful,
 // but WITHOUT ANY WARRANTY; without even the implied warranty of
 //
 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
-
-//  SALOME SALOMEGUI : implementation of desktop and GUI kernel
 //  File   : PyConsole_Interp.cxx
-//  Author : Nicolas REJNERI
-//  Module : SALOME
-//
+//  Author : Nicolas REJNERI, Adrien BRUNETON
+
 #include "PyConsole_Interp.h"
 
 /*!
@@ -38,7 +35,6 @@
 
   The method initialize() calls virtuals methods
   - initPython()  to initialize global Python interpreter
-  //- initState()   to initialize embedded interpreter state (OBSOLETE)
   - initContext() to initialize interpreter internal context
   - initRun()     to prepare interpreter for running commands
 */
@@ -60,24 +56,38 @@ PyConsole_Interp::PyConsole_Interp(): PyInterp_Interp()
 PyConsole_Interp::~PyConsole_Interp()
 {
 }
+
+/*! Sets the variable "__IN_SALOME_GUI_CONSOLE" to True.
+* This is not attached to a module (like salome_iapp.IN_SALOME_GUI_CONSOLE)
+* since modules are shared across all interpreters in SALOME.
+*
+* (GIL is already acquired here)
+*/
+int PyConsole_Interp::beforeRun()
+{
+  return PyRun_SimpleString("__builtins__.__IN_SALOME_GUI_CONSOLE=True");
+}
  
-/*!
-  \brief Initialize python interpeter context.
+int PyConsole_Interp::afterRun()
+{
+  return PyRun_SimpleString("__builtins__.__IN_SALOME_GUI_CONSOLE=False");
+}
 
-  The GIL is assumed to be held.
-  It is the caller responsability to acquire the GIL.
-  It must still be held on initContext() exit.
+QStringList PyConsole_Interp::getLastMatches() const
+{
+  return QStringList();
+}
 
-  \return \c true on success
-*/
-bool PyConsole_Interp::initContext()
+QString PyConsole_Interp::getDocStr() const
+{
+  return QString();
+}
+
+int PyConsole_Interp::runDirCommand(const QString&, const QString& )
+{
+  return 0;
+}
+
+void PyConsole_Interp::clearCompletion()
 {
-  PyObject *m = PyImport_AddModule("__main__");  // interpreter main module (module context)
-  if(!m){
-    PyErr_Print();
-    return false;
-  }  
-  PyObject* global_dict = PyModule_GetDict(m);          // get interpreter dictionnary context
-  _context = PyDict_Copy(global_dict);
-  return true;
 }