From 7701e3e37ce14a5050c031f01adfea59ba3fa662 Mon Sep 17 00:00:00 2001 From: smh Date: Wed, 28 Apr 2004 08:53:09 +0000 Subject: [PATCH] Porting to the new interaface of modules and implementation of python interp. --- src/SALOME_PYQT/SALOME_PYQT_GUI.cxx | 220 ++++++++++------------------ src/SALOME_PYQT/SALOME_PYQT_GUI.hxx | 40 ++--- 2 files changed, 97 insertions(+), 163 deletions(-) diff --git a/src/SALOME_PYQT/SALOME_PYQT_GUI.cxx b/src/SALOME_PYQT/SALOME_PYQT_GUI.cxx index dc3ff8b41..b59210b2a 100644 --- a/src/SALOME_PYQT/SALOME_PYQT_GUI.cxx +++ b/src/SALOME_PYQT/SALOME_PYQT_GUI.cxx @@ -42,23 +42,17 @@ static string _moduleName; static void setWorkSpace() { MESSAGE("setWorkSpace"); - PyObject *res,*pyws; + PyLockWrapper aLock = interp->GetLockWrapper(); - interp->enter(); - pyws=sipMapCppToSelf( QAD_Application::getDesktop()->getMainFrame(), - sipClass_QWorkspace); - res=PyObject_CallMethod(module,"setWorkSpace","O",pyws); + PyObjWrapper pyws(sipMapCppToSelf( QAD_Application::getDesktop()->getMainFrame(), + sipClass_QWorkspace)); + PyObjWrapper res(PyObject_CallMethod(module,"setWorkSpace","O",pyws.get())); SCRUTE(pyws->ob_refcnt); - Py_DECREF(pyws); - if (res == NULL) - { - PyErr_Print(); - interp->quit(); - return ; - } - Py_DECREF(res); - interp->quit(); - return ; + if(!res){ + PyErr_Print(); + return ; + } + return; } //============================================================================= @@ -72,31 +66,26 @@ static void setWorkSpace() static void initInterp(int StudyID) { MESSAGE("initInterp"); - if (mapInterp.find(StudyID) != mapInterp.end()) - { - MESSAGE ( " StudyID is found " << StudyID ); - interp = mapInterp[StudyID]; - return; - } - else - { - MESSAGE ( " StudyID is not found " << StudyID ); - interp=new PyInterp_PyQt(); - mapInterp[StudyID] = interp; - } - - interp->enter(); - - module=PyImport_ImportModule((char*)_moduleName.c_str()); - if(module == NULL) - { - MESSAGE ( " Problem... " ); - PyErr_Print(); - interp->quit(); - return; - } + if(mapInterp.find(StudyID) != mapInterp.end()){ + MESSAGE ( " StudyID is found " << StudyID ); + interp = mapInterp[StudyID]; + return; + }else{ + MESSAGE ( " StudyID is not found " << StudyID ); + interp=new PyInterp_PyQt(); + mapInterp[StudyID] = interp; + } + + PyLockWrapper aLock = interp->GetLockWrapper(); + + PyObjWrapper res(PyImport_ImportModule((char*)_moduleName.c_str())); + if(!res){ + MESSAGE ( " Problem... " ); + PyErr_Print(); + return; + } + // PyQt import is OK - interp->quit(); setWorkSpace(); } @@ -110,18 +99,13 @@ bool SALOME_PYQT_GUI::OnGUIEvent (int theCommandID, QAD_Desktop* parent) { MESSAGE("SALOME_PYQT_GUI::OnGUIEvent"); - PyObject *res; - - interp->enter(); - res=PyObject_CallMethod(module,"OnGUIEvent","i",theCommandID); - if (res == NULL) - { - PyErr_Print(); - interp->quit(); - return false; - } - Py_DECREF(res); - interp->quit(); + PyLockWrapper aLock = interp->GetLockWrapper(); + + PyObjWrapper res(PyObject_CallMethod(module,"OnGUIEvent","i",theCommandID)); + if(!res){ + PyErr_Print(); + return false; + } return true; } @@ -178,23 +162,19 @@ bool SALOME_PYQT_GUI::OnMouseMove (QMouseEvent* pe , bool SALOME_PYQT_GUI::SetSettings (QAD_Desktop* parent, char* moduleName) { MESSAGE("SALOME_PYQT_GUI::SetSettings"); - PyObject *res; int StudyID = QAD_Application::getDesktop()->getActiveStudy()->getStudyId(); SCRUTE ( StudyID ); _moduleName = moduleName + string("GUI"); SCRUTE(_moduleName); initInterp(StudyID); - interp->enter(); - res=PyObject_CallMethod(module,"setSettings",""); - if (res == NULL) - { - PyErr_Print(); - interp->quit(); - return false; - } - Py_DECREF(res); - interp->quit(); + PyLockWrapper aLock = interp->GetLockWrapper(); + + PyObjWrapper res(PyObject_CallMethod(module,"setSettings","")); + if(!res){ + PyErr_Print(); + return false; + } return true; } @@ -218,25 +198,19 @@ bool SALOME_PYQT_GUI::CustomPopup ( QAD_Desktop* parent, MESSAGE ( " theParent : " << theParent.latin1() ); MESSAGE ( " theObject : " << theObject.latin1() ); - PyObject *res,*pypop; - interp->enter(); - pypop=sipMapCppToSelf( popup, - sipClass_QPopupMenu); - - res=PyObject_CallMethod(module,"customPopup","Osss",pypop, - theContext.latin1(), theObject.latin1(), theParent.latin1()); - Py_DECREF(pypop); - if (res == NULL) - { - PyErr_Print(); - interp->quit(); - return false; - } - - Py_DECREF(res); - interp->quit(); + PyLockWrapper aLock = interp->GetLockWrapper(); + PyObjWrapper pypop(sipMapCppToSelf( popup, sipClass_QPopupMenu)); + PyObjWrapper res(PyObject_CallMethod(module,"customPopup", + "Osss",pypop.get(), + theContext.latin1(), + theObject.latin1(), + theParent.latin1())); + if(!res){ + PyErr_Print(); + return false; + } return true; } @@ -257,16 +231,16 @@ void SALOME_PYQT_GUI::DefinePopup( QString & theContext, theObject = ""; theParent = ""; - PyObject *res; - interp->enter(); - res=PyObject_CallMethod(module,"definePopup","sss", - theContext.latin1(), theObject.latin1(), theParent.latin1()); - if (res == NULL) - { - PyErr_Print(); - interp->quit(); - return ; - } + PyLockWrapper aLock = interp->GetLockWrapper(); + + PyObjWrapper res(PyObject_CallMethod(module,"definePopup","sss", + theContext.latin1(), + theObject.latin1(), + theParent.latin1())); + if(!res){ + PyErr_Print(); + return; + } char *co, *ob, *pa; int parseOk = PyArg_ParseTuple(res, "sss", &co, &ob, &pa); @@ -276,13 +250,10 @@ void SALOME_PYQT_GUI::DefinePopup( QString & theContext, theContext = co; theObject = ob; theParent = pa; - Py_DECREF(res); - interp->quit(); MESSAGE ( " theContext : " << theContext.latin1() ); MESSAGE ( " theParent : " << theParent.latin1() ); MESSAGE ( " theObject : " << theObject.latin1() ); - } //============================================================================= @@ -292,25 +263,21 @@ void SALOME_PYQT_GUI::DefinePopup( QString & theContext, */ //============================================================================= -void SALOME_PYQT_GUI::ActiveStudyChanged( QAD_Desktop* parent ) +bool SALOME_PYQT_GUI::ActiveStudyChanged( QAD_Desktop* parent ) { MESSAGE("SALOME_PYQT_GUI::ActiveStudyChanged"); - PyObject *res; int StudyID = parent->getActiveApp()->getActiveStudy()->getStudyId(); initInterp(StudyID); - interp->enter(); - res=PyObject_CallMethod(module,"activeStudyChanged","i", StudyID ); - if (res == NULL) - { - PyErr_Print(); - interp->quit(); - return ; - } - Py_DECREF(res); - interp->quit(); - return; + PyLockWrapper aLock = interp->GetLockWrapper(); + + PyObjWrapper res(PyObject_CallMethod(module,"activeStudyChanged","i", StudyID )); + if(!res){ + PyErr_Print(); + return false; + } + return true; } @@ -321,47 +288,10 @@ void SALOME_PYQT_GUI::ActiveStudyChanged( QAD_Desktop* parent ) //============================================================================= +static SALOME_PYQT_GUI aGUI(""); extern "C" { - bool OnGUIEvent(int theCommandID, QAD_Desktop* parent) - { - return SALOME_PYQT_GUI::OnGUIEvent(theCommandID, parent); - } - - bool OnKeyPress(QKeyEvent* pe, QAD_Desktop* parent, QAD_StudyFrame* studyFrame) - { - return SALOME_PYQT_GUI::OnKeyPress(pe, parent, studyFrame); - } - - bool OnMousePress(QMouseEvent* pe, QAD_Desktop* parent, QAD_StudyFrame* studyFrame) - { - return SALOME_PYQT_GUI::OnMousePress(pe, parent, studyFrame); - } - - bool OnMouseMove(QMouseEvent* pe, QAD_Desktop* parent, QAD_StudyFrame* studyFrame) - { - return SALOME_PYQT_GUI::OnMouseMove(pe, parent, studyFrame); - } - - bool SetSettings(QAD_Desktop* parent, char* moduleName) - { - return SALOME_PYQT_GUI::SetSettings(parent, moduleName); - } - - bool customPopup(QAD_Desktop* parent, QPopupMenu* popup, const QString & theContext, - const QString & theParent, const QString & theObject) - { - return SALOME_PYQT_GUI::CustomPopup( parent, popup, theContext, theParent, theObject ); - } - - void definePopup(QString & theContext, QString & theParent, QString & theObject) - { - SALOME_PYQT_GUI::DefinePopup(theContext, theParent, theObject); - } - - void activeStudyChanged ( QAD_Desktop* parent ) - { - SALOME_PYQT_GUI::ActiveStudyChanged(parent); + Standard_EXPORT SALOMEGUI* GetComponentGUI() { + return &aGUI; } } - diff --git a/src/SALOME_PYQT/SALOME_PYQT_GUI.hxx b/src/SALOME_PYQT/SALOME_PYQT_GUI.hxx index fe0f6ffb5..618395aa9 100644 --- a/src/SALOME_PYQT/SALOME_PYQT_GUI.hxx +++ b/src/SALOME_PYQT/SALOME_PYQT_GUI.hxx @@ -11,30 +11,34 @@ #define _SALOME_PYQT_GUI_HXX_ #include "QAD_Desktop.h" +#include "SALOMEGUI.h" -class SALOME_PYQT_GUI: public QObject +class SALOME_PYQT_GUI: public SALOMEGUI { - Q_OBJECT - + Q_OBJECT; + private: public: - static bool OnGUIEvent (int theCommandID, QAD_Desktop* parent); - static bool OnMousePress (QMouseEvent* pe, QAD_Desktop* parent, - QAD_StudyFrame* studyFrame); - static bool OnMouseMove (QMouseEvent* pe, QAD_Desktop* parent, - QAD_StudyFrame* studyFrame); - static bool OnKeyPress (QKeyEvent* pe, QAD_Desktop* parent, - QAD_StudyFrame* studyFrame); - static bool SetSettings (QAD_Desktop* parent, char* moduleName); - static bool CustomPopup (QAD_Desktop* parent, QPopupMenu* popup, - const QString & theContext, - const QString & theParent, - const QString & theObject); - static void DefinePopup (QString & theContext, QString & theParent, - QString & theObject) ; - static void ActiveStudyChanged (QAD_Desktop* parent); + SALOME_PYQT_GUI( const QString& name = "", QObject* parent = 0 ); + virtual ~SALOME_PYQT_GUI(); + + virtual bool OnGUIEvent (int theCommandID, QAD_Desktop* parent); + virtual bool OnKeyPress (QKeyEvent* pe, QAD_Desktop* parent, + QAD_StudyFrame* studyFrame); + virtual bool OnMousePress (QMouseEvent* pe, QAD_Desktop* parent, + QAD_StudyFrame* studyFrame); + virtual bool OnMouseMove (QMouseEvent* pe, QAD_Desktop* parent, + QAD_StudyFrame* studyFrame); + virtual bool SetSettings (QAD_Desktop* parent, char* moduleName); + virtual bool CustomPopup (QAD_Desktop* parent, QPopupMenu* popup, + const QString & theContext, + const QString & theParent, + const QString & theObject); + virtual void DefinePopup (QString & theContext, QString & theParent, + QString & theObject) ; + virtual bool ActiveStudyChanged (QAD_Desktop* parent); protected: -- 2.39.2