From: vsr Date: Wed, 30 Nov 2016 13:01:27 +0000 (+0300) Subject: Introduce new syntax to openFiles() and saveFiles() Python callback functions, to... X-Git-Tag: V8_2_0rc1 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=bfadde3dd17765ec968e53799319deb1654095ef;p=modules%2Fgui.git Introduce new syntax to openFiles() and saveFiles() Python callback functions, to specify URL (file path) of study being saved / loaded --- diff --git a/src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_DataModelLight.cxx b/src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_DataModelLight.cxx index 031e1124d..99e4222e0 100644 --- a/src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_DataModelLight.cxx +++ b/src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_DataModelLight.cxx @@ -70,7 +70,7 @@ bool SALOME_PYQT_DataModelLight::open( const QString& theURL, CAM_Study* study, setModified( false ); - return aModule->load(theListOfFiles); + return aModule->load(theListOfFiles, theURL); } @@ -95,7 +95,7 @@ bool SALOME_PYQT_DataModelLight::save( QStringList& theListOfFiles) theListOfFiles.append(QString(aTmpDir.c_str())); int listSize = theListOfFiles.size(); - aModule->save(theListOfFiles); + aModule->save(theListOfFiles, myStudyURL); setModified( false ); diff --git a/src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_ModuleLight.cxx b/src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_ModuleLight.cxx index ee19eb173..c1791289b 100644 --- a/src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_ModuleLight.cxx +++ b/src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_ModuleLight.cxx @@ -253,24 +253,27 @@ void SALOME_PYQT_ModuleLight::preferencesChanged( const QString& section, const /*! \brief Save module data. Called when user saves study. \param files output list of files where module stores data + \param url study URL \sa PyModuleHelper::save() */ -void SALOME_PYQT_ModuleLight::save( QStringList& files ) +void SALOME_PYQT_ModuleLight::save( QStringList& files, const QString& url ) { // call helper - myHelper->save( files ); + myHelper->save( files, url ); } /* - \brief Load module data. Called when user opens study - and activates module. - \param files list of files where module data is stored - \sa PyModuleHelper::load() + \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 + \sa PyModuleHelper::load() */ -bool SALOME_PYQT_ModuleLight::load( const QStringList& files ) +bool SALOME_PYQT_ModuleLight::load( const QStringList& files, const QString& url ) { // call helper - return myHelper->load( files ); + return myHelper->load( files, url ); } /*! diff --git a/src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_ModuleLight.h b/src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_ModuleLight.h index 33942486f..b0c9dd6e3 100644 --- a/src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_ModuleLight.h +++ b/src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_ModuleLight.h @@ -58,8 +58,8 @@ public: void preferencesChanged( const QString&, const QString& ); // persistence & dump python - void save( QStringList& ); - bool load( const QStringList& ); + void save( QStringList&, const QString& ); + bool load( const QStringList&, const QString& ); void dumpPython( QStringList& ); // drag-n-drop support diff --git a/src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_PyModule.cxx b/src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_PyModule.cxx index 33ec8b991..2d9e74550 100644 --- a/src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_PyModule.cxx +++ b/src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_PyModule.cxx @@ -1374,8 +1374,9 @@ void PyModuleHelper::cloneView( SUIT_ViewWindow* view ) /*! \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()" ); @@ -1391,33 +1392,38 @@ void PyModuleHelper::save( QStringList& files ) 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()" ); @@ -1429,27 +1435,30 @@ bool PyModuleHelper::load( const QStringList& files ) 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; } @@ -2421,8 +2430,9 @@ void PyModuleHelper::internalCloneView( SUIT_ViewWindow* view ) \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()" ); @@ -2434,9 +2444,16 @@ void PyModuleHelper::internalSave( QStringList& files ) 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().toLatin1().constData(), + url.toLatin1().constData() ) ); + if ( !res ) + // try with single parameter (old syntax) + res = PyObject_CallMethod( myPyModule, (char*)"saveFiles", + (char*)"s", files.first().toLatin1().constData() ); + if ( !res ) { PyErr_Print(); } @@ -2465,9 +2482,10 @@ void PyModuleHelper::internalSave( QStringList& files ) \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()" ); @@ -2484,13 +2502,22 @@ void PyModuleHelper::internalLoad( const QStringList& files, bool& opened ) PyObjWrapper sipList( sipBuildResult( 0, "D", theList, sipType_QStringList, NULL ) ); #endif 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.toLatin1().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 ); } } diff --git a/src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_PyModule.h b/src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_PyModule.h index d49485080..f8e012159 100644 --- a/src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_PyModule.h +++ b/src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_PyModule.h @@ -97,8 +97,8 @@ public slots: void tryCloseView( SUIT_ViewWindow* ); void closeView( SUIT_ViewWindow* ); void cloneView( SUIT_ViewWindow* ); - void save( QStringList& ); - bool load( const QStringList& ); + void save( QStringList&, const QString& ); + bool load( const QStringList&, const QString& ); void dumpPython( QStringList& files ); bool isDraggable( const SUIT_DataObject* ) const; bool isDropAccepted( const SUIT_DataObject* ) const; @@ -127,8 +127,8 @@ private: void internalTryCloseView( SUIT_ViewWindow* ); void internalCloseView( SUIT_ViewWindow* ); void internalCloneView( SUIT_ViewWindow* ); - void internalSave( QStringList& ); - void internalLoad( const QStringList&, bool& ); + void internalSave( QStringList&, const QString& ); + void internalLoad( const QStringList&, const QString&, bool& ); void internalDumpPython( QStringList& ); bool internalIsDraggable( LightApp_DataObject* ); bool internalIsDropAccepted( LightApp_DataObject* ); diff --git a/tools/PyInterp/src/PyInterp_Utils.h b/tools/PyInterp/src/PyInterp_Utils.h index 8d6ce8c63..d47ff1846 100644 --- a/tools/PyInterp/src/PyInterp_Utils.h +++ b/tools/PyInterp/src/PyInterp_Utils.h @@ -101,6 +101,14 @@ public: { Py_XDECREF(myObject); myObject = theObjWrapper->myObject; + Py_XINCREF(myObject); + return *this; + } + PyObjWrapper& operator=(const PyObjWrapper& theObjWrapper) + { + Py_XDECREF(myObject); + myObject = theObjWrapper.myObject; + Py_XINCREF(myObject); return *this; } };