From: nds Date: Mon, 6 Oct 2008 09:19:05 +0000 (+0000) Subject: Merging from the BR_VP5_DEV branch. X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=6b78afdf59857b9a63851c66adf8afd2aafe7c91;p=modules%2Fgui.git Merging from the BR_VP5_DEV branch. --- diff --git a/src/Plot2d/resources/plot2d_legend.png b/src/Plot2d/resources/plot2d_legend.png index cdcc1e0d8..81c06277b 100755 Binary files a/src/Plot2d/resources/plot2d_legend.png and b/src/Plot2d/resources/plot2d_legend.png differ diff --git a/src/Plot2d/resources/plot2d_linear.png b/src/Plot2d/resources/plot2d_linear.png index d79f21426..0140fcc98 100755 Binary files a/src/Plot2d/resources/plot2d_linear.png and b/src/Plot2d/resources/plot2d_linear.png differ diff --git a/src/Plot2d/resources/plot2d_linear_y.png b/src/Plot2d/resources/plot2d_linear_y.png index e396eac2e..7acc8fe79 100755 Binary files a/src/Plot2d/resources/plot2d_linear_y.png and b/src/Plot2d/resources/plot2d_linear_y.png differ diff --git a/src/Plot2d/resources/plot2d_lines.png b/src/Plot2d/resources/plot2d_lines.png index 6baf57344..978945284 100755 Binary files a/src/Plot2d/resources/plot2d_lines.png and b/src/Plot2d/resources/plot2d_lines.png differ diff --git a/src/Plot2d/resources/plot2d_log.png b/src/Plot2d/resources/plot2d_log.png index aecca8c13..fb62cd772 100755 Binary files a/src/Plot2d/resources/plot2d_log.png and b/src/Plot2d/resources/plot2d_log.png differ diff --git a/src/Plot2d/resources/plot2d_log_y.png b/src/Plot2d/resources/plot2d_log_y.png index 4e1e21147..825d59edb 100755 Binary files a/src/Plot2d/resources/plot2d_log_y.png and b/src/Plot2d/resources/plot2d_log_y.png differ diff --git a/src/Plot2d/resources/plot2d_points.png b/src/Plot2d/resources/plot2d_points.png index 4847c4e8b..3cdea33dd 100755 Binary files a/src/Plot2d/resources/plot2d_points.png and b/src/Plot2d/resources/plot2d_points.png differ diff --git a/src/Plot2d/resources/plot2d_settings.png b/src/Plot2d/resources/plot2d_settings.png index d291da9dc..64df2460b 100755 Binary files a/src/Plot2d/resources/plot2d_settings.png and b/src/Plot2d/resources/plot2d_settings.png differ diff --git a/src/Plot2d/resources/plot2d_splines.png b/src/Plot2d/resources/plot2d_splines.png index c39d4321c..06a95572d 100755 Binary files a/src/Plot2d/resources/plot2d_splines.png and b/src/Plot2d/resources/plot2d_splines.png differ diff --git a/src/PyInterp/PyInterp.pro b/src/PyInterp/PyInterp.pro index 8ee7c1f25..62e78e807 100644 --- a/src/PyInterp/PyInterp.pro +++ b/src/PyInterp/PyInterp.pro @@ -5,7 +5,7 @@ MOC_DIR = ../../moc OBJECTS_DIR = ../../$(CONFIG_ID)/obj/$$TARGET INCLUDEPATH += ../../include $$(PYTHONINC) -unix:LIBS += -L$$(PYTHONLIB) -lpython2.5 +unix:LIBS += -L$$(PYTHONLIB) -lpython2.5 -L../../$(CONFIG_ID)/lib -lEvent win32:LIBS += /LIBPATH:$$(PYTHONLIB) CONFIG -= debug release debug_and_release diff --git a/src/PyInterp/PyInterp_Dispatcher.cxx b/src/PyInterp/PyInterp_Dispatcher.cxx index e3adb001d..2fbda19ee 100755 --- a/src/PyInterp/PyInterp_Dispatcher.cxx +++ b/src/PyInterp/PyInterp_Dispatcher.cxx @@ -23,10 +23,23 @@ #include "PyInterp_Dispatcher.h" // !!! WARNING !!! THIS INCLUDE MUST BE THE VERY FIRST !!! #include "PyInterp_Interp.h" #include "PyInterp_Watcher.h" +#include #include #include +class PyInterp_ExecuteEvent: public SALOME_Event +{ +public: + PyInterp_Request* myRequest; + PyInterp_ExecuteEvent( PyInterp_Request* r ) + : myRequest( r ) {} + virtual void Execute() + { + myRequest->execute(); + } +}; + using namespace std; PyInterp_Dispatcher* PyInterp_Dispatcher::myInstance = 0; @@ -49,7 +62,7 @@ void PyInterp_Request::process() void PyInterp_Request::safeExecute() { - execute(); + ProcessVoidEvent( new PyInterp_ExecuteEvent( this ) ); } void PyInterp_Request::Destroy( PyInterp_Request* request ) @@ -62,7 +75,7 @@ void PyInterp_Request::Destroy( PyInterp_Request* request ) QEvent* PyInterp_Request::createEvent() const { - return new PyInterp_Event( PyInterp_Event::NOTIFY, (PyInterp_Request*)this ); + return new PyInterp_Event( PyInterp_Event::ES_NOTIFY, (PyInterp_Request*)this ); } void PyInterp_Request::processEvent( QObject* o ) @@ -94,7 +107,7 @@ void PyInterp_LockRequest::safeExecute() { if ( getInterp() ){ PyLockWrapper aLock = getInterp()->GetLockWrapper(); - execute(); + ProcessVoidEvent( new PyInterp_ExecuteEvent( this ) ); } } diff --git a/src/PyInterp/PyInterp_Dispatcher.h b/src/PyInterp/PyInterp_Dispatcher.h index cf46694e4..5040b1032 100755 --- a/src/PyInterp/PyInterp_Dispatcher.h +++ b/src/PyInterp/PyInterp_Dispatcher.h @@ -35,10 +35,12 @@ class QObject; class PyInterp_Interp; class PyInterp_Watcher; class PyInterp_Dispatcher; +class PyInterp_ExecuteEvent; class PYINTERP_EXPORT PyInterp_Request { friend class PyInterp_Dispatcher; + friend class PyInterp_ExecuteEvent; PyInterp_Request(); PyInterp_Request( const PyInterp_Request& ); @@ -102,7 +104,8 @@ class PYINTERP_EXPORT PyInterp_Event : public QEvent PyInterp_Event( const PyInterp_Event& ); public: - enum { NOTIFY = QEvent::User + 5000, OK, ERROR, INCOMPLETE, LAST }; + //Execution state + enum { ES_NOTIFY = QEvent::User + 5000, ES_OK, ES_ERROR, ES_INCOMPLETE, ES_LAST }; PyInterp_Event( int type, PyInterp_Request* request ) : QEvent( (QEvent::Type)type ), myRequest( request ) {} diff --git a/src/PyInterp/PyInterp_base.cxx b/src/PyInterp/PyInterp_base.cxx deleted file mode 100644 index 1ff7cd241..000000000 --- a/src/PyInterp/PyInterp_base.cxx +++ /dev/null @@ -1,317 +0,0 @@ -// Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License. -// -// This library is distributed in the hope that it will be useful -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com -// -// SALOME SALOMEGUI : implementation of desktop and GUI kernel -// -// File : PyInterp_base.cxx -// Author : Christian CAREMOLI, Paul RASCLE, EDF -// Module : SALOME -// $Header$ - - -#include "PyInterp_base.h" // this include must be first (see PyInterp_base.h)! - -#include - -#include -#include - -using namespace std; - -PyLockWrapper::PyLockWrapper(PyThreadState* theThreadState): - myThreadState(theThreadState), - mySaveThreadState(0) -{ -#if defined(USE_GILSTATE) - if (myThreadState->interp == PyInterp_base::_interp) { - _savestate = PyGILState_Ensure(); - } else { - PyEval_AcquireThread(myThreadState); - } -#else - PyEval_AcquireThread(myThreadState); -#endif -} - -PyLockWrapper::~PyLockWrapper() -{ -#if defined(USE_GILSTATE) - if (myThreadState->interp == PyInterp_base::_interp) { - PyGILState_Release(_savestate); - } else { - PyEval_ReleaseThread(myThreadState); - } -#else - PyEval_ReleaseThread(myThreadState); -#endif -} - -class PyReleaseLock{ -public: - ~PyReleaseLock(){ - PyEval_ReleaseLock(); - } -}; - - -PyLockWrapper PyInterp_base::GetLockWrapper(){ - return _tstate; -} - - -// main python interpreter (static attributes) - -int PyInterp_base::_argc = 1; -char* PyInterp_base::_argv[] = {""}; - -PyObject *PyInterp_base::builtinmodule = NULL; - -PyThreadState *PyInterp_base::_gtstate = NULL; -PyInterpreterState *PyInterp_base::_interp = NULL; - - -/*! - * basic constructor here : herited classes constructors must call initalize() method - * defined here. - */ -PyInterp_base::PyInterp_base(): _tstate(0), _vout(0), _verr(0), _g(0), _atFirst(true) -{ -} - -PyInterp_base::~PyInterp_base() -{ -} - - -/*! - * Must be called by herited classes constructors. initialize() calls virtuals methods - * initstate & initcontext, not defined here in base class. initstate & initcontext methods - * must be implemented in herited classes, following the Python interpreter policy - * (mono or multi interpreter...). - */ -void PyInterp_base::initialize() -{ - _history.clear(); // start a new list of user's commands - _ith = _history.begin(); - - init_python(); - // Here the global lock is released - - initState(); - - PyLockWrapper aLock= GetLockWrapper(); - - initContext(); - - // used to interpret & compile commands - PyObjWrapper m(PyImport_ImportModule("codeop")); - if(!m){ - PyErr_Print(); - return; - } - - // Create cStringIO to capture stdout and stderr - PycString_IMPORT; - if (PycStringIO) { // CTH11627 : additional check - _vout = PycStringIO->NewOutput(128); - _verr = PycStringIO->NewOutput(128); - } - - // All the initRun outputs are redirected to the standard output (console) - initRun(); -} - -void PyInterp_base::init_python() -{ - _atFirst = false; - if (Py_IsInitialized()) - return; - - // Python is not initialized - Py_SetProgramName(_argv[0]); - Py_Initialize(); // Initialize the interpreter - PySys_SetArgv(_argc, _argv); - PyEval_InitThreads(); // Create (and acquire) the interpreter lock - _interp = PyThreadState_Get()->interp; - _gtstate = PyEval_SaveThread(); // Release global thread state -} - -string PyInterp_base::getbanner() -{ - // Should we take the lock ? - // PyEval_RestoreThread(_tstate); - string aBanner("Python "); - aBanner = aBanner + Py_GetVersion() + " on " + Py_GetPlatform() ; - aBanner = aBanner + "\ntype help to get general information on environment\n"; - //PyEval_SaveThread(); - return aBanner; -} - - -int PyInterp_base::initRun() -{ - PySys_SetObject("stderr",_verr); - PySys_SetObject("stdout",_vout); - - PyObjWrapper verr(PyObject_CallMethod(_verr,"reset","")); - PyObjWrapper vout(PyObject_CallMethod(_vout,"reset","")); - - //PyObject *m = PyImport_GetModuleDict(); - - PySys_SetObject("stdout",PySys_GetObject("__stdout__")); - PySys_SetObject("stderr",PySys_GetObject("__stderr__")); - - return 0; -} - - -/*! - * This function compiles a string (command) and then evaluates it in the dictionnary - * context if possible. - * Returns : - * -1 : fatal error - * 1 : incomplete text - * 0 : complete text executed with success - */ -int compile_command(const char *command,PyObject *context) -{ - PyObject *m = PyImport_AddModule("codeop"); - if(!m){ // Fatal error. No way to go on. - PyErr_Print(); - return -1; - } - PyObjWrapper v(PyObject_CallMethod(m,"compile_command","s",command)); - if(!v){ - // Error encountered. It should be SyntaxError, - //so we don't write out traceback - PyObjWrapper exception, value, tb; - PyErr_Fetch(&exception, &value, &tb); - PyErr_NormalizeException(&exception, &value, &tb); - PyErr_Display(exception, value, NULL); - return -1; - }else if (v == Py_None){ - // Incomplete text we return 1 : we need a complete text to execute - return 1; - }else{ - // Complete and correct text. We evaluate it. - //#if PY_VERSION_HEX < 0x02040000 // python version earlier than 2.4.0 - // PyObjWrapper r(PyEval_EvalCode(v,context,context)); - //#else - PyObjWrapper r(PyEval_EvalCode((PyCodeObject *)(void *)v,context,context)); - //#endif - if(!r){ - // Execution error. We return -1 - PyErr_Print(); - return -1; - } - // The command has been successfully executed. Return 0 - return 0; - } -} - - -int PyInterp_base::run(const char *command) -{ - if(_atFirst){ - int ret = 0; - ret = simpleRun("from Help import *"); - if (ret) { - _atFirst = false; - return ret; - } - ret = simpleRun("import salome"); - if (ret) { - _atFirst = false; - return ret; - } - ret = simpleRun("salome.salome_init(0,1)"); - if (ret) { - _atFirst = false; - return ret; - } - _atFirst = false; - } - return simpleRun(command); -} - - -int PyInterp_base::simpleRun(const char *command) -{ - if( !_atFirst && strcmp(command,"") != 0 ) { - _history.push_back(command); - _ith = _history.end(); - } - - // We come from C++ to enter Python world - // We need to acquire the Python global lock - //PyLockWrapper aLock(_tstate); // san - lock is centralized now - - // Reset redirected outputs before treatment - PySys_SetObject("stderr",_verr); - PySys_SetObject("stdout",_vout); - - PyObjWrapper verr(PyObject_CallMethod(_verr,"reset","")); - PyObjWrapper vout(PyObject_CallMethod(_vout,"reset","")); - - int ier = compile_command(command,_g); - - // Outputs are redirected on standards outputs (console) - PySys_SetObject("stdout",PySys_GetObject("__stdout__")); - PySys_SetObject("stderr",PySys_GetObject("__stderr__")); - - return ier; -} - - -const char * PyInterp_base::getPrevious() -{ - if(_ith != _history.begin()){ - _ith--; - return (*_ith).c_str(); - } - else - return BEGIN_HISTORY_PY; -} - - -const char * PyInterp_base::getNext() -{ - if(_ith != _history.end()){ - _ith++; - } - if (_ith == _history.end()) - return TOP_HISTORY_PY; - else - return (*_ith).c_str(); -} - - -string PyInterp_base::getverr(){ - //PyLockWrapper aLock(_tstate); - PyObjWrapper v(PycStringIO->cgetvalue(_verr)); - string aRet(PyString_AsString(v)); - return aRet; -} - - -string PyInterp_base::getvout(){ - //PyLockWrapper aLock(_tstate); - PyObjWrapper v(PycStringIO->cgetvalue(_vout)); - string aRet(PyString_AsString(v)); - return aRet; -} diff --git a/src/PyInterp/PyInterp_base.h b/src/PyInterp/PyInterp_base.h deleted file mode 100644 index a00056e86..000000000 --- a/src/PyInterp/PyInterp_base.h +++ /dev/null @@ -1,145 +0,0 @@ -// Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License. -// -// This library is distributed in the hope that it will be useful -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com -// -// SALOME SALOMEGUI : implementation of desktop and GUI kernel -// -// File : PyInterp_base.h -// Author : Christian CAREMOLI, Paul RASCLE, EDF -// Module : SALOME - -#ifndef _PYINTERP_BASE_H_ -#define _PYINTERP_BASE_H_ - -#include "PyInterp.h" - -#include -#include -#include - -// include order important! -// pthread then python then qt -//#include // must be before Python.h ! - -#include // must be before qt includes ... -#include // Python include needed for versions before 2.4. Included in Python.h now. -#include // Python include needed for versions before 2.4. Included in Python.h now. - -//#if PY_VERSION_HEX < 0x02040000 // python version earlier than 2.4.0 -//extern "C" PyObject * PyEval_EvalCode(PyObject *co, PyObject *g, PyObject *l); -//#endif - -/* For 2.3, use the PyGILState_ calls */ -#if (PY_VERSION_HEX >= 0x02030000) -#define USE_GILSTATE -#endif - -#define TOP_HISTORY_PY "--- top of history ---" -#define BEGIN_HISTORY_PY "--- begin of history ---" - -class PYINTERP_EXPORT PyLockWrapper -{ - PyThreadState* myThreadState; - PyThreadState* mySaveThreadState; -#if defined(USE_GILSTATE) - PyGILState_STATE _savestate ; -#endif - public: - PyLockWrapper(PyThreadState* theThreadState); - ~PyLockWrapper(); -}; - -class PYINTERP_EXPORT PyInterp_base{ - public: - static int _argc; - static char* _argv[]; - static PyObject *builtinmodule; - static PyThreadState *_gtstate; - static PyInterpreterState *_interp; - - PyInterp_base(); - virtual ~PyInterp_base(); - - virtual void initialize(); - virtual void init_python(); - // init_python() made virtual to: - // 1. Remove dependency on KERNEL in light SALOME configuration - // 2. Allow redefinition of this method in SalomeApp_PyInterp class (it should be empty there and rely on KERNEL_PYTHON) - - virtual int run(const char *command); - - PyLockWrapper GetLockWrapper(); - - std::string getbanner(); - std::string getverr(); - std::string getvout(); - - const char * getPrevious(); - const char * getNext(); - - protected: - PyThreadState * _tstate; - PyObject * _vout; - PyObject * _verr; - PyObject * _g; - PyObject * _codeop; - std::list _history; - std::list::iterator _ith; - bool _atFirst; - - int simpleRun(const char* command); - int initRun(); - - virtual bool initState() = 0; - virtual bool initContext() = 0; -}; - - -class PYINTERP_EXPORT PyObjWrapper{ - PyObject* myObject; -public: - PyObjWrapper(PyObject* theObject): myObject(theObject) {} - PyObjWrapper(): myObject(0) {} - operator PyObject*(){ - return myObject; - } - PyObject* operator->(){ - return myObject; - } - PyObject* get(){ - return myObject; - } - bool operator!(){ - return !myObject; - } - bool operator==(PyObject* theObject){ - return myObject == theObject; - } - PyObject** operator&(){ - return &myObject; - } - PyObjWrapper& operator=(PyObjWrapper* theObjWrapper){ - Py_XDECREF(myObject); - myObject = theObjWrapper->myObject; - return *this; - } - virtual ~PyObjWrapper(){ - Py_XDECREF(myObject); - } -}; - -#endif