]> SALOME platform Git repositories - modules/kernel.git/blob - src/SALOMEGUI/QAD_PyInterp_mono.cxx
Salome HOME
This commit was generated by cvs2git to track changes on a CVS vendor
[modules/kernel.git] / src / SALOMEGUI / QAD_PyInterp_mono.cxx
1 using namespace std;
2 using namespace std;
3 //=============================================================================
4 // File      : QAD_PyInterp_mono.cxx
5 // Created   : ven fév  7 10:01:36 CET 2003
6 // Author    : Paul RASCLE, EDF
7 // Project   : SALOME
8 // Copyright : EDF 2003
9 // $Header$
10 //=============================================================================
11
12 #include "QAD_PyInterp_mono.h"
13 #include "utilities.h"
14
15 /*!
16  * constructor : only one Python interpreter, shared within SALOME studies.
17  * calls initialize method defined in base class, which calls virtual methods
18  * initstate & initcontext redefined here.
19  */
20 QAD_PyInterp_mono::QAD_PyInterp_mono(): PyInterp_base()
21 {
22   initialize();
23 }
24
25 QAD_PyInterp_mono::~QAD_PyInterp_mono()
26 {
27 }
28
29 /*!
30  * EDF-CCAR
31  * When SALOME uses mono  Python interpreter feature,
32  * every study has its own context (dictionnary) but shares builtins
33  * and all the modules (sys, ...) with other studies.
34  * A module imported in a study is seen in another study (pros ans cons !).
35  */
36
37 void QAD_PyInterp_mono::initState()
38 {
39   salomeAcquireLock(); //acquire python global lock (one for all interpreters)
40   _tstate = PyThreadState_Get();
41   PySys_SetArgv(PyInterp_base::_argc,PyInterp_base::_argv);      // initialize sys.argv
42 }
43
44 void QAD_PyInterp_mono::initContext()
45 {
46   _g = PyDict_New();          // create interpreter dictionnary context
47   PyObject *bimod = PyImport_ImportModule("__builtin__");
48   PyDict_SetItemString(_g, "__builtins__", bimod);
49   Py_DECREF(bimod);
50 }
51