myThreadState(theThreadState),
mySaveThreadState(0)
{
- PyEval_AcquireLock();
- mySaveThreadState = PyThreadState_Swap(myThreadState); // store previous current in save,
+ PyEval_AcquireThread(myThreadState);
+ //PyEval_AcquireLock();
+ //mySaveThreadState = PyThreadState_Swap(myThreadState); // store previous current in save,
// set local in current
}
PyLockWrapper::~PyLockWrapper(){
- PyThreadState_Swap(mySaveThreadState); // restore previous current (no need to get local,
- PyEval_ReleaseLock(); // local thread state* already in _tstate
+ PyEval_ReleaseThread(myThreadState);
+ //PyThreadState_Swap(mySaveThreadState); // restore previous current (no need to get local,
+ //PyEval_ReleaseLock(); // local thread state* already in _tstate
}
*/
void PyInterp_base::initialize()
{
+ cerr << "PyInterp_base::initialize" << endl;
_history.clear(); // start a new list of user's commands
_ith = _history.begin();
// Here the global lock is released
// The lock will be acquired in initState. Make provision to release it on exit
- PyReleaseLock aReleaseLock;
+ // PyReleaseLock aReleaseLock;
initState();
+
+ PyLockWrapper aLock= GetLockWrapper();
+
initContext();
// used to interpret & compile commands
PyObjWrapper m(PyImport_ImportModule("codeop"));
if(!m){
PyErr_Print();
+ //PyEval_SaveThread();
return;
}
// All the initRun outputs are redirected to the standard output (console)
initRun();
+ //PyEval_SaveThread();
+ cerr << "---------------------------PyInterp_base::initialize" << endl;
}
void PyInterp_base::init_python()
PySys_SetArgv(_argc, _argv);
PyEval_InitThreads(); // Create (and acquire) the interpreter lock
_gtstate = PyEval_SaveThread(); // Release global thread state
+ // There the thread state is NULL
// if(!_gtstate){
// PyReleaseLock aReleaseLock;
// Py_Initialize(); // Initialize the interpreter
string PyInterp_base::getbanner()
{
+ // PyEval_RestoreThread(_tstate);
string aBanner("Python ");
aBanner = aBanner + Py_GetVersion() + " on " + Py_GetPlatform() ;
aBanner = aBanner + "\ntype help to get general information on environment\n";
+ //PyEval_SaveThread();
return aBanner;
}
int PyInterp_base::simpleRun(const char *command)
{
+ cerr << "PyInterp_base::simpleRun : " << command << endl;
if( !_atFirst && strcmp(command,"") != 0 ) {
_history.push_back(command);
_ith = _history.end();
// Outputs are redirected on standards outputs (console)
PySys_SetObject("stdout",PySys_GetObject("__stdout__"));
PySys_SetObject("stderr",PySys_GetObject("__stderr__"));
+
+ cerr << "----------PyInterp_base::simpleRun" << endl;
+
return ier;
}
*/
void SALOME_PYQT_Module::init( CAM_Application* app )
{
+ cerr << "SALOME_PYQT_Module::init" << endl;
// reset interpreter to NULL
myInterp = NULL;
PyLockWrapper aLock = myInterp->GetLockWrapper();
// ... (the Python module is already imported)
// ... finally call Python module's initialize() method
- PyObjWrapper res( PyObject_CallMethod( myModule, "initialize", "" ) );
- if( !res ) {
- // VSR: this method may not be implemented in Python module
- // PyErr_Print();
- PyErr_Clear();
+ if(PyObject_HasAttrString(myModule , "initialize")){
+ PyObjWrapper res( PyObject_CallMethod( myModule, "initialize", "" ) );
+ if( !res ) {
+ // CCAR already tested // VSR: this method may not be implemented in Python module
+ PyErr_Print();
+ //PyErr_Clear();
+ }
}
// get the windows list from the Python module by calling windows() method
// VSR: LogWindow is not yet implemented
// myWindowsMap.insert( SalomeApp_Application::WT_LogWindow, Qt::DockBottom );
- PyObjWrapper res1( PyObject_CallMethod( myModule, "windows", "" ) );
- if( !res1 ) {
- // VSR: this method may not be implemented in Python module
- // PyErr_Print();
- PyErr_Clear();
- }
- else {
- myWindowsMap.clear();
- if ( PyDict_Check( res1 ) ) {
- PyObject* key;
- PyObject* value;
- int pos = 0;
- while ( PyDict_Next( res1, &pos, &key, &value ) ) {
- // parse the return value
- // it should be a map: {integer:integer}
- int aKey, aValue;
- if( key && PyInt_Check( key ) && value && PyInt_Check( value ) ) {
- aKey = PyInt_AsLong( key );
- aValue = PyInt_AsLong( value );
- myWindowsMap[ aKey ] = aValue;
- }
+ if(PyObject_HasAttrString(myModule , "windows")){
+ PyObjWrapper res1( PyObject_CallMethod( myModule, "windows", "" ) );
+ if( !res1 ) {
+ // VSR: this method may not be implemented in Python module
+ PyErr_Print();
+ //PyErr_Clear();
+ }
+ else {
+ myWindowsMap.clear();
+ if ( PyDict_Check( res1 ) ) {
+ PyObject* key;
+ PyObject* value;
+ int pos = 0;
+ while ( PyDict_Next( res1, &pos, &key, &value ) ) {
+ // parse the return value
+ // it should be a map: {integer:integer}
+ int aKey, aValue;
+ if( key && PyInt_Check( key ) && value && PyInt_Check( value ) ) {
+ aKey = PyInt_AsLong( key );
+ aValue = PyInt_AsLong( value );
+ myWindowsMap[ aKey ] = aValue;
+ }
+ }
}
}
}
// get the windows list from the Python module by calling views() method
- PyObjWrapper res2( PyObject_CallMethod( myModule, "views", "" ) );
- if( !res2 ) {
- // VSR: this method may not be implemented in Python module
- // PyErr_Print();
- PyErr_Clear();
- }
- else {
- // parse the return value
- // result can be one string...
- if ( PyString_Check( res2 ) ) {
- myViewMgrList.append( PyString_AsString( res2 ) );
+ if(PyObject_HasAttrString(myModule , "views")){
+ PyObjWrapper res2( PyObject_CallMethod( myModule, "views", "" ) );
+ if( !res2 ) {
+ // VSR: this method may not be implemented in Python module
+ PyErr_Print();
+ //PyErr_Clear();
}
- // ... or list of strings
- else if ( PyList_Check( res2 ) ) {
- int size = PyList_Size( res2 );
- for ( int i = 0; i < size; i++ ) {
- PyObject* value = PyList_GetItem( res2, i );
- if( value && PyString_Check( value ) ) {
- myViewMgrList.append( PyString_AsString( value ) );
- }
+ else {
+ // parse the return value
+ // result can be one string...
+ if ( PyString_Check( res2 ) ) {
+ myViewMgrList.append( PyString_AsString( res2 ) );
+ }
+ // ... or list of strings
+ else if ( PyList_Check( res2 ) ) {
+ int size = PyList_Size( res2 );
+ for ( int i = 0; i < size; i++ ) {
+ PyObject* value = PyList_GetItem( res2, i );
+ if( value && PyString_Check( value ) ) {
+ myViewMgrList.append( PyString_AsString( value ) );
+ }
+ }
}
}
}
myInitModule = 0;
+ cerr << "----------------------SALOME_PYQT_Module::init" << endl;
}
/*!
if ( IsCallOldMethods ) { //__CALL_OLD_METHODS__
// call Python module's setSettings() method (obsolete)
- PyObjWrapper res( PyObject_CallMethod( myModule, "setSettings", "" ) );
- if( !res ) {
- // VSR: this method may not be implemented in Python module
- // PyErr_Print();
- PyErr_Clear();
+ if(PyObject_HasAttrString(myModule , "setSettings")){
+ PyObjWrapper res( PyObject_CallMethod( myModule, "setSettings", "" ) );
+ if( !res ) {
+ // VSR: this method may not be implemented in Python module
+ PyErr_Print();
+ //PyErr_Clear();
+ }
}
} //__CALL_OLD_METHODS__
// call Python module's activate() method (for the new modules)
- PyObjWrapper res1( PyObject_CallMethod( myModule, "activate", "" ) );
- if( !res1 ) {
- // VSR: this method may not be implemented in Python module
- // PyErr_Print();
- PyErr_Clear();
+ if(PyObject_HasAttrString(myModule , "activate")){
+ PyObjWrapper res1( PyObject_CallMethod( myModule, "activate", "" ) );
+ if( !res1 ) {
+ // VSR: this method may not be implemented in Python module
+ PyErr_Print();
+ //PyErr_Clear();
+ }
}
}
return;
}
// then call Python module's deactivate() method
- PyObjWrapper res( PyObject_CallMethod( myModule, "deactivate", "" ) );
- if( !res ) {
- // VSR: this method may not be implemented in Python module
- // PyErr_Print();
- PyErr_Clear();
+ if(PyObject_HasAttrString(myModule , "deactivate")){
+ PyObjWrapper res( PyObject_CallMethod( myModule, "deactivate", "" ) );
+ if( !res ) {
+ // VSR: this method may not be implemented in Python module
+ PyErr_Print();
+ //PyErr_Clear();
+ }
}
}
PyLockWrapper aLock = myInterp->GetLockWrapper();
// call Python module's activeStudyChanged() method
- PyObjWrapper res( PyObject_CallMethod( myModule, "activeStudyChanged", "i", aStudyId ) );
- if( !res ) {
- // VSR: this method may not be implemented in Python module
- // PyErr_Print();
- PyErr_Clear();
+ if(PyObject_HasAttrString(myModule , "activeStudyChanged")){
+ PyObjWrapper res( PyObject_CallMethod( myModule, "activeStudyChanged", "i", aStudyId ) );
+ if( !res ) {
+ // VSR: this method may not be implemented in Python module
+ PyErr_Print();
+ //PyErr_Clear();
+ }
}
}
return;
QString aContext( theContext ), aObject( "" ), aParent( "" );
-
- if ( IsCallOldMethods ) { //__CALL_OLD_METHODS__
+
+ if ( IsCallOldMethods && PyObject_HasAttrString(myModule , "definePopup") ) { //__CALL_OLD_METHODS__
// call definePopup() Python module's function
// this is obsolete function, used only for compatibility reasons
PyObjWrapper res(PyObject_CallMethod( myModule,
aParent.latin1() ) );
if( !res ) {
// VSR: this method may not be implemented in Python module
- // PyErr_Print();
- PyErr_Clear();
+ PyErr_Print();
+ //PyErr_Clear();
}
else {
// parse return value
PyObjWrapper sipPopup( sipBuildResult( 0, "M", thePopupMenu, sipClass_QPopupMenu ) );
// then call Python module's createPopupMenu() method (for new modules)
- PyObjWrapper res1( PyObject_CallMethod( myModule,
+ if ( PyObject_HasAttrString(myModule , "createPopupMenu") ) {
+ PyObjWrapper res1( PyObject_CallMethod( myModule,
"createPopupMenu",
"Os",
sipPopup.get(),
aContext.latin1() ) );
- if( !res1 ) {
- // VSR: this method may not be implemented in Python module
- // PyErr_Print();
- PyErr_Clear();
+ if( !res1 ) {
+ // VSR: this method may not be implemented in Python module
+ PyErr_Print();
+ //PyErr_Clear();
+ }
}
- if ( IsCallOldMethods ) { //__CALL_OLD_METHODS__
+ if ( IsCallOldMethods && PyObject_HasAttrString(myModule , "customPopup") ) { //__CALL_OLD_METHODS__
// call customPopup() Python module's function
// this is obsolete function, used only for compatibility reasons
PyObjWrapper res2( PyObject_CallMethod( myModule,
aParent.latin1() ) );
if( !res2 ) {
// VSR: this method may not be implemented in Python module
- // PyErr_Print();
- PyErr_Clear();
+ PyErr_Print();
+ //PyErr_Clear();
}
} //__CALL_OLD_METHODS__
}
if ( !myInterp || !myModule )
return;
- PyObjWrapper res( PyObject_CallMethod( myModule, "OnGUIEvent", "i", theId ) );
- if( !res ) {
- // VSR: this method may not be implemented in Python module
- // PyErr_Print();
- PyErr_Clear();
+ if ( PyObject_HasAttrString(myModule , "OnGUIEvent") ) {
+ PyObjWrapper res( PyObject_CallMethod( myModule, "OnGUIEvent", "i", theId ) );
+ if( !res ) {
+ // VSR: this method may not be implemented in Python module
+ PyErr_Print();
+ //PyErr_Clear();
+ }
}
}
}
PyObjWrapper pyws( sipBuildResult( 0, "M", aWorkspace, sipClass_QWidget ) );
// ... and finally call Python module's setWorkspace() method (obsolete)
- PyObjWrapper res( PyObject_CallMethod( myModule, "setWorkSpace", "O", pyws.get() ) );
- if( !res ) {
- // VSR: this method may not be implemented in Python module
- // PyErr_Print();
- PyErr_Clear();
+ if ( PyObject_HasAttrString(myModule , "setWorkSpace") ) {
+ PyObjWrapper res( PyObject_CallMethod( myModule, "setWorkSpace", "O", pyws.get() ) );
+ if( !res ) {
+ // VSR: this method may not be implemented in Python module
+ PyErr_Print();
+ //PyErr_Clear();
+ }
}
} //__CALL_OLD_METHODS__
}