Salome HOME
DCQ : Update msg File.
[modules/kernel.git] / src / SALOMEGUI / PyInterp_PyQt.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   : PyInterp_PyQt.cxx
8 //  Author : Christian CAREMOLI, Paul RASCLE, EDF
9 //  Module : SALOME
10 //  $Header$
11
12 #include "PyInterp_PyQt.h"
13 #include "utilities.h"
14
15 using namespace std;
16
17
18 /*!
19  * constructor : the main SALOME Python interpreter is used for PyQt GUI.
20  * calls initialize method defined in base class, which calls virtual methods
21  * initstate & initcontext redefined here
22  */
23 PyInterp_PyQt::PyInterp_PyQt(): PyInterp_base()
24 {
25   initialize();
26 }
27
28 PyInterp_PyQt::~PyInterp_PyQt()
29 {
30 }
31
32 void PyInterp_PyQt::initState()
33 {
34   SCRUTE(PyInterp_base::_gtstate);
35   _tstate=PyInterp_base::_gtstate;
36   PyThreadState_Swap(_tstate);
37   SCRUTE(_tstate);
38 }
39
40 void PyInterp_PyQt::initContext()
41 {
42   _g = PyDict_New();          // create interpreter dictionnary context
43   PyObject *bimod = PyImport_ImportModule("__builtin__");
44   PyDict_SetItemString(_g, "__builtins__", bimod);
45   Py_DECREF(bimod);
46 }
47
48 void PyInterp_PyQt::run(const char *command)
49 {
50   MESSAGE("compile");
51   PyLockWrapper aLock(_tstate);
52   PyObject *code = Py_CompileString((char *)command,"PyGUI",Py_file_input);
53   if(!code){
54     // Une erreur s est produite en general SyntaxError
55     PyErr_Print();
56     return;
57   }
58   PyObject *r = PyEval_EvalCode(code,_g,_g);
59   Py_DECREF(code);
60   if(!r){
61     // Une erreur s est produite a l execution
62     PyErr_Print();
63     return;
64   }
65   Py_DECREF(r);
66 }
67