*/
QMutex myInitMutex;
+/*! DEBUG mode */
+const bool DEBUG = false;
+
/*!
\var IsCallOldMethods
\brief Allow calling obsolete callback methods.
FuncMsg( const QString& funcName )
{
myName = funcName;
- MESSAGE( qPrintable( myName ) << " [ begin ]" );
+ if ( DEBUG )
+ MESSAGE( qPrintable( myName ) << " [ begin ]" );
}
~FuncMsg()
{
- MESSAGE( qPrintable( myName ) << " [ end ]" );
+ if ( DEBUG )
+ MESSAGE( qPrintable( myName ) << " [ end ]" );
}
void message( const QString& msg )
{
- MESSAGE( qPrintable( myName ) << " : " << qPrintable( msg ) );
+ if ( DEBUG )
+ MESSAGE( qPrintable( myName ) << " : " << qPrintable( msg ) );
}
private:
QString myName;
SUIT_ResourceMgr* resMgr = module()->getApp()->resourceMgr();
QPixmap pixmap = resMgr->loadPixmap( module()->name(),
QApplication::translate( module()->name().toLatin1().data(),
- fileName.toLatin1().data() ) );
+ fileName.toUtf8().data() ) );
if ( !pixmap.isNull() )
icon = QIcon( pixmap );
}
SALOME GUI modules.
*/
-PyModuleHelper::InterpMap PyModuleHelper::myInterpMap;
LightApp_Module* PyModuleHelper::myInitModule = 0;
/*!
PyInterp_Dispatcher::Get()->Exec( new ActionReq( myInterp, this, myModule->actionId( action ) ) );
}
+/*!
+ \brief update selection from other views or modules.
+
+ Called when selection is modified outside.
+*/
+void PyModuleHelper::selectionUpdated(const QStringList& entries)
+{
+ FuncMsg fmsg( "PyModuleHelper::selectionUpdated()" );
+ MESSAGE("selectionUpdated");
+
+ // perform synchronous request to Python event dispatcher
+ class SelectionReq : public PyInterp_LockRequest
+ {
+ public:
+ SelectionReq( PyInterp_Interp* _py_interp,
+ PyModuleHelper* _helper,
+ const QStringList& _entries )
+ : PyInterp_LockRequest( _py_interp, 0, true ), // this request should be processed synchronously (sync == true)
+ myHelper( _helper ),
+ myEntries( _entries )
+ {
+ MESSAGE("SelectionReq");
+ }
+ protected:
+ virtual void execute()
+ {
+ MESSAGE("execute");
+ myHelper->internalSelectionUpdated( myEntries );
+ }
+ private:
+ PyModuleHelper* myHelper;
+ const QStringList& myEntries;
+ };
+
+ // post request
+ PyInterp_Dispatcher::Get()->Exec( new SelectionReq( myInterp, this, entries ) );
+}
+
/*!
\brief Process context popup menu request.
/*!
\brief Save module data. Called when user saves study.
\param files output list of files where module stores data
+ \param url study URL
*/
-void PyModuleHelper::save( QStringList& files )
+void PyModuleHelper::save( QStringList& files, const QString& url )
{
FuncMsg fmsg( "PyModuleHelper::save()" );
public:
SaveReq( PyInterp_Interp* _py_interp,
PyModuleHelper* _helper,
- QStringList& _files )
+ QStringList& _files,
+ const QString& _url )
: PyInterp_LockRequest( _py_interp, 0, true ), // this request should be processed synchronously (sync == true)
myHelper( _helper ) ,
- myFiles( _files )
+ myFiles( _files ),
+ myUrl( _url )
{}
protected:
virtual void execute()
{
- myHelper->internalSave( myFiles );
+ myHelper->internalSave( myFiles, myUrl );
}
private:
PyModuleHelper* myHelper;
QStringList& myFiles;
+ QString myUrl;
};
// Posting the request only if dispatcher is not busy!
// Executing the request synchronously
if ( !PyInterp_Dispatcher::Get()->IsBusy() )
- PyInterp_Dispatcher::Get()->Exec( new SaveReq( myInterp, this, files ) );
+ PyInterp_Dispatcher::Get()->Exec( new SaveReq( myInterp, this, files, url ) );
}
/*
- \brief Load module data. Called when user opens study
- and activates module.
- \param files list of files where module data is stored
+ \brief Load module data. Called when user opens study
+ and activates module.
+ \param files list of files where module data is stored
+ \param url study URL
+ \return \c true if loading has been finished successfully or \c false otherwise
*/
-bool PyModuleHelper::load( const QStringList& files )
+bool PyModuleHelper::load( const QStringList& files, const QString& url )
{
FuncMsg fmsg( "PyModuleHelper::load()" );
LoadReq( PyInterp_Interp* _py_interp,
PyModuleHelper* _helper,
QStringList _files,
+ const QString& _url,
bool& _loaded )
: PyInterp_LockRequest( _py_interp, 0, true ), // this request should be processed synchronously (sync == true)
myHelper( _helper ) ,
myFiles( _files ),
+ myUrl( _url ),
myLoaded( _loaded )
{}
protected:
virtual void execute()
{
- myHelper->internalLoad( myFiles, myLoaded );
+ myHelper->internalLoad( myFiles, myUrl, myLoaded );
}
private:
PyModuleHelper* myHelper;
QStringList myFiles;
+ QString myUrl;
bool& myLoaded;
};
// Posting the request only if dispatcher is not busy!
// Executing the request synchronously
if ( !PyInterp_Dispatcher::Get()->IsBusy() )
- PyInterp_Dispatcher::Get()->Exec( new LoadReq( myInterp, this, files, loaded ) );
+ PyInterp_Dispatcher::Get()->Exec( new LoadReq( myInterp, this, files, url, loaded ) );
return loaded;
}
/*!
\brief Initialize python subinterpreter (one per study).
\internal
- \param studyId study ID
*/
-void PyModuleHelper::initInterp( int studyId )
+void PyModuleHelper::initInterp()
{
FuncMsg fmsg( "--- PyModuleHelper::initInterp()" );
- // check study Id
- if ( !studyId ) {
- // Error! Study Id must not be 0!
- myInterp = 0;
- return;
- }
-
QMutexLocker ml( &myInitMutex );
- // try to find the subinterpreter
- if ( myInterpMap.contains( studyId ) ) {
- // found!
- myInterp = myInterpMap[ studyId ];
- return;
- }
-
myInterp = new SALOME_PYQT_PyInterp();
myInterp->initialize();
- myInterpMap[ studyId ] = myInterp;
#ifndef GUI_DISABLE_CORBA
if ( !SUIT_PYTHON::initialized ) {
}
// ... then call a method
int embedded = 1;
- PyObjWrapper aRes( PyObject_CallMethod( aMod, (char*)"salome_init", (char*)"ii", studyId, embedded ) );
+ PyObjWrapper aRes( PyObject_CallMethod( aMod, (char*)"salome_init", (char*)"i", embedded ) );
if ( !aRes ) {
// Error!
PyErr_Print();
if ( d )
aWorkspace = d->workstack();
}
-#if SIP_VERSION < 0x040800
- PyObjWrapper pyws( sipBuildResult( 0, "M", aWorkspace, sipClass_QWidget) );
-#else
- PyObjWrapper pyws( sipBuildResult( 0, "D", aWorkspace, sipType_QWidget , NULL) );
+#if SIP_VERSION >= 0x041300
+ static const sipTypeDef *sipType_QWidget = 0;
+ if (!sipType_QWidget)
+ sipType_QWidget = sipFindType("QWidget");
#endif
+ PyObjWrapper pyws( sipBuildResult( 0, "D", aWorkspace, sipType_QWidget , NULL) );
// ... and finally call Python module's setWorkSpace() method (obsolete)
if ( PyObject_HasAttrString( myPyModule, (char*)"setWorkSpace" ) ) {
PyObjWrapper res( PyObject_CallMethod( myPyModule, (char*)"setWorkSpace", (char*)"O", pyws.get() ) );
LightApp_Study* aStudy = dynamic_cast<LightApp_Study*>( app->activeStudy() );
if ( !aStudy )
return;
- int aStudyId = aStudy ? aStudy->id() : 0;
// initialize Python subinterpreter (on per study) and put it in <myInterp> variable
- initInterp( aStudyId );
+ initInterp();
if ( !myInterp )
return; // Error
// 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 );
+ if( key && PyLong_Check( key ) && value && PyLong_Check( value ) ) {
+ aKey = PyLong_AsLong( key );
+ aValue = PyLong_AsLong( value );
myWindowsMap[ aKey ] = aValue;
}
}
else {
// parse the return value
// result can be one string...
- if ( PyString_Check( res2 ) ) {
- myViewMgrList.append( PyString_AsString( res2 ) );
+ if ( PyUnicode_Check( res2 ) ) {
+ myViewMgrList.append( PyUnicode_AsUTF8( 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 ) );
+ if( value && PyUnicode_Check( value ) ) {
+ myViewMgrList.append( PyUnicode_AsUTF8( value ) );
}
}
}
// get study Id
LightApp_Study* aStudy = dynamic_cast<LightApp_Study*>( study );
- int aStudyId = aStudy ? aStudy->id() : 0;
+ if ( !aStudy )
+ return;
// initialize Python subinterpreter (on per study) and put it in <myInterp> variable
- initInterp( aStudyId );
+ initInterp();
if ( !myInterp ) {
myLastActivateStatus = false;
return; // Error
// get study Id
LightApp_Study* aStudy = dynamic_cast<LightApp_Study*>( study );
- int aStudyId = aStudy ? aStudy->id() : 0;
+ if ( !aStudy )
+ return;
// initialize Python subinterpreter (on per study) and put it in <myInterp> variable
- initInterp( aStudyId );
+ initInterp();
if ( !myInterp ) {
myLastActivateStatus = false;
return; // Error
// Get study Id
// get study Id
LightApp_Study* aStudy = dynamic_cast<LightApp_Study*>( theStudy );
- int aStudyId = aStudy ? aStudy->id() : 0;
+ if ( !aStudy )
+ return;
// check that Python subinterpreter is initialized and Python module is imported
if ( !myInterp || !myPyModule ) {
}
// then call Python module's deactivate() method
if ( PyObject_HasAttrString( myPyModule , (char*)"closeStudy" ) ) {
- PyObjWrapper res( PyObject_CallMethod( myPyModule, (char*)"closeStudy", (char*)"i", aStudyId ) );
+ PyObjWrapper res( PyObject_CallMethod( myPyModule, (char*)"closeStudy", (char*)"i" ) );
if( !res ) {
PyErr_Print();
}
PyObjWrapper res( PyObject_CallMethod( myPyModule,
(char*)"preferenceChanged",
(char*)"ss",
- section.toLatin1().constData(),
- setting.toLatin1().constData() ) );
+ section.toUtf8().constData(),
+ setting.toUtf8().constData() ) );
if( !res ) {
PyErr_Print();
}
// get study Id
LightApp_Study* aStudy = dynamic_cast<LightApp_Study*>( study );
- int id = aStudy ? aStudy->id() : 0;
-
- fmsg.message( QString( "study id = %1" ).arg( id ) );
+ if ( !aStudy )
+ return;
// initialize Python subinterpreter (on per study) and put it in <myInterp> variable
- initInterp( id );
+ initInterp();
if ( !myInterp )
return; // Error
// call Python module's activeStudyChanged() method
if ( PyObject_HasAttrString( myPyModule, (char*)"activeStudyChanged" ) ) {
- PyObjWrapper res( PyObject_CallMethod( myPyModule, (char*)"activeStudyChanged", (char*)"i", id ) );
+ PyObjWrapper res( PyObject_CallMethod( myPyModule, (char*)"activeStudyChanged", (char*)"i" ) );
if( !res ) {
PyErr_Print();
}
}
}
+/*!
+ \brief update selection from other views or modules
+ \internal
+
+ Performs the following actions:
+ - calls Python module's onSelectionpdated(entries) method
+
+ \param list of entries
+*/
+void PyModuleHelper::internalSelectionUpdated(const QStringList& entries)
+{
+ FuncMsg fmsg("--- PyModuleHelper::internalSelectionUpdated()");
+ MESSAGE("internalSelectionUpdated");
+
+ // Python interpreter should be initialized and Python module should be imported first
+ if (!myInterp || !myPyModule)
+ return; // Error
+
+ QStringList* theList = new QStringList(entries);
+
+#if SIP_VERSION >= 0x041300
+ static const sipTypeDef *sipType_QStringList = 0;
+ if (!sipType_QStringList)
+ sipType_QStringList = sipFindType("QStringList");
+#endif
+ PyObjWrapper sipList( sipBuildResult( 0, "D", theList, sipType_QStringList, NULL ) );
+ if (PyObject_HasAttrString(myPyModule, (char*) "onSelectionUpdated"))
+ {
+ MESSAGE("call onSelectionUpdated");
+ PyObjWrapper res(PyObject_CallMethod(myPyModule, (char*) "onSelectionUpdated", (char*) "O", sipList.get()));
+
+ if (!res)
+ {
+ PyErr_Print();
+ }
+ }
+}
+
/*!
\brief Context popup menu handling callback function
\internal
PyObjWrapper res( PyObject_CallMethod( myPyModule,
(char*)"definePopup",
(char*)"sss",
- context.toLatin1().constData(),
- aObject.toLatin1().constData(),
- aParent.toLatin1().constData() ) );
+ context.toUtf8().constData(),
+ aObject.toUtf8().constData(),
+ aParent.toUtf8().constData() ) );
if( !res ) {
PyErr_Print();
}
if ( myXmlHandler )
myXmlHandler->createPopup( menu, aContext, aParent, aObject );
-#if SIP_VERSION < 0x040800
- PyObjWrapper sipPopup( sipBuildResult( 0, "M", menu, sipClass_QMenu ) );
-#else
- PyObjWrapper sipPopup( sipBuildResult( 0, "D", menu, sipType_QMenu, NULL ) );
+#if SIP_VERSION >= 0x041300
+ static const sipTypeDef *sipType_QMenu = 0;
+ if (!sipType_QMenu)
+ sipType_QMenu = sipFindType("QMenu");
#endif
+ PyObjWrapper sipPopup( sipBuildResult( 0, "D", menu, sipType_QMenu, NULL ) );
// then call Python module's createPopupMenu() method (for new modules)
if ( PyObject_HasAttrString( myPyModule, (char*)"createPopupMenu" ) ) {
(char*)"createPopupMenu",
(char*)"Os",
sipPopup.get(),
- context.toLatin1().constData() ) );
+ context.toUtf8().constData() ) );
if( !res1 ) {
PyErr_Print();
}
(char*)"customPopup",
(char*)"Osss",
sipPopup.get(),
- aContext.toLatin1().constData(),
- aObject.toLatin1().constData(),
- aParent.toLatin1().constData() ) );
+ aContext.toUtf8().constData(),
+ aObject.toUtf8().constData(),
+ aParent.toUtf8().constData() ) );
if( !res2 ) {
PyErr_Print();
}
\brief Module data saving callback function.
\internal
\param files output list of files where module stores data
+ \param url study URL
*/
-void PyModuleHelper::internalSave( QStringList& files )
+void PyModuleHelper::internalSave( QStringList& files, const QString& url )
{
FuncMsg fmsg( "--- PyModuleHelper::internalSave()" );
if ( PyObject_HasAttrString(myPyModule, (char*)"saveFiles") ) {
+ // try with two parameters (new syntax)
PyObjWrapper res( PyObject_CallMethod( myPyModule, (char*)"saveFiles",
- (char*)"s", files.first().toLatin1().constData() ) );
-
+ (char*)"ss",
+ files.first().toUtf8().constData(),
+ url.toUtf8().constData() ) );
+ if ( !res )
+ // try with single parameter (old syntax)
+ res = PyObject_CallMethod( myPyModule, (char*)"saveFiles",
+ (char*)"s", files.first().toUtf8().constData() );
+
if ( !res ) {
PyErr_Print();
}
else {
// parse the return value
// result can be one string...
- if ( PyString_Check( res ) ) {
- QString astr = PyString_AsString( res );
+ if ( PyUnicode_Check( res ) ) {
+ QString astr = PyUnicode_AsUTF8( res );
files.append( astr );
}
//also result can be a list...
int size = PyList_Size( res );
for ( int i = 0; i < size; i++ ) {
PyObject* value = PyList_GetItem( res, i );
- if ( value && PyString_Check( value ) ) {
- files.append( PyString_AsString( value ) );
+ if ( value && PyUnicode_Check( value ) ) {
+ files.append( PyUnicode_AsUTF8( value ) );
}
}
}
\brief Module data loading callback function.
\internal
\param files list of files where module data is stored
+ \param url study URL
\param opened output success flag
*/
-void PyModuleHelper::internalLoad( const QStringList& files, bool& opened )
+void PyModuleHelper::internalLoad( const QStringList& files, const QString& url, bool& opened )
{
FuncMsg fmsg( "--- PyModuleHelper::internalLoad()" );
QStringList* theList = new QStringList( files );
-#if SIP_VERSION < 0x040800
- PyObjWrapper sipList( sipBuildResult( 0, "M", theList, sipClass_QStringList ) );
-#else
- PyObjWrapper sipList( sipBuildResult( 0, "D", theList, sipType_QStringList, NULL ) );
+#if SIP_VERSION >= 0x041300
+ static const sipTypeDef *sipType_QStringList = 0;
+ if (!sipType_QStringList)
+ sipType_QStringList = sipFindType("QStringList");
#endif
+ PyObjWrapper sipList( sipBuildResult( 0, "D", theList, sipType_QStringList, NULL ) );
if ( PyObject_HasAttrString(myPyModule , (char*)"openFiles") ) {
+
+ // try with two parameters (new syntax)
PyObjWrapper res( PyObject_CallMethod( myPyModule, (char*)"openFiles",
- (char*)"O", sipList.get()));
- if( !res || !PyBool_Check( res )) {
+ (char*)"Os", sipList.get(),
+ url.toUtf8().constData() ) );
+
+ if ( !res )
+ // try with single parameter (old syntax)
+ res = PyObject_CallMethod( myPyModule, (char*)"openFiles",
+ (char*)"O", sipList.get() );
+
+ if ( !res || !PyBool_Check( res ) ) {
PyErr_Print();
opened = false;
}
- else{
+ else {
opened = PyObject_IsTrue( res );
}
}
if ( PyObject_HasAttrString(myPyModule, (char*)"dumpStudy") ) {
PyObjWrapper res( PyObject_CallMethod( myPyModule, (char*)"dumpStudy",
- (char*)"s", files.first().toLatin1().constData()));
+ (char*)"s", files.first().toUtf8().constData()));
if ( !res ) {
PyErr_Print();
else {
// parse the return value
// result can be one string...
- if ( PyString_Check( res ) ) {
- QString astr = PyString_AsString( res );
+ if ( PyUnicode_Check( res ) ) {
+ QString astr = PyUnicode_AsUTF8( res );
//SCRUTE(astr);
files.append(astr);
}
int size = PyList_Size( res );
for ( int i = 0; i < size; i++ ) {
PyObject* value = PyList_GetItem( res, i );
- if( value && PyString_Check( value ) ) {
- files.append( PyString_AsString( value ) );
+ if( value && PyUnicode_Check( value ) ) {
+ files.append( PyUnicode_AsUTF8( value ) );
}
}
}
if ( PyObject_HasAttrString(myPyModule , (char*)"isDraggable") ) {
PyObjWrapper res( PyObject_CallMethod( myPyModule, (char*)"isDraggable",
- (char*)"s", what->entry().toLatin1().constData() ) );
+ (char*)"s", what->entry().toUtf8().constData() ) );
if( !res || !PyBool_Check( res )) {
PyErr_Print();
draggable = false;
if ( PyObject_HasAttrString(myPyModule , (char*)"isDropAccepted") ) {
PyObjWrapper res( PyObject_CallMethod( myPyModule, (char*)"isDropAccepted",
- (char*)"s", where->entry().toLatin1().constData() ) );
+ (char*)"s", where->entry().toUtf8().constData() ) );
if( !res || !PyBool_Check( res )) {
PyErr_Print();
dropAccepted = false;
if ( dataObject ) theList->append( dataObject->entry() );
}
-#if SIP_VERSION < 0x040800
- PyObjWrapper sipList( sipBuildResult( 0, "M", theList, sipClass_QStringList) );
-#else
- PyObjWrapper sipList( sipBuildResult( 0, "D", theList, sipType_QStringList, NULL) );
+#if SIP_VERSION >= 0x041300
+ static const sipTypeDef *sipType_QStringList = 0;
+ if (!sipType_QStringList)
+ sipType_QStringList = sipFindType("QStringList");
#endif
+ PyObjWrapper sipList( sipBuildResult( 0, "D", theList, sipType_QStringList, NULL) );
if ( PyObject_HasAttrString(myPyModule, (char*)"dropObjects") ) {
PyObjWrapper res( PyObject_CallMethod( myPyModule, (char*)"dropObjects", (char*)"Osii",
sipList.get(),
- whereObject->entry().toLatin1().constData(),
+ whereObject->entry().toUtf8().constData(),
row, action ) );
if( !res ) {
}
else {
// parse the return value, result chould be string
- if ( PyString_Check( res ) ) {
- ior = PyString_AsString( res );
+ if ( PyUnicode_Check( res ) ) {
+ ior = PyUnicode_AsUTF8( res );
}
}
}
return; // Error
if ( PyObject_HasAttrString( myPyModule, (char*)"onObjectBrowserClicked" ) ) {
- PyObjWrapper res( PyObject_CallMethod( myPyModule, (char*)"onObjectBrowserClicked", (char*)"si", theObj.toLatin1().constData(), theColumn ) );
+ PyObjWrapper res( PyObject_CallMethod( myPyModule, (char*)"onObjectBrowserClicked", (char*)"si", theObj.toUtf8().constData(), theColumn ) );
if( !res ) {
PyErr_Print();
}