]> SALOME platform Git repositories - modules/kernel.git/commitdiff
Salome HOME
Latest corrections (from Event_Server branch) Ecole_Ete_a2
authorsmh <smh@opencascade.com>
Fri, 30 Apr 2004 14:18:51 +0000 (14:18 +0000)
committersmh <smh@opencascade.com>
Fri, 30 Apr 2004 14:18:51 +0000 (14:18 +0000)
src/SALOMEGUI/PyInterp_base.cxx
src/SALOMEGUI/QAD_PyEditor.cxx
src/SALOMEGUI/QAD_PyEditor.h
src/SALOMEGUI/QAD_Study.cxx

index d460ee541ecf3836478c75a0f0f861c0252fb0f8..032be6aeb99d70e73a79add1ad9a706fd1520cea 100644 (file)
@@ -26,8 +26,10 @@ using namespace std;
 
 #ifdef _DEBUG_
 static int MYDEBUG = 0;
+static int MYPYDEBUG = 0;
 #else
 static int MYDEBUG = 0;
+static int MYPYDEBUG = 0;
 #endif
 
 
@@ -38,32 +40,14 @@ PyLockWrapper::PyLockWrapper(PyThreadState* theThreadState):
   myThreadState(theThreadState),
   mySaveThreadState(PyInterp_base::_gtstate)
 {
-  //if(MYDEBUG) MESSAGE(" PyLockWrapper(...) - myThreadState = "<<myThreadState<<" - "<<myMutex.locked());
-  //myMutex.lock();
-  //PyEval_RestoreThread(myThreadState);
-
   PyEval_AcquireLock();
   mySaveThreadState = PyThreadState_Swap(myThreadState);
-
-  //PyEval_SaveThread();
-
-  //mySaveThreadState = PyThreadState_Swap(myThreadState);
-  //PyEval_ReleaseLock();
 }
 
 
 PyLockWrapper::~PyLockWrapper(){
-  //if(MYDEBUG) MESSAGE("~PyLockWrapper(...) - myThreadState = "<<myThreadState);
-  //PyEval_SaveThread();
-  //myMutex.unlock();
-
   PyThreadState_Swap(mySaveThreadState);
   PyEval_ReleaseLock();
-
-  //PyEval_RestoreThread(myThreadState);
-
-  //PyEval_AcquireLock();
-  //PyThreadState_Swap(mySaveThreadState);
 }
 
 
@@ -95,16 +79,14 @@ ThreadLock GetPyThreadLock(const char* theComment){
 class PyReleaseLock{
 public:
   ~PyReleaseLock(){
-    //if(MYDEBUG) MESSAGE("~PyReleaseLock()");
-    //PyEval_SaveThread();
-
+    if(MYPYDEBUG) MESSAGE("~PyReleaseLock()");
     PyEval_ReleaseLock();
   }
 };
 
 
 PyLockWrapper PyInterp_base::GetLockWrapper(){
-  return PyLockWrapper(_tstate);
+  return _tstate;
 }
 
 
@@ -124,15 +106,14 @@ PyObject *PyInterp_base::salome_shared_modules_module = NULL;
  */
 PyInterp_base::PyInterp_base(): _tstate(0), _vout(0), _verr(0), _g(0), _atFirst(true)
 {
-  //if(MYDEBUG) MESSAGE("PyInterp_base::PyInterp_base() - this = "<<this);
+  if(MYPYDEBUG) MESSAGE("PyInterp_base::PyInterp_base() - this = "<<this);
 }
 
 PyInterp_base::~PyInterp_base()
 {
-  if(MYDEBUG) MESSAGE("PyInterp_base::~PyInterp_base() - this = "<<this);
+  if(MYPYDEBUG) MESSAGE("PyInterp_base::~PyInterp_base() - this = "<<this);
   PyLockWrapper aLock(_tstate);
-  PyThreadState_Swap(_tstate);
-  Py_EndInterpreter(_tstate);
+  //Py_EndInterpreter(_tstate);
 }
 
 
@@ -154,11 +135,11 @@ void PyInterp_base::initialize()
     PySys_SetArgv(_argc,_argv); // initialize sys.argv
     _gtstate = PyThreadState_Get();
   }
-  //if(MYDEBUG) MESSAGE("PyInterp_base::initialize() - this = "<<this<<"; _gtstate = "<<_gtstate);
+  if(MYPYDEBUG) MESSAGE("PyInterp_base::initialize() - this = "<<this<<"; _gtstate = "<<_gtstate);
 
   salome_shared_modules_module = PyImport_ImportModule("salome_shared_modules");
   if(!salome_shared_modules_module){
-    if(MYDEBUG) MESSAGE("init_python: problem with salome_shared_modules import");
+    INFOS("PyInterp_base::initialize() - salome_shared_modules_module == NULL");
     PyErr_Print();
     PyErr_Clear();
   }
@@ -170,7 +151,7 @@ void PyInterp_base::initialize()
   // used to interpret & compile commands
   PyObjWrapper m(PyImport_ImportModule("codeop"));
   if(!m){
-    if(MYDEBUG)  MESSAGE("Problem...");
+    INFOS("PyInterp_base::initialize() - PyImport_ImportModule('codeop') failed");
     PyErr_Print();
     ASSERT(0);
     return;
@@ -209,7 +190,7 @@ int PyInterp_base::initRun()
   PySys_SetObject("stdout",PySys_GetObject("__stdout__"));
   PySys_SetObject("stderr",PySys_GetObject("__stderr__"));
 
-  //if(MYDEBUG) MESSAGE("PyInterp_base::initRun() - this = "<<this<<"; _verr = "<<_verr<<"; _vout = "<<_vout);
+  if(MYPYDEBUG) MESSAGE("PyInterp_base::initRun() - this = "<<this<<"; _verr = "<<_verr<<"; _vout = "<<_vout);
   return 0;
 }
 
@@ -288,7 +269,6 @@ int PyInterp_base::simpleRun(const char *command)
   PyObjWrapper vout(PyObject_CallMethod(_vout,"reset",""));
   
   int ier = compile_command(command,_g);
-  //if(MYDEBUG) MESSAGE("simpleRun(...) - this = "<<this<<"; command = '"<<command<<"'; ier = "<<ier); 
 
   // Outputs are redirected on standards outputs (console)
   PySys_SetObject("stdout",PySys_GetObject("__stdout__"));
index de74767d54551db75b418136e5e96ea8873b3673..e7c52baca4bfab7927c02e5ad0c0025191339589 100644 (file)
@@ -85,6 +85,7 @@ protected:
     ThreadLock aStudyLock(myStudyMutex,"TInitEditorThread::aStudyLock");
     ThreadLock aPyLock = GetPyThreadLock("TInitEditorThread::aPyLock");
     if(MYDEBUG) MESSAGE("TInitEditorThread::run() - myInterp = "<<myInterp<<"; myMutex = "<<myMutex);
+    myListener->myBanner = myInterp->getbanner().c_str();
     QThread::postEvent(myListener, new QCustomEvent(QAD_PyEditor::INITIALIZE));
     QThread::postEvent(myListener, new QCustomEvent(QAD_PyEditor::PYTHON_OK));
     QThread::postEvent(myListener, new QCustomEvent(QAD_PyEditor::UNSET_CURSOR));
@@ -133,7 +134,8 @@ protected:
        anId = QAD_PyEditor::PYTHON_ERROR;
       if(ret > 0)
        anId = QAD_PyEditor::PYTHON_INCOMPLETE;
-      myListener->viewport()->unsetCursor();
+      myListener->myError = myInterp->getverr().c_str();
+      myListener->myOutput = myInterp->getvout().c_str();
       QThread::postEvent(myListener, new QCustomEvent(anId));
       QThread::postEvent(myListener, new QCustomEvent(QAD_PyEditor::UNSET_CURSOR));
     }
@@ -289,8 +291,7 @@ void QAD_PyEditor::mousePressEvent (QMouseEvent * event)
     }
     else if ( r == idMap[ IdClear ] ) {
       clear();
-      ThreadLock aPyLock = GetPyThreadLock();
-      setText(myInterp->getbanner().c_str());
+      setText(myBanner);
       setText(_currentPrompt);
     }
     else if ( r == idMap[ IdSelectAll ] ) {
@@ -527,9 +528,8 @@ void QAD_PyEditor::customEvent(QCustomEvent *e)
   case PYTHON_ERROR:
     {
       _buf.truncate(0);
-      ThreadLock aPyLock = GetPyThreadLock();
-      setText(myInterp->getvout().c_str());
-      setText(myInterp->getverr().c_str());
+      setText(myOutput);
+      setText(myError);
       _currentPrompt = ">>> ";
       setText(_currentPrompt);
       break;
index 94c92c3af2c00cbb8c1d5019a356cd9ec4a3fa2b..fd7ff49554fd2e7da8a7263471c657f512a533b4 100644 (file)
@@ -40,7 +40,10 @@ class TExecCommandThread;
 
 class QAD_PyEditor : public QTextEdit
 {
-  Q_OBJECT
+  Q_OBJECT;
+
+  friend class TInitEditorThread;
+  friend class TExecCommandThread;
 
 public:
   enum { PYTHON_OK = QEvent::User + 5000, PYTHON_ERROR, PYTHON_INCOMPLETE, 
@@ -77,6 +80,10 @@ private:
   QMutex* myExecCommandMutex;
   TInitEditorThread* myInitEditorThread;
   TExecCommandThread* myExecCommandThread;
+
+  QString myBanner;
+  QString myOutput;
+  QString myError;
 };
 
 #endif
index fbd95d9e40b0833ebf61abd9c2459e44ebbffe03..f43c8714f2854510a097ea39e24cf5defe8c6de7 100644 (file)
@@ -171,6 +171,7 @@ QAD_Study::~QAD_Study ()
       delete myInitStudyThread;
     }
     delete myMutex;
+    delete myInterp;
   }
 }