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