// $Header$
//=============================================================================
-#include "SALOME_PYQT_GUI.hxx"
+#include "SALOME_PYQT_GUI.h"
#include "QAD_Desktop.h"
-#include "QAD_MessageBox.h"
#include "SALOME_Selection.h"
#include "SALOME_InteractiveObject.hxx"
#include "SALOMEGUI_QtCatchCorbaException.hxx"
#include "utilities.h"
-#include "PyInterp_PyQt.h"
-//#include <cStringIO.h>
#include <sipSalomePyQtDeclSalomePyQt.h>
#include <sipqtQWorkspace.h>
static PyInterp_PyQt *interp = NULL;
static map<int,PyInterp_PyQt*> mapInterp;
-static PyObject *module;
-static string _moduleName;
//=============================================================================
/*!
*/
//=============================================================================
-static void setWorkSpace()
+void SALOME_PYQT_GUI::setWorkSpace()
{
MESSAGE("setWorkSpace");
PyLockWrapper aLock = interp->GetLockWrapper();
PyObjWrapper pyws(sipMapCppToSelf( QAD_Application::getDesktop()->getMainFrame(),
sipClass_QWorkspace));
- PyObjWrapper res(PyObject_CallMethod(module,"setWorkSpace","O",pyws.get()));
+ PyObjWrapper res(PyObject_CallMethod(_module,"setWorkSpace","O",pyws.get()));
SCRUTE(pyws->ob_refcnt);
if(!res){
PyErr_Print();
}
}
+//=============================================================================
+/*!
+ * Import Python module (from _moduleName)
+ */
+//=============================================================================
+void SALOME_PYQT_GUI::importModule()
+{
+ PyLockWrapper aLock = interp->GetLockWrapper();
+
+ _module=PyImport_ImportModule((char*)_moduleName.c_str());
+ if(!_module){
+ MESSAGE ( " Problem... " );
+ PyErr_Print();
+ return;
+ }
+}
+
//=============================================================================
/*!
* Initialises python interpreter (only one per study), imports python module
*/
//=============================================================================
-static void initInterp(int StudyID)
+void SALOME_PYQT_GUI::initInterp(int StudyID)
{
MESSAGE("initInterp");
if(mapInterp.find(StudyID) != mapInterp.end()){
interp=new PyInterp_PyQt();
mapInterp[StudyID] = interp;
}
+ // imports Python GUI module and puts it in _module attribute
+ importModule();
+ // calls _module.setWorkspace and passes the SIP object main workspace
+ setWorkSpace();
- PyLockWrapper aLock = interp->GetLockWrapper();
+}
- PyObjWrapper res(PyImport_ImportModule((char*)_moduleName.c_str()));
- if(!res){
- MESSAGE ( " Problem... " );
- PyErr_Print();
- return;
- }
+//=============================================================================
+/*!
+ * constructor : only calls SALOMEGUI constructor
+ */
+//=============================================================================
+SALOME_PYQT_GUI::SALOME_PYQT_GUI( const QString& theName, QObject* theParent ) :
+ SALOMEGUI( theName, theParent )
+{
+ MESSAGE("SALOME_PYQT_GUI::SALOME_PYQT_GUI");
+}
- // PyQt import is OK
- setWorkSpace();
+//=============================================================================
+/*!
+ * destructor : do nothing
+ */
+//=============================================================================
+SALOME_PYQT_GUI::~SALOME_PYQT_GUI()
+{
}
//=============================================================================
MESSAGE("SALOME_PYQT_GUI::OnGUIEvent");
PyLockWrapper aLock = interp->GetLockWrapper();
- PyObjWrapper res(PyObject_CallMethod(module,"OnGUIEvent","i",theCommandID));
+ PyObjWrapper res(PyObject_CallMethod(_module,"OnGUIEvent","i",theCommandID));
if(!res){
PyErr_Print();
return false;
SCRUTE ( StudyID );
_moduleName = moduleName + string("GUI");
SCRUTE(_moduleName);
+
+ // initializes one Python interpreter by study and puts it in interp global variable
+ // imports Python GUI module and puts it in _module attribute
+ // calls _module.setWorkspace and passes the SIP object main workspace
initInterp(StudyID);
PyLockWrapper aLock = interp->GetLockWrapper();
- PyObjWrapper module(PyImport_ImportModule((char*)_moduleName.c_str()));
- if(!module){
+ _module = PyImport_ImportModule((char*)_moduleName.c_str());
+ if(!_module){
PyErr_Print();
return false;
}
- PyObjWrapper res(PyObject_CallMethod(module,"setSettings",""));
+ PyObjWrapper res(PyObject_CallMethod(_module,"setSettings",""));
if(!res){
PyErr_Print();
return false;
PyObjWrapper pypop(sipMapCppToSelf( popup, sipClass_QPopupMenu));
- PyObjWrapper res(PyObject_CallMethod(module,"customPopup",
+ PyObjWrapper res(PyObject_CallMethod(_module,"customPopup",
"Osss",pypop.get(),
theContext.latin1(),
theObject.latin1(),
QString & theObject )
{
MESSAGE("SALOME_PYQT_GUI::DefinePopup");
- theContext = "";
- theObject = "";
- theParent = "";
+ //theContext = "";
+ //theObject = "";
+ //theParent = "";
PyLockWrapper aLock = interp->GetLockWrapper();
- PyObjWrapper res(PyObject_CallMethod(module,"definePopup","sss",
+ PyObjWrapper res(PyObject_CallMethod(_module,"definePopup","sss",
theContext.latin1(),
theObject.latin1(),
theParent.latin1()));
return;
}
char *co, *ob, *pa;
- int parseOk = PyArg_ParseTuple(res, "sss", &co, &ob, &pa);
+ if(!PyArg_ParseTuple(res, "sss", &co, &ob, &pa))
+ {
+ // It's not a valid tuple. Do nothing.
+ return;
+ }
- MESSAGE ("parseOk " << parseOk);
+ MESSAGE ("parseOk ");
MESSAGE (" --- " << co << " " << ob << " " << pa);
theContext = co;
PyLockWrapper aLock = interp->GetLockWrapper();
- PyObjWrapper res(PyObject_CallMethod(module,"activeStudyChanged","i", StudyID ));
+ PyObjWrapper res(PyObject_CallMethod(_module,"activeStudyChanged","i", StudyID ));
if(!res){
PyErr_Print();
return false;
return true;
}
+//=============================================================================
+/*!
+ * no call to python module.BuildPresentation() (not yet ???)
+ */
+//=============================================================================
+void SALOME_PYQT_GUI::BuildPresentation( const Handle(SALOME_InteractiveObject)& theIO )
+{
+}
//=============================================================================
/*!
- *
+ * no call to python module.SupportedViewType() (not yet ???)
*/
//=============================================================================
+void SALOME_PYQT_GUI::SupportedViewType(int* buffer, int bufferSize)
+{
+}
+//=============================================================================
+/*!
+ * no call to python module.Deactivate() (not yet ???)
+ */
+//=============================================================================
+void SALOME_PYQT_GUI::Deactivate()
+{
+}
+
+
+
+
+//=============================================================================
+/*!
+ * Component GUI Factory : returns a new GUI obj at each call
+ */
+//=============================================================================
-static SALOME_PYQT_GUI aGUI("");
extern "C"
{
Standard_EXPORT SALOMEGUI* GetComponentGUI() {
- return &aGUI;
+ MESSAGE("SALOME_PYQT_GUI::GetComponentGUI");
+ SALOMEGUI* aGUI = new SALOME_PYQT_GUI("");
+ return aGUI;
}
}
--- /dev/null
+//=============================================================================
+// File : SALOME_PYQT_GUI.hxx
+// Created : mer jun 4 17:17:20 UTC 2003
+// Author : Paul RASCLE, EDF
+// Project : SALOME
+// Copyright : EDF 2003
+// $Header$
+//=============================================================================
+
+#ifndef _SALOME_PYQT_GUI_HXX_
+#define _SALOME_PYQT_GUI_HXX_
+
+#include "QAD_Desktop.h"
+#include "PyInterp_PyQt.h"
+#include "SALOMEGUI.h"
+
+class SALOME_PYQT_GUI: public SALOMEGUI
+{
+ Q_OBJECT;
+
+private:
+ // save the current Python module in the attribute _module
+ PyObjWrapper _module;
+ // save the current Python module name in the attribute _moduleName
+ string _moduleName;
+
+public:
+
+ 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);
+ virtual void BuildPresentation ( const Handle(SALOME_InteractiveObject)& theIO );
+ virtual void SupportedViewType (int* buffer, int bufferSize);
+ virtual void Deactivate ();
+ void initInterp(int studyId);
+ void importModule();
+ void setWorkSpace();
+
+protected:
+
+};
+
+#endif
+++ /dev/null
-//=============================================================================
-// File : SALOME_PYQT_GUI.hxx
-// Created : mer jun 4 17:17:20 UTC 2003
-// Author : Paul RASCLE, EDF
-// Project : SALOME
-// Copyright : EDF 2003
-// $Header$
-//=============================================================================
-
-#ifndef _SALOME_PYQT_GUI_HXX_
-#define _SALOME_PYQT_GUI_HXX_
-
-#include "QAD_Desktop.h"
-#include "SALOMEGUI.h"
-
-class SALOME_PYQT_GUI: public SALOMEGUI
-{
- Q_OBJECT;
-
-private:
-
-public:
-
- 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:
-
-};
-
-#endif