2 //=============================================================================
3 // File : SALOME_PYQT_GUI.cxx
4 // Created : mer jun 4 17:17:20 UTC 2003
5 // Author : Paul RASCLE, EDF
7 // Copyright : EDF 2003
9 //=============================================================================
11 #include "SALOME_PYQT_GUI.hxx"
13 #include "QAD_Desktop.h"
15 #include "QAD_MessageBox.h"
16 #include "SALOME_Selection.h"
17 #include "SALOME_InteractiveObject.hxx"
18 #include "SALOMEGUI_QtCatchCorbaException.hxx"
19 #include "utilities.h"
20 #include "PyInterp_PyQt.h"
21 //#include <cStringIO.h>
23 #include <sipSalomePyQtDeclSalomePyQt.h>
24 #include <sipqtQWorkspace.h>
25 #include <sipqtQPopupMenu.h>
30 static PyInterp_PyQt *interp = NULL;
31 static map<int,PyInterp_PyQt*> mapInterp;
32 static PyObject *module;
33 static string _moduleName;
35 //=============================================================================
37 * Calls module.setWorkSpace with PyQt QWorkspace object to use with
40 //=============================================================================
42 static void setWorkSpace()
44 MESSAGE("setWorkSpace");
48 pyws=sipMapCppToSelf( QAD_Application::getDesktop()->getMainFrame(),
50 res=PyObject_CallMethod(module,"setWorkSpace","O",pyws);
51 SCRUTE(pyws->ob_refcnt);
64 //=============================================================================
66 * Initialises python interpreter (only one per study), imports python module
67 * from given module name, sets static reference to module,
68 * sets module workspace.
70 //=============================================================================
72 static void initInterp(int StudyID)
74 MESSAGE("initInterp");
75 if (mapInterp.find(StudyID) != mapInterp.end())
77 MESSAGE ( " StudyID is found " << StudyID );
78 interp = mapInterp[StudyID];
83 MESSAGE ( " StudyID is not found " << StudyID );
84 interp=new PyInterp_PyQt();
85 mapInterp[StudyID] = interp;
90 module=PyImport_ImportModule((char*)_moduleName.c_str());
93 INFOS ( " Problem... " );
103 //=============================================================================
105 * Calls python module.OnGUIEvent(theCommandID)
107 //=============================================================================
109 bool SALOME_PYQT_GUI::OnGUIEvent (int theCommandID,
112 MESSAGE("SALOME_PYQT_GUI::OnGUIEvent");
116 res=PyObject_CallMethod(module,"OnGUIEvent","i",theCommandID);
128 //=============================================================================
130 * no call to python module.OnKeyPress()
132 //=============================================================================
134 bool SALOME_PYQT_GUI::OnKeyPress (QKeyEvent* pe,
136 QAD_StudyFrame* studyFrame)
138 MESSAGE("SALOME_PYQT_GUI::OnKeyPress");
142 //=============================================================================
144 * no call to python module.OnMousePress()
146 //=============================================================================
148 bool SALOME_PYQT_GUI::OnMousePress (QMouseEvent* pe ,
150 QAD_StudyFrame* studyFrame)
152 MESSAGE("SALOME_PYQT_GUI::OnMousePress");
156 //=============================================================================
158 * no call to python module.OnMouseMove()
160 //=============================================================================
162 bool SALOME_PYQT_GUI::OnMouseMove (QMouseEvent* pe ,
164 QAD_StudyFrame* studyFrame)
166 // La ligne suivante est commentée sinon multiple traces ...
167 // MESSAGE("SALOME_PYQT_GUI::OnMouseMouve");
171 //=============================================================================
173 * Calls initInterp to initialise python interpreter (only one per study) and
174 * to import python module. Calls module.setSettings()
176 //=============================================================================
178 bool SALOME_PYQT_GUI::SetSettings (QAD_Desktop* parent, char* moduleName)
180 MESSAGE("SALOME_PYQT_GUI::SetSettings");
182 int StudyID = QAD_Application::getDesktop()->getActiveStudy()->getStudyId();
184 _moduleName = moduleName + string("GUI");
189 res=PyObject_CallMethod(module,"setSettings","");
201 //=============================================================================
203 * Calls module.customPopup with popup menu to custom, and string values of
204 * context, parent and selected object (strings defined by DefinePopup, which
207 //=============================================================================
209 bool SALOME_PYQT_GUI::CustomPopup ( QAD_Desktop* parent,
211 const QString & theContext,
212 const QString & theParent,
213 const QString & theObject )
215 MESSAGE("SALOME_PYQT_GUI::CustomPopup");
217 MESSAGE ( " theContext : " << theContext.latin1() );
218 MESSAGE ( " theParent : " << theParent.latin1() );
219 MESSAGE ( " theObject : " << theObject.latin1() );
221 PyObject *res,*pypop;
223 pypop=sipMapCppToSelf( popup,
224 sipClass_QPopupMenu);
226 res=PyObject_CallMethod(module,"customPopup","Osss",pypop,
227 theContext.latin1(), theObject.latin1(), theParent.latin1());
244 //=============================================================================
246 * Calls module.definePopup to modify the strings that define context parent
247 * and selected object. Called before CustomPopup.
249 //=============================================================================
251 void SALOME_PYQT_GUI::DefinePopup( QString & theContext,
253 QString & theObject )
255 MESSAGE("SALOME_PYQT_GUI::DefinePopup");
262 res=PyObject_CallMethod(module,"definePopup","sss",
263 theContext.latin1(), theObject.latin1(), theParent.latin1());
271 int parseOk = PyArg_ParseTuple(res, "sss", &co, &ob, &pa);
273 MESSAGE ("parseOk " << parseOk);
274 MESSAGE (" --- " << co << " " << ob << " " << pa);
282 MESSAGE ( " theContext : " << theContext.latin1() );
283 MESSAGE ( " theParent : " << theParent.latin1() );
284 MESSAGE ( " theObject : " << theObject.latin1() );
288 //=============================================================================
290 * Initialize new interpreter (if not exists) with new study ID.
291 * Calls module.activeStudyChanged with new study ID. Called twice.
293 //=============================================================================
295 void SALOME_PYQT_GUI::ActiveStudyChanged( QAD_Desktop* parent )
297 MESSAGE("SALOME_PYQT_GUI::ActiveStudyChanged");
300 int StudyID = parent->getActiveApp()->getActiveStudy()->getStudyId();
304 res=PyObject_CallMethod(module,"activeStudyChanged","i", StudyID );
317 //=============================================================================
321 //=============================================================================
326 bool OnGUIEvent(int theCommandID, QAD_Desktop* parent)
328 return SALOME_PYQT_GUI::OnGUIEvent(theCommandID, parent);
331 bool OnKeyPress(QKeyEvent* pe, QAD_Desktop* parent, QAD_StudyFrame* studyFrame)
333 return SALOME_PYQT_GUI::OnKeyPress(pe, parent, studyFrame);
336 bool OnMousePress(QMouseEvent* pe, QAD_Desktop* parent, QAD_StudyFrame* studyFrame)
338 return SALOME_PYQT_GUI::OnMousePress(pe, parent, studyFrame);
341 bool OnMouseMove(QMouseEvent* pe, QAD_Desktop* parent, QAD_StudyFrame* studyFrame)
343 return SALOME_PYQT_GUI::OnMouseMove(pe, parent, studyFrame);
346 bool SetSettings(QAD_Desktop* parent, char* moduleName)
348 return SALOME_PYQT_GUI::SetSettings(parent, moduleName);
351 bool customPopup(QAD_Desktop* parent, QPopupMenu* popup, const QString & theContext,
352 const QString & theParent, const QString & theObject)
354 return SALOME_PYQT_GUI::CustomPopup( parent, popup, theContext, theParent, theObject );
357 void definePopup(QString & theContext, QString & theParent, QString & theObject)
359 SALOME_PYQT_GUI::DefinePopup(theContext, theParent, theObject);
362 void activeStudyChanged ( QAD_Desktop* parent )
364 SALOME_PYQT_GUI::ActiveStudyChanged(parent);