Salome HOME
Porting to Mandrake 10.1 and new products:
[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
13
14
15 #include "QAD_PyInterp_mono.h" // this include must be first (see PyInterp_base.h)!
16 #include "utilities.h"
17
18 using namespace std;
19
20 /*!
21  * constructor : only one Python interpreter, shared within SALOME studies.
22  * calls initialize method defined in base class, which calls virtual methods
23  * initstate & initcontext redefined here.
24  */
25 QAD_PyInterp_mono::QAD_PyInterp_mono(): PyInterp_base()
26 {
27 }
28
29 QAD_PyInterp_mono::~QAD_PyInterp_mono()
30 {
31 }
32
33 /*!
34  * EDF-CCAR
35  * When SALOME uses mono  Python interpreter feature,
36  * every study has its own context (dictionnary) but shares builtins
37  * and all the modules (sys, ...) with other studies.
38  * A module imported in a study is seen in another study (pros ans cons !).
39  */
40
41 void QAD_PyInterp_mono::initState()
42 {
43   _tstate = PyThreadState_Get();
44   PySys_SetArgv(PyInterp_base::_argc,PyInterp_base::_argv);      // initialize sys.argv
45 }
46
47 void QAD_PyInterp_mono::initContext()
48 {
49   _g = PyDict_New();          // create interpreter dictionnary context
50   PyObject *bimod = PyImport_ImportModule("__builtin__");
51   PyDict_SetItemString(_g, "__builtins__", bimod);
52   Py_DECREF(bimod);
53 }
54