From: prascle Date: Wed, 12 May 2004 13:28:29 +0000 (+0000) Subject: PR: KERNEL 5852 X-Git-Tag: Ecole_Ete_a5~6 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=8eb7c18420743aca682b329c8641e4479ad189d1;p=modules%2Fkernel.git PR: KERNEL 5852 --- diff --git a/src/SALOMEGUI/QAD_Desktop.cxx b/src/SALOMEGUI/QAD_Desktop.cxx index 528ce0b53..ea07b4373 100644 --- a/src/SALOMEGUI/QAD_Desktop.cxx +++ b/src/SALOMEGUI/QAD_Desktop.cxx @@ -2612,12 +2612,8 @@ void QAD_Desktop::setSettings() { SALOMEGUI* anActiveGUI = getActiveGUI(); if ( anActiveGUI ) { - if (_islibso) - anActiveGUI->SetSettings( this ); - else { - QString Component = mapComponentName[myActiveComp]; - anActiveGUI->SetSettings( this, (char*)Component.latin1() ); - } + QString Component = mapComponentName[myActiveComp]; + anActiveGUI->SetSettings( this, (char*)Component.latin1() ); } } @@ -2706,10 +2702,7 @@ bool QAD_Desktop::loadComponent(QString Component) return false; /* SETTINGS */ - if (_islibso) - anActiveGUI->SetSettings( this ); - else - anActiveGUI->SetSettings( this, (char*)Component.latin1() ); + anActiveGUI->SetSettings( this, (char*)Component.latin1() ); /* COMPONENT INTERFACE */ SALOME_ModuleCatalog::Acomponent_ptr aComponent = @@ -3242,6 +3235,8 @@ SALOMEGUI* QAD_Desktop::getComponentGUI( const QString& component ) QAD_WaitCursor wc; + _islibso= false; + if ( libs = getenv("LD_LIBRARY_PATH")) { // MESSAGE ( " LD_LIBRARY_PATH : " << libs ); QStringList dirList = QStringList::split( SEPARATOR, libs, false ); // skip empty entries diff --git a/src/SALOMEGUI/SALOMEGUI.cxx b/src/SALOMEGUI/SALOMEGUI.cxx index 1092b50f8..5f853a485 100644 --- a/src/SALOMEGUI/SALOMEGUI.cxx +++ b/src/SALOMEGUI/SALOMEGUI.cxx @@ -107,7 +107,7 @@ bool SALOMEGUI::SetSettings( QAD_Desktop* parent ) //============================================================================= bool SALOMEGUI::SetSettings( QAD_Desktop* parent, char* compName ) { - return true; + return SetSettings( parent); } //============================================================================= diff --git a/src/SALOME_PYQT/Makefile.in b/src/SALOME_PYQT/Makefile.in index 146f123c1..7c1de51a1 100644 --- a/src/SALOME_PYQT/Makefile.in +++ b/src/SALOME_PYQT/Makefile.in @@ -41,6 +41,7 @@ LIB = libSalomePyQtcmodule.la MOC_SRC = sipSalomePyQtProxySalomePyQt_moc.cxx LIB_SRC += SalomePyQt.cxx SALOME_PYQT_GUI.cxx $(SIP_SRC) $(MOC_SRC) +LIB_MOC = SALOME_PYQT_GUI.h #LIB_MOC += sipSalomePyQtProxySalomePyQt.h diff --git a/src/SALOME_PYQT/SALOME_PYQT_GUI.cxx b/src/SALOME_PYQT/SALOME_PYQT_GUI.cxx index 14ef2f968..76b4cc896 100644 --- a/src/SALOME_PYQT/SALOME_PYQT_GUI.cxx +++ b/src/SALOME_PYQT/SALOME_PYQT_GUI.cxx @@ -8,17 +8,14 @@ using namespace std; // $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 #include #include @@ -29,8 +26,6 @@ using namespace std; static PyInterp_PyQt *interp = NULL; static map mapInterp; -static PyObject *module; -static string _moduleName; //============================================================================= /*! @@ -39,7 +34,7 @@ static string _moduleName; */ //============================================================================= -static void setWorkSpace() +void SALOME_PYQT_GUI::setWorkSpace() { MESSAGE("setWorkSpace"); PyLockWrapper aLock = interp->GetLockWrapper(); @@ -53,7 +48,7 @@ static void setWorkSpace() 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(); @@ -61,6 +56,23 @@ static void setWorkSpace() } } +//============================================================================= +/*! + * 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 @@ -69,7 +81,7 @@ static void setWorkSpace() */ //============================================================================= -static void initInterp(int StudyID) +void SALOME_PYQT_GUI::initInterp(int StudyID) { MESSAGE("initInterp"); if(mapInterp.find(StudyID) != mapInterp.end()){ @@ -81,18 +93,31 @@ static void initInterp(int StudyID) 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() +{ } //============================================================================= @@ -107,7 +132,7 @@ bool SALOME_PYQT_GUI::OnGUIEvent (int theCommandID, 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; @@ -172,17 +197,21 @@ bool SALOME_PYQT_GUI::SetSettings (QAD_Desktop* parent, char* moduleName) 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; @@ -214,7 +243,7 @@ bool SALOME_PYQT_GUI::CustomPopup ( QAD_Desktop* parent, 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(), @@ -239,13 +268,13 @@ void SALOME_PYQT_GUI::DefinePopup( QString & theContext, 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())); @@ -254,9 +283,13 @@ void SALOME_PYQT_GUI::DefinePopup( QString & theContext, 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; @@ -284,7 +317,7 @@ bool SALOME_PYQT_GUI::ActiveStudyChanged( QAD_Desktop* parent ) 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; @@ -292,18 +325,47 @@ bool SALOME_PYQT_GUI::ActiveStudyChanged( QAD_Desktop* parent ) 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; } } diff --git a/src/SALOME_PYQT/SALOME_PYQT_GUI.h b/src/SALOME_PYQT/SALOME_PYQT_GUI.h new file mode 100644 index 000000000..2e7617d5a --- /dev/null +++ b/src/SALOME_PYQT/SALOME_PYQT_GUI.h @@ -0,0 +1,52 @@ +//============================================================================= +// 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 diff --git a/src/SALOME_PYQT/SALOME_PYQT_GUI.hxx b/src/SALOME_PYQT/SALOME_PYQT_GUI.hxx deleted file mode 100644 index 618395aa9..000000000 --- a/src/SALOME_PYQT/SALOME_PYQT_GUI.hxx +++ /dev/null @@ -1,47 +0,0 @@ -//============================================================================= -// 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