Back to index

salome-gui  6.5.0
LightApp_PyInterp.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // This library is free software; you can redistribute it and/or
00004 // modify it under the terms of the GNU Lesser General Public
00005 // License as published by the Free Software Foundation; either
00006 // version 2.1 of the License.
00007 //
00008 // This library is distributed in the hope that it will be useful,
00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011 // Lesser General Public License for more details.
00012 //
00013 // You should have received a copy of the GNU Lesser General Public
00014 // License along with this library; if not, write to the Free Software
00015 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00016 //
00017 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00018 //
00019 
00020 //  Author : Roman NIKOLAEV, Open CASCADE S.A.S. (roman.nikolaev@opencascade.com)
00021 //  Date   : 22/06/2007
00022 //
00023 #include "LightApp_PyInterp.h"
00024 
00025 #include <SUITApp_init_python.hxx>
00026 #include <PyConsole_Interp.h>
00027 
00028 #include <pthread.h>
00029 
00035 LightApp_PyInterp::LightApp_PyInterp(): PyConsole_Interp()
00036 {
00037 }
00038 
00042 LightApp_PyInterp::~LightApp_PyInterp()
00043 {
00044 }
00045  
00065 bool LightApp_PyInterp::initContext()
00066 {
00072   if ( !PyConsole_Interp::initContext() )
00073     return false;
00074   
00075   //Import special module to change the import mechanism
00076   PyObjWrapper m1( PyImport_ImportModule( "import_hook" ) );
00077   if ( !m1 )
00078   {
00079     PyErr_Print();
00080     return false;
00081     }
00082   
00083   // Call init_shared_modules to initialize the shared import mechanism for modules 
00084   //that must not be imported twice
00085   PyObjWrapper m2( PyObject_CallMethod( m1, (char*)"init_shared_modules", (char*)"O", SUIT_PYTHON::salome_shared_modules_module ) );
00086   if ( !m2 )
00087   {
00088     PyErr_Print();
00089     return false;
00090   }
00091   return true;
00092 }
00093 
00098 void LightApp_PyInterp::initPython()
00099 {
00100   _gtstate=SUIT_PYTHON::_gtstate; // initialisation in main
00101   _interp=SUIT_PYTHON::_interp;
00102 }