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;
}
//=============================================================================
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();
}
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;
}
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;
}
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;
}
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);
theContext = co;
theObject = ob;
theParent = pa;
- Py_DECREF(res);
- interp->quit();
MESSAGE ( " theContext : " << theContext.latin1() );
MESSAGE ( " theParent : " << theParent.latin1() );
MESSAGE ( " theObject : " << theObject.latin1() );
-
}
//=============================================================================
*/
//=============================================================================
-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;
}
//=============================================================================
+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;
}
}
-
#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: