From: vsr Date: Tue, 15 May 2007 13:00:11 +0000 (+0000) Subject: Porting to Qt4 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=c67000926ba24ef5042cdf8cb3cae961fc497cc0;p=modules%2Fgui.git Porting to Qt4 --- diff --git a/src/CAF/CAF.h b/src/CAF/CAF.h index d70c01d80..0a0131936 100755 --- a/src/CAF/CAF.h +++ b/src/CAF/CAF.h @@ -20,13 +20,13 @@ #define CAF_H #if defined CAF_EXPORTS -#if defined WNT +#if defined WIN32 #define CAF_EXPORT __declspec( dllexport ) #else #define CAF_EXPORT #endif #else -#if defined WNT +#if defined WIN32 #define CAF_EXPORT __declspec( dllimport ) #else #define CAF_EXPORT @@ -39,7 +39,7 @@ #define true 1 #endif -#if defined WNT +#if defined WIN32 #pragma warning ( disable: 4251 ) #endif diff --git a/src/CAF/CAF_Study.h b/src/CAF/CAF_Study.h index 0e5980cc9..7959d819c 100755 --- a/src/CAF/CAF_Study.h +++ b/src/CAF/CAF_Study.h @@ -30,7 +30,7 @@ class CAF_Application; -#if defined WNT +#if defined WIN32 #pragma warning ( disable: 4251 ) #endif @@ -88,7 +88,7 @@ private: friend class CAF_Operation; }; -#if defined WNT +#if defined WIN32 #pragma warning ( default: 4251 ) #endif diff --git a/src/CAM/CAM.h b/src/CAM/CAM.h index b953c9927..09cc3934d 100755 --- a/src/CAM/CAM.h +++ b/src/CAM/CAM.h @@ -20,13 +20,13 @@ #define CAM_H #if defined CAM_EXPORTS -#if defined WNT +#if defined WIN32 #define CAM_EXPORT __declspec( dllexport ) #else #define CAM_EXPORT #endif #else -#if defined WNT +#if defined WIN32 #define CAM_EXPORT __declspec( dllimport ) #else #define CAM_EXPORT @@ -39,7 +39,7 @@ #define true 1 #endif -#if defined WNT +#if defined WIN32 #pragma warning ( disable: 4251 ) #endif diff --git a/src/Event/Event.h b/src/Event/Event.h index 8df1a71b1..472e385bc 100755 --- a/src/Event/Event.h +++ b/src/Event/Event.h @@ -30,7 +30,7 @@ // that uses this DLL. This way any other project whose source files include this file see // SalomeApp_API functions as being imported from a DLL, wheras this DLL sees symbols // defined with this macro as being exported. -#ifdef WNT +#ifdef WIN32 #ifdef EVENT_EXPORTS #define EVENT_EXPORT __declspec(dllexport) @@ -40,11 +40,11 @@ #else #define EVENT_EXPORT -#endif //WNT +#endif //WIN32 #define APP_VERSION "0.1" -#if defined WNT +#if defined WIN32 #pragma warning ( disable: 4251 ) #endif diff --git a/src/GLViewer/GLViewer.h b/src/GLViewer/GLViewer.h index bf34bae3a..af1bb3d3f 100644 --- a/src/GLViewer/GLViewer.h +++ b/src/GLViewer/GLViewer.h @@ -23,7 +23,7 @@ // Created: November, 2004 //! Macro for exports -#ifdef WNT +#ifdef WIN32 #ifdef GLVIEWER_EXPORTS #define GLVIEWER_API __declspec(dllexport) @@ -33,5 +33,5 @@ #else #define GLVIEWER_API -#endif // WNT +#endif // WIN32 diff --git a/src/GLViewer/GLViewer_AspectLine.h b/src/GLViewer/GLViewer_AspectLine.h index 99cdbcd97..866a96909 100644 --- a/src/GLViewer/GLViewer_AspectLine.h +++ b/src/GLViewer/GLViewer_AspectLine.h @@ -29,7 +29,7 @@ #include -#ifdef WNT +#ifdef WIN32 #pragma warning( disable:4251 ) #endif @@ -113,7 +113,7 @@ protected: int myLineType; }; -#ifdef WNT +#ifdef WIN32 #pragma warning ( default:4251 ) #endif diff --git a/src/GLViewer/GLViewer_BaseDrawers.h b/src/GLViewer/GLViewer_BaseDrawers.h index d06311cf3..37c7a898f 100644 --- a/src/GLViewer/GLViewer_BaseDrawers.h +++ b/src/GLViewer/GLViewer_BaseDrawers.h @@ -36,7 +36,7 @@ class GLViewer_AspectLine; -#ifdef WNT +#ifdef WIN32 #pragma warning( disable:4251 ) #endif @@ -91,7 +91,7 @@ public: void updateObjects(); }; -#ifdef WNT +#ifdef WIN32 #pragma warning ( default:4251 ) #endif diff --git a/src/GLViewer/GLViewer_BaseObjects.h b/src/GLViewer/GLViewer_BaseObjects.h index c0f45d328..8070664d5 100644 --- a/src/GLViewer/GLViewer_BaseObjects.h +++ b/src/GLViewer/GLViewer_BaseObjects.h @@ -33,7 +33,7 @@ #include -#ifdef WNT +#ifdef WIN32 #pragma warning( disable:4251 ) #endif @@ -248,7 +248,7 @@ protected: int myHeight; }; -#ifdef WNT +#ifdef WIN32 #pragma warning ( default:4251 ) #endif diff --git a/src/GLViewer/GLViewer_Compass.h b/src/GLViewer/GLViewer_Compass.h index 62dd4f257..9870ccf82 100644 --- a/src/GLViewer/GLViewer_Compass.h +++ b/src/GLViewer/GLViewer_Compass.h @@ -29,7 +29,7 @@ #include -#ifdef WNT +#ifdef WIN32 #pragma warning( disable:4251 ) #endif @@ -142,7 +142,7 @@ protected: bool isGenereted; }; -#ifdef WNT +#ifdef WIN32 #pragma warning ( default:4251 ) #endif diff --git a/src/GLViewer/GLViewer_Context.h b/src/GLViewer/GLViewer_Context.h index 5a9df2ceb..2ec1a0ccf 100644 --- a/src/GLViewer/GLViewer_Context.h +++ b/src/GLViewer/GLViewer_Context.h @@ -26,7 +26,7 @@ #ifndef GLVIEWER_CONTEXT_H #define GLVIEWER_CONTEXT_H -#ifdef WNT +#ifdef WIN32 #include "windows.h" #endif @@ -44,7 +44,7 @@ class GLViewer_Viewer2d; -#ifdef WNT +#ifdef WIN32 #pragma warning( disable:4251 ) #endif @@ -201,7 +201,7 @@ protected: int myTolerance; }; -#ifdef WNT +#ifdef WIN32 #pragma warning ( default:4251 ) #endif diff --git a/src/GLViewer/GLViewer_CoordSystem.h b/src/GLViewer/GLViewer_CoordSystem.h index 6db89583b..83d7b55e1 100644 --- a/src/GLViewer/GLViewer_CoordSystem.h +++ b/src/GLViewer/GLViewer_CoordSystem.h @@ -31,7 +31,7 @@ #include "GLViewer.h" -#ifdef WNT +#ifdef WIN32 #pragma warning( disable:4251 ) #endif @@ -100,7 +100,7 @@ protected: virtual void fromReference( double& x, double& y ); }; -#ifdef WNT +#ifdef WIN32 #pragma warning ( default:4251 ) #endif diff --git a/src/GLViewer/GLViewer_Drawer.h b/src/GLViewer/GLViewer_Drawer.h index 21c6386ce..9cfae081a 100644 --- a/src/GLViewer/GLViewer_Drawer.h +++ b/src/GLViewer/GLViewer_Drawer.h @@ -25,7 +25,7 @@ #ifndef GLVIEWER_DRAWER_H #define GLVIEWER_DRAWER_H -#ifdef WNT +#ifdef WIN32 #include "windows.h" #endif @@ -45,7 +45,7 @@ class GLViewer_Object; class GLViewer_Rect; class GLViewer_CoordSystem; -#ifdef WNT +#ifdef WIN32 #pragma warning( disable:4251 ) #endif /*! @@ -443,7 +443,7 @@ protected: GLfloat myTextScale; }; -#ifdef WNT +#ifdef WIN32 #pragma warning ( default:4251 ) #endif diff --git a/src/GLViewer/GLViewer_Geom.h b/src/GLViewer/GLViewer_Geom.h index 7ba4db69f..524eafa39 100644 --- a/src/GLViewer/GLViewer_Geom.h +++ b/src/GLViewer/GLViewer_Geom.h @@ -33,7 +33,7 @@ #include -#ifdef WNT +#ifdef WIN32 #pragma warning( disable:4251 ) #endif @@ -191,7 +191,7 @@ private: GLViewer_PntList* myPoints; }; -#ifdef WNT +#ifdef WIN32 #pragma warning ( default:4251 ) #endif diff --git a/src/GLViewer/GLViewer_Grid.h b/src/GLViewer/GLViewer_Grid.h index d4a4567e4..d4ff7b6a4 100644 --- a/src/GLViewer/GLViewer_Grid.h +++ b/src/GLViewer/GLViewer_Grid.h @@ -25,7 +25,7 @@ #ifndef GLVIEWER_GRID_H #define GLVIEWER_GRID_H -#ifdef WNT +#ifdef WIN32 #include "windows.h" #endif @@ -34,7 +34,7 @@ #include #include -#ifdef WNT +#ifdef WIN32 #pragma warning( disable:4251 ) #endif @@ -115,7 +115,7 @@ protected: GLboolean myIsUpdate; }; -#ifdef WNT +#ifdef WIN32 #pragma warning ( default:4251 ) #endif diff --git a/src/GLViewer/GLViewer_Group.h b/src/GLViewer/GLViewer_Group.h index 4382b06c9..620cd2f35 100644 --- a/src/GLViewer/GLViewer_Group.h +++ b/src/GLViewer/GLViewer_Group.h @@ -28,7 +28,7 @@ #include #include "GLViewer.h" -#ifdef WNT +#ifdef WIN32 #pragma warning( disable:4251 ) #endif diff --git a/src/GLViewer/GLViewer_MimeSource.h b/src/GLViewer/GLViewer_MimeSource.h index 55262d1d1..7b79bfd3f 100644 --- a/src/GLViewer/GLViewer_MimeSource.h +++ b/src/GLViewer/GLViewer_MimeSource.h @@ -25,7 +25,7 @@ #ifndef GLVIEWER_MIMESOURCE_H #define GLVIEWER_MIMESOURCE_H -#ifdef WNT +#ifdef WIN32 #include #endif @@ -34,7 +34,7 @@ #include #include -#ifdef WNT +#ifdef WIN32 #pragma warning( disable:4251 ) #endif @@ -67,7 +67,7 @@ private: QByteArray myByteArray; }; -#ifdef WNT +#ifdef WIN32 #pragma warning ( default:4251 ) #endif diff --git a/src/GLViewer/GLViewer_Object.h b/src/GLViewer/GLViewer_Object.h index 2384bb440..f3d3215b2 100644 --- a/src/GLViewer/GLViewer_Object.h +++ b/src/GLViewer/GLViewer_Object.h @@ -25,7 +25,7 @@ #ifndef GLVIEWER_OBJECT_H #define GLVIEWER_OBJECT_H -#ifdef WNT +#ifdef WIN32 #include #endif @@ -41,7 +41,7 @@ #include #include -#ifdef WNT +#ifdef WIN32 #pragma warning( disable:4251 ) #endif @@ -303,7 +303,7 @@ protected: GLViewer_Group* myGroup; }; -#ifdef WNT +#ifdef WIN32 #pragma warning ( default:4251 ) #endif diff --git a/src/GLViewer/GLViewer_Selector2d.h b/src/GLViewer/GLViewer_Selector2d.h index 34da93d59..bbb4c3634 100644 --- a/src/GLViewer/GLViewer_Selector2d.h +++ b/src/GLViewer/GLViewer_Selector2d.h @@ -25,7 +25,7 @@ #ifndef GLVIEWER_SELECTOR2D_H #define GLVIEWER_SELECTOR2D_H -#ifdef WNT +#ifdef WIN32 #include "windows.h" #endif diff --git a/src/GLViewer/GLViewer_Text.h b/src/GLViewer/GLViewer_Text.h index edf680e7b..597a61375 100644 --- a/src/GLViewer/GLViewer_Text.h +++ b/src/GLViewer/GLViewer_Text.h @@ -25,7 +25,7 @@ #ifndef GLVIEWER_TEXT_H #define GLVIEWER_TEXT_H -#ifdef WNT +#ifdef WIN32 #include #endif @@ -39,7 +39,7 @@ #include #include -#ifdef WNT +#ifdef WIN32 #pragma warning( disable:4251 ) #endif @@ -107,7 +107,7 @@ protected: DisplayTextFormat myDTF; }; -#ifdef WNT +#ifdef WIN32 #pragma warning ( default:4251 ) #endif diff --git a/src/GLViewer/GLViewer_Tools.h b/src/GLViewer/GLViewer_Tools.h index b9add1f19..ce7aa9db0 100644 --- a/src/GLViewer/GLViewer_Tools.h +++ b/src/GLViewer/GLViewer_Tools.h @@ -25,7 +25,7 @@ #ifndef GLVIEWER_TOOLS_H #define GLVIEWER_TOOLS_H -#ifdef WNT +#ifdef WIN32 #include "windows.h" #endif diff --git a/src/GLViewer/GLViewer_ViewFrame.cxx b/src/GLViewer/GLViewer_ViewFrame.cxx index d89922d48..322870cfc 100644 --- a/src/GLViewer/GLViewer_ViewFrame.cxx +++ b/src/GLViewer/GLViewer_ViewFrame.cxx @@ -272,7 +272,7 @@ void GLViewer_ViewFrame::onViewDump() imageBits = new unsigned char[imageSize]; -#ifdef WNT +#ifdef WIN32 int num; HBITMAP hBmp; @@ -429,7 +429,7 @@ void GLViewer_ViewFrame::onViewDump() aFileName += ".png"; aSaveOp = "PNG"; -//#ifdef WNT +//#ifdef WIN32 // if( !anImage.save( aFileName, aSaveOp ) ) //#else if( !aWidget->grabFrameBuffer().save( aFileName, aSaveOp ) ) diff --git a/src/GLViewer/GLViewer_ViewFrame.h b/src/GLViewer/GLViewer_ViewFrame.h index 76b9fe55b..ceb3f5be9 100644 --- a/src/GLViewer/GLViewer_ViewFrame.h +++ b/src/GLViewer/GLViewer_ViewFrame.h @@ -37,7 +37,7 @@ class GLViewer_ViewPort; #include -#ifdef WNT +#ifdef WIN32 #pragma warning( disable:4251 ) #endif @@ -121,7 +121,7 @@ private: }; -#ifdef WNT +#ifdef WIN32 #pragma warning ( default:4251 ) #endif diff --git a/src/GLViewer/GLViewer_ViewPort.cxx b/src/GLViewer/GLViewer_ViewPort.cxx index 07de20242..090af2381 100644 --- a/src/GLViewer/GLViewer_ViewPort.cxx +++ b/src/GLViewer/GLViewer_ViewPort.cxx @@ -24,10 +24,6 @@ //#include -#if !(defined WNT) && !(defined QT_CLEAN_NAMESPACE) -#define QT_CLEAN_NAMESPACE /* avoid definition of INT32 and INT8 */ -#endif - #include "GLViewer_ViewPort.h" #include "SUIT_ResourceMgr.h" @@ -43,7 +39,7 @@ #include -#if !defined WNT +#if !defined WIN32 #include #include #include @@ -343,7 +339,7 @@ void GLViewer_ViewPort::cleanup() */ void GLViewer_ViewPort::selectVisualId( ViewType type ) { -#if !defined WNT +#if !defined WIN32 XVisualInfo* pVisualInfo; if ( x11Display() ) { diff --git a/src/GLViewer/GLViewer_ViewPort.h b/src/GLViewer/GLViewer_ViewPort.h index b7ceaf2dc..f6c3cee51 100644 --- a/src/GLViewer/GLViewer_ViewPort.h +++ b/src/GLViewer/GLViewer_ViewPort.h @@ -40,7 +40,7 @@ class QPainter; class GLViewer_ViewSketcher; class GLViewer_ViewTransformer; -#ifdef WNT +#ifdef WIN32 #pragma warning( disable:4251 ) #endif @@ -170,7 +170,7 @@ private: static QCursor* sketchCursor; }; -#ifdef WNT +#ifdef WIN32 #pragma warning ( default:4251 ) #endif diff --git a/src/GLViewer/GLViewer_ViewPort2d.h b/src/GLViewer/GLViewer_ViewPort2d.h index 76b59b6d4..cf534f8a4 100644 --- a/src/GLViewer/GLViewer_ViewPort2d.h +++ b/src/GLViewer/GLViewer_ViewPort2d.h @@ -25,7 +25,7 @@ #ifndef GLVIEWER_VIEWPORT2D_H #define GLVIEWER_VIEWPORT2D_H -#ifdef WNT +#ifdef WIN32 #include #endif @@ -41,7 +41,7 @@ #include #include -#ifdef WNT +#ifdef WIN32 #pragma warning( disable:4251 ) #endif @@ -239,7 +239,7 @@ protected: bool myIsMouseReleaseBlock; }; -#ifdef WNT +#ifdef WIN32 #pragma warning ( default:4251 ) #endif diff --git a/src/GLViewer/GLViewer_Viewer.h b/src/GLViewer/GLViewer_Viewer.h index 0d68a450d..a17664bcb 100644 --- a/src/GLViewer/GLViewer_Viewer.h +++ b/src/GLViewer/GLViewer_Viewer.h @@ -41,7 +41,7 @@ class GLViewer_ViewTransformer; class SUIT_Desktop; class SUIT_ViewWindow; -#ifdef WNT +#ifdef WIN32 #pragma warning( disable:4251 ) #endif @@ -220,7 +220,7 @@ protected: int myButtonState; }; -#ifdef WNT +#ifdef WIN32 #pragma warning ( default:4251 ) #endif diff --git a/src/GLViewer/GLViewer_Viewer2d.h b/src/GLViewer/GLViewer_Viewer2d.h index 93c9d30f0..141a6071a 100644 --- a/src/GLViewer/GLViewer_Viewer2d.h +++ b/src/GLViewer/GLViewer_Viewer2d.h @@ -25,7 +25,7 @@ #ifndef GLVIEWER_VIEWER2D_H #define GLVIEWER_VIEWER2D_H -#ifdef WNT +#ifdef WIN32 #include #endif @@ -58,7 +58,7 @@ const double Sizes[2*5] = { /* A5 */ 148.5, 210.0 }; -#ifdef WNT +#ifdef WIN32 #pragma warning( disable:4251 ) #endif @@ -247,7 +247,7 @@ protected: static int rotateBtn; }; -#ifdef WNT +#ifdef WIN32 #pragma warning ( default:4251 ) #endif diff --git a/src/LightApp/LightApp.h b/src/LightApp/LightApp.h index 0fbeb1497..3282621bd 100644 --- a/src/LightApp/LightApp.h +++ b/src/LightApp/LightApp.h @@ -27,7 +27,7 @@ // that uses this DLL. This way any other project whose source files include this file see // LightApp_API functions as being imported from a DLL, wheras this DLL sees symbols // defined with this macro as being exported. -#ifdef WNT +#ifdef WIN32 #ifdef LIGHTAPP_EXPORTS #define LIGHTAPP_EXPORT __declspec(dllexport) @@ -41,6 +41,6 @@ #else #define LIGHTAPP_EXPORT -#endif //WNT +#endif //WIN32 #define APP_VERSION "0.1" diff --git a/src/LightApp/LightApp_Driver.cxx b/src/LightApp/LightApp_Driver.cxx index e8e161dc5..3676f2c89 100644 --- a/src/LightApp/LightApp_Driver.cxx +++ b/src/LightApp/LightApp_Driver.cxx @@ -116,7 +116,7 @@ bool LightApp_Driver::SaveDatasInFile( const char* theFileName, bool isMultiFile aCurrentPos += aBufferSize[i]; } -#ifdef WNT +#ifdef WIN32 ofstream aFile(theFileName, ios::out | ios::binary); #else ofstream aFile(theFileName); @@ -137,7 +137,7 @@ bool LightApp_Driver::SaveDatasInFile( const char* theFileName, bool isMultiFile */ bool LightApp_Driver::ReadDatasFromFile( const char* theFileName, bool isMultiFile ) { -#ifdef WNT +#ifdef WIN32 ifstream aFile(theFileName, ios::binary); #else ifstream aFile(theFileName); @@ -261,7 +261,7 @@ void LightApp_Driver::PutFilesToStream( const std::string& theModuleName, unsign OSD_Path anOSDPath(aFullPath); OSD_File anOSDFile(anOSDPath); if(!anOSDFile.Exists()) continue; -#ifdef WNT +#ifdef WIN32 ifstream aFile(aFullPath.ToCString(), ios::binary); #else ifstream aFile(aFullPath.ToCString()); @@ -299,7 +299,7 @@ void LightApp_Driver::PutFilesToStream( const std::string& theModuleName, unsign OSD_Path anOSDPath(aFullPath); OSD_File anOSDFile(anOSDPath); if(!anOSDFile.Exists()) continue; -#ifdef WNT +#ifdef WIN32 aFile = new ifstream(aFullPath.ToCString(), ios::binary); #else aFile = new ifstream(aFullPath.ToCString()); @@ -382,7 +382,7 @@ LightApp_Driver::ListOfFiles LightApp_Driver::PutStreamToFiles( const unsigned c TCollection_AsciiString aFullPath = aTmpDir + aFileName; -#ifdef WNT +#ifdef WIN32 ofstream aFile(aFullPath.ToCString(), ios::out | ios::binary); #else ofstream aFile(aFullPath.ToCString()); diff --git a/src/LightApp/LightApp_EventFilter.h b/src/LightApp/LightApp_EventFilter.h index 836db4476..16b43f767 100644 --- a/src/LightApp/LightApp_EventFilter.h +++ b/src/LightApp/LightApp_EventFilter.h @@ -24,7 +24,7 @@ #include -#if defined WNT +#if defined WIN32 #pragma warning( disable: 4251 ) #endif @@ -49,7 +49,7 @@ private: static LightApp_EventFilter* myFilter; }; -#if defined WNT +#if defined WIN32 #pragma warning( default: 4251 ) #endif diff --git a/src/LightApp/LightApp_Selection.cxx b/src/LightApp/LightApp_Selection.cxx index fe0a15207..dde1c314e 100644 --- a/src/LightApp/LightApp_Selection.cxx +++ b/src/LightApp/LightApp_Selection.cxx @@ -192,7 +192,7 @@ QtxValue LightApp_Selection::globalParam( const QString& p ) const } else if ( p == "isActiveView" ) return QtxValue( (bool)activeVW() ); else if ( p == "activeView" ) return QtxValue( activeViewType() ); -#ifndef WNT +#ifndef WIN32 else return QtxPopupMgr::Selection::globalParam( p ); #else else return Selection::globalParam( p ); diff --git a/src/LogWindow/LogWindow.cxx b/src/LogWindow/LogWindow.cxx index 201374785..277747772 100755 --- a/src/LogWindow/LogWindow.cxx +++ b/src/LogWindow/LogWindow.cxx @@ -400,7 +400,7 @@ void LogWindow::onCopy() Actions, which IDs are set in \a flags parameter, will be shown in the context popup menu. Other actions will not be shown. - \param ORed together actions flags + \param flags ORed together actions flags */ void LogWindow::setMenuActions( const int flags ) { diff --git a/src/OCCViewer/OCCViewer.h b/src/OCCViewer/OCCViewer.h index 724486cb9..199ca6a44 100755 --- a/src/OCCViewer/OCCViewer.h +++ b/src/OCCViewer/OCCViewer.h @@ -16,7 +16,7 @@ // // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // -#ifdef WNT +#ifdef WIN32 #ifdef OCCVIEWER_EXPORTS #define OCCVIEWER_EXPORT __declspec(dllexport) #else @@ -26,6 +26,6 @@ #define OCCVIEWER_EXPORT #endif -#if defined WNT +#if defined WIN32 #pragma warning ( disable: 4251 ) #endif diff --git a/src/ObjBrowser/OB.h b/src/ObjBrowser/OB.h index 8b243affe..dd40fb973 100755 --- a/src/ObjBrowser/OB.h +++ b/src/ObjBrowser/OB.h @@ -20,13 +20,13 @@ #define OB_H #if defined OB_EXPORTS -#if defined WNT +#if defined WIN32 #define OB_EXPORT __declspec( dllexport ) #else #define OB_EXPORT #endif #else -#if defined WNT +#if defined WIN32 #define OB_EXPORT __declspec( dllimport ) #else #define OB_EXPORT @@ -39,7 +39,7 @@ #define true 1 #endif -#if defined WNT +#if defined WIN32 #pragma warning ( disable: 4251 ) #endif diff --git a/src/ObjBrowser/OB_Browser.h b/src/ObjBrowser/OB_Browser.h index 2edf0239c..1175b7b9a 100755 --- a/src/ObjBrowser/OB_Browser.h +++ b/src/ObjBrowser/OB_Browser.h @@ -30,7 +30,7 @@ #include #include -#ifdef WNT +#ifdef WIN32 #pragma warning( disable:4251 ) #endif diff --git a/src/ObjBrowser/OB_ListItem.cxx b/src/ObjBrowser/OB_ListItem.cxx index f5fb6cb11..a66072a1b 100755 --- a/src/ObjBrowser/OB_ListItem.cxx +++ b/src/ObjBrowser/OB_ListItem.cxx @@ -28,7 +28,7 @@ #include using namespace std; -#ifdef WNT +#ifdef WIN32 #define min(a, b) (((a) < (b)) ? (a) : (b)) #endif @@ -287,11 +287,7 @@ QCheckListItem( parent, "", type ) */ OB_CheckListItem::OB_CheckListItem( SUIT_DataObject* obj, QListView* parent, QListViewItem* after, Type type ) : ListItemF( this, obj), -#if defined(QT_VERSION) && QT_VERSION >= 0x030101 QCheckListItem( parent, after, "", type ) -#else - QCheckListItem( parent, "", type ) -#endif { update(); } @@ -301,11 +297,7 @@ OB_CheckListItem::OB_CheckListItem( SUIT_DataObject* obj, QListView* parent, QLi */ OB_CheckListItem::OB_CheckListItem( SUIT_DataObject* obj, QListViewItem* parent, QListViewItem* after, Type type ) : ListItemF( this, obj), -#if defined(QT_VERSION) && QT_VERSION >= 0x030101 QCheckListItem( parent, after, "", type ) -#else - QCheckListItem( parent, "", type ) -#endif { update(); } diff --git a/src/Plot2d/Plot2d.h b/src/Plot2d/Plot2d.h index 20deb6ec1..72e7b7017 100755 --- a/src/Plot2d/Plot2d.h +++ b/src/Plot2d/Plot2d.h @@ -16,7 +16,7 @@ // // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // -#ifdef WNT +#ifdef WIN32 #ifdef PLOT2D_EXPORTS #define PLOT2D_EXPORT __declspec(dllexport) #else @@ -26,6 +26,6 @@ #define PLOT2D_EXPORT #endif -#if defined WNT +#if defined WIN32 #pragma warning ( disable: 4251 ) #endif diff --git a/src/Plot2d/Plot2d_SetupCurveDlg.cxx b/src/Plot2d/Plot2d_SetupCurveDlg.cxx index 4873db496..dc2291e24 100644 --- a/src/Plot2d/Plot2d_SetupCurveDlg.cxx +++ b/src/Plot2d/Plot2d_SetupCurveDlg.cxx @@ -34,7 +34,7 @@ #include #include -#ifndef WNT +#ifndef WIN32 using namespace std; #endif diff --git a/src/Prs/SALOME_Prs.h b/src/Prs/SALOME_Prs.h index fa7c62369..e8465a9b5 100755 --- a/src/Prs/SALOME_Prs.h +++ b/src/Prs/SALOME_Prs.h @@ -19,7 +19,7 @@ #ifndef SALOME_PRS_H #define SALOME_PRS_H -#ifdef WNT +#ifdef WIN32 #ifdef PRS_EXPORTS #define PRS_EXPORT __declspec(dllexport) #else diff --git a/src/PyConsole/Makefile.am b/src/PyConsole/Makefile.am new file mode 100755 index 000000000..78ea6b6d5 --- /dev/null +++ b/src/PyConsole/Makefile.am @@ -0,0 +1,49 @@ +# Copyright (C) 2005 CEA/DEN, EDF R&D, OPEN CASCADE, 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 +# +# File : Makefile.in +# Author : Vladimir Klyachin (OCN) +# Module : PyConsole +# $Header$ + +include $(top_srcdir)/adm_local/unix/make_common_starter.am + +lib_LTLIBRARIES = libPyConsole.la + +salomeinclude_HEADERS= \ + PyConsole.h \ + PyConsole_Console.h \ + PyConsole_Editor.h \ + PyConsole_Interp.h + +dist_libPyConsole_la_SOURCES= \ + PyConsole_Console.cxx \ + PyConsole_Editor.cxx \ + PyConsole_Interp.cxx + +MOC_FILES= \ + PyConsole_Editor_moc.cxx \ + PyConsole_Console_moc.cxx + +nodist_libPyConsole_la_SOURCES= $(MOC_FILES) + +libPyConsole_la_CPPFLAGS= $(PYTHON_INCLUDES) $(QT_INCLUDES) \ + -I$(srcdir)/../PyInterp -I$(srcdir)/../SUIT -I$(srcdir)/../Qtx + +libPyConsole_la_LDFLAGS= $(PYTHON_LIBS) $(QT_MT_LIBS) +libPyConsole_la_LIBADD=../Qtx/libqtx.la ../SUIT/libsuit.la ../PyInterp/libPyInterp.la diff --git a/src/PyConsole/PyConsole.h b/src/PyConsole/PyConsole.h new file mode 100644 index 000000000..c99a5864f --- /dev/null +++ b/src/PyConsole/PyConsole.h @@ -0,0 +1,45 @@ +// 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 +// +// File : PyConsole.h +// Author : Vadim SANDLER +// Module : SALOME + +#if !defined ( PYCONSOLE_H ) +#define PYCONSOLE_H + +// ======================================================== +// set dllexport type for Win platform +#ifdef WIN32 +# ifdef PYCONSOLE_EXPORTS +# define PYCONSOLE_EXPORT __declspec(dllexport) +# else +# define PYCONSOLE_EXPORT __declspec(dllimport) +# endif +#else // WIN32 +# define PYCONSOLE_EXPORT +#endif // WIN32 + +// ======================================================== +// avoid warning messages +#ifdef WIN32 +#pragma warning (disable : 4786) +#pragma warning (disable : 4251) +#endif + +#endif // PYCONSOLE_H diff --git a/src/PyConsole/PyConsole.pro b/src/PyConsole/PyConsole.pro new file mode 100644 index 000000000..4839a6c3d --- /dev/null +++ b/src/PyConsole/PyConsole.pro @@ -0,0 +1,41 @@ +TEMPLATE = lib +TARGET = PyConsole +DESTDIR = ../../lib +MOC_DIR = ../../moc +OBJECTS_DIR = ../../obj/$$TARGET + +PYTHONVER=2.4 +PYTHONHOME=$$(PYTHONHOME) +PYTHONINC=$${PYTHONHOME}/include/python$${PYTHONVER} +PYTHONLIB=$${PYTHONHOME}/lib + +INCLUDEPATH += ../../include $${PYTHONINC} +INCLUDEPATH += ../Qtx ../SUIT ../PyInterp +unix:LIBS += -L$${PYTHONLIB} -lpython$${PYTHONVER} +win32:LIBS += /LIBPATH:$$(PYTHONLIB) +LIBS += -L../../lib -lqtx -lsuit -lPyInterp + +CONFIG -= debug release debug_and_release +CONFIG += qt thread debug dll shared + +win32:DEFINES += WIN32 +DEFINES += PYCONSOLE_EXPORTS + +HEADERS = PyConsole.h +HEADERS += PyConsole_Console.h +HEADERS += PyConsole_Editor.h +HEADERS += PyConsole_Interp.h + +SOURCES = PyConsole_Console.cxx +SOURCES += PyConsole_Editor.cxx +SOURCES += PyConsole_Interp.cxx + +TRANSLATIONS = resources/PyConsole_msg_en.ts + +includes.files = $$HEADERS +includes.path = ../../include + +resources.files = resources/*.qm +resources.path = ../../resources + +INSTALLS += includes resources diff --git a/src/PyConsole/PyConsole_Console.cxx b/src/PyConsole/PyConsole_Console.cxx new file mode 100644 index 000000000..3e84dd477 --- /dev/null +++ b/src/PyConsole/PyConsole_Console.cxx @@ -0,0 +1,246 @@ +// 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 +// +// File : PyConsole_Console.cxx +// Author : Vadim SANDLER +// Module : SALOME + +/*! + \class PyConsole_Console + \brief Python console widget. +*/ + +#include "PyConsole_Interp.h" /// !!! WARNING !!! THIS INCLUDE MUST BE VERY FIRST !!! +#include "PyConsole_Console.h" +#include "PyConsole_Editor.h" + +#include + +#include +#include +#include +#include +#include +#include + +/*! + \brief Constructor. + + Creates new python console widget. + \param parent parent widget + \param interp python interpreter +*/ +PyConsole_Console::PyConsole_Console( QWidget* parent, PyConsole_Interp* interp ) +: QFrame( parent ), + myEditor( 0 ) +{ + // create python interpreter + myInterp = interp; + if ( !myInterp ) + myInterp = new PyConsole_Interp(); + + // initialize Python interpretator + myInterp->initialize(); + + // create editor console + QVBoxLayout* lay = new QVBoxLayout( this ); + lay->setMargin( 5 ); + myEditor = new PyConsole_Editor( myInterp, this ); + myEditor->viewport()->installEventFilter( this ); + lay->addWidget( myEditor ); + + createActions(); +} + +/*! + \brief Destructor. + + Does nothing for the moment. +*/ +PyConsole_Console::~PyConsole_Console() +{ +} + +/*! + \brief Execute python command in the interpreter. + \param command string with command and arguments +*/ +void PyConsole_Console::exec( const QString& command ) +{ + if ( myEditor ) + myEditor->exec( command ); +} + +/*! + \brief Execute python command in the interpreter + and wait until it is finished. + + Block execution of main application until the python command is executed. + \param command string with command and arguments +*/ +void PyConsole_Console::execAndWait( const QString& command ) +{ + if ( myEditor ) + myEditor->execAndWait( command ); +} + +/*! + \brief Get synchronous mode flag value. + + \sa setIsSync() + \return True if python console works in synchronous mode +*/ +bool PyConsole_Console::isSync() const +{ + return myEditor->isSync(); +} + +/*! + \brief Set synchronous mode flag value. + + In synhronous mode the Python commands are executed in the GUI thread + and the GUI is blocked until the command is finished. In the asynchronous + mode each Python command is executed in the separate thread that does not + block the main GUI loop. + + \param on synhronous mode flag +*/ +void PyConsole_Console::setIsSync( const bool on ) +{ + myEditor->setIsSync( on ); +} + +/*! + \brief Change the python console's font. + \param f new font +*/ +void PyConsole_Console::setFont( const QFont& f ) +{ + if( myEditor ) + myEditor->setFont( f ); +} + +/*! + \brief Get python console font. + \return current python console's font +*/ +QFont PyConsole_Console::font() const +{ + QFont res; + if( myEditor ) + res = myEditor->font(); + return res; +} + +/*! + \brief Event handler. + + Handles context menu request event. + + \param o object + \param e event + \return True if the event is processed and further processing should be stopped +*/ +bool PyConsole_Console::eventFilter( QObject* o, QEvent* e ) +{ + if ( o == myEditor->viewport() && e->type() == QEvent::ContextMenu ) + { + contextMenuRequest( (QContextMenuEvent*)e ); + return true; + } + return QFrame::eventFilter( o, e ); +} + +/*! + \brief Create the context popup menu. + + Fill in the popup menu with the commands. + + \param menu context popup menu +*/ +void PyConsole_Console::contextMenuPopup( QMenu* menu ) +{ + if ( myEditor->isReadOnly() ) + return; + + menu->addAction( myActions[CopyId] ); + menu->addAction( myActions[PasteId] ); + menu->addAction( myActions[ClearId] ); + menu->addSeparator(); + menu->addAction( myActions[SelectAllId] ); + + Qtx::simplifySeparators( menu ); + + updateActions(); +} + +/*! + \brief Set actions to be visible in the context popup menu. + + Actions, which IDs are set in \a flags parameter, will be shown in the + context popup menu. Other actions will not be shown. + + \param flags ORed together actions flags +*/ +void PyConsole_Console::setMenuActions( const int flags ) +{ + myActions[CopyId]->setVisible( flags & CopyId ); + myActions[PasteId]->setVisible( flags & PasteId ); + myActions[ClearId]->setVisible( flags & ClearId ); + myActions[SelectAllId]->setVisible( flags & SelectAllId ); +} + +/*! + \brief Create menu actions. + + Create context popup menu actions. +*/ +void PyConsole_Console::createActions() +{ + QAction* a = new QAction( tr( "EDIT_COPY_CMD" ), this ); + a->setStatusTip( tr( "EDIT_COPY_CMD" ) ); + connect( a, SIGNAL( triggered( bool ) ), myEditor, SLOT( copy() ) ); + myActions.insert( CopyId, a ); + + a = new QAction( tr( "EDIT_PASTE_CMD" ), this ); + a->setStatusTip( tr( "EDIT_PASTE_CMD" ) ); + connect( a, SIGNAL( triggered( bool ) ), myEditor, SLOT( paste() ) ); + myActions.insert( PasteId, a ); + + a = new QAction( tr( "EDIT_CLEAR_CMD" ), this ); + a->setStatusTip( tr( "EDIT_CLEAR_CMD" ) ); + connect( a, SIGNAL( triggered( bool ) ), myEditor, SLOT( clear() ) ); + myActions.insert( ClearId, a ); + + a = new QAction( tr( "EDIT_SELECTALL_CMD" ), this ); + a->setStatusTip( tr( "EDIT_SELECTALL_CMD" ) ); + connect( a, SIGNAL( triggered( bool ) ), myEditor, SLOT( selectAll() ) ); + myActions.insert( SelectAllId, a ); +} + +/*! + \brief Update menu actions. + + Update context popup menu action state. +*/ +void PyConsole_Console::updateActions() +{ + myActions[CopyId]->setEnabled( myEditor->textCursor().hasSelection() ); + myActions[PasteId]->setEnabled( !myEditor->isReadOnly() && !QApplication::clipboard()->text().isEmpty() ); + myActions[SelectAllId]->setEnabled( !myEditor->document()->isEmpty() ); +} diff --git a/src/PyConsole/PyConsole_Console.h b/src/PyConsole/PyConsole_Console.h new file mode 100644 index 000000000..c8b8677fe --- /dev/null +++ b/src/PyConsole/PyConsole_Console.h @@ -0,0 +1,83 @@ +// 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 +// +// File : PyConsole_Console.h +// Author : Vadim SANDLER, Open CASCADE S.A. (vadim.sandler@opencascade.com) +// Module : SALOME + +#ifndef PYCONSOLE_CONSOLE_H +#define PYCONSOLE_CONSOLE_H + +#include "PyConsole.h" + +#include +#include +#include + +class PyConsole_Interp; +class PyConsole_Editor; + +class PYCONSOLE_EXPORT PyConsole_Console : public QFrame, public SUIT_PopupClient +{ + Q_OBJECT + +public: + //! Context popup menu actions flags + enum + { + CopyId = 0x01, //!< "Copy" menu action + PasteId = 0x02, //!< "Paste" menu action + ClearId = 0x04, //!< "Clear" menu action + SelectAllId = 0x08, //!< "Select All" menu action + All = CopyId | PasteId | ClearId | SelectAllId //!< all menu actions + }; + +public: + PyConsole_Console( QWidget* parent, PyConsole_Interp* interp = 0 ); + virtual ~PyConsole_Console(); + + //! \brief Get python interperter + PyConsole_Interp* getInterp() { return myInterp; } + QFont font() const; + virtual void setFont( const QFont& ); + + bool isSync() const; + void setIsSync( const bool ); + + void exec( const QString& ); + void execAndWait( const QString& ); + + virtual bool eventFilter( QObject*, QEvent* ); + + //! \brief Get popup client symbolic name + virtual QString popupClientType() const { return QString( "PyConsole" ); } + virtual void contextMenuPopup( QMenu* ); + + void setMenuActions( const int ); + +private: + void createActions(); + void updateActions(); + +private: + PyConsole_Interp* myInterp; //!< python interpreter + PyConsole_Editor* myEditor; //!< python console editor widget + QMap myActions; //!< menu actions list +}; + +#endif // PYCONSOLE_CONSOLE_H diff --git a/src/PyConsole/PyConsole_Editor.cxx b/src/PyConsole/PyConsole_Editor.cxx new file mode 100644 index 000000000..98c0425a6 --- /dev/null +++ b/src/PyConsole/PyConsole_Editor.cxx @@ -0,0 +1,1039 @@ +// SALOME SALOMEGUI : implementation of desktop and GUI kernel +// +// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// 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 +// +// File : PyConsole_Editor.cxx +// Author : Vadim SANDLER +// Module : SALOME + +/*! + \class PyConsole_Editor + \brief Python command line interpreter front-end GUI widget. + + This class provides simple GUI interface to the Python interpreter, including basic + navigation operations, executing commands (both interactively and programmatically), + copy-paste operations, history of the commands and so on. + + Here below is the shortcut keyboard boundings used for navigation and other operations: + - : execute current command + - : clear current command + - : clear current command + - : previous command in the history + - : move cursor one row up with selection + - : move cursor one row up without selection + - : move cursor one row up with selection + - : next command in the history + - : move cursor one row down with selection + - : move cursor one row down without selection + - : move cursor one row down with selection + - : move one symbol left without selection + - : move one symbol left with selection + - : move one word left without selection + - : move one word left with selection + - : move one symbol right without selection + - : move one symbol right with selection + - : move one word right without selection + - : move one word right with selection + - : first command in the history + - : move one page up with selection + - : move one page up without selection + - : scroll one page up + - : last command in the history + - : move one page down with selection + - : move one page down without selection + - : scroll one page down + - : move to the beginning of the line without selection + - : move to the beginning of the line with selection + - : move to the very first symbol without selection + - : move to the very first symbol with selection + - : move to the end of the line without selection + - : move to the end of the line with selection + - : move to the very last symbol without selection + - : move to the very last symbol with selection + - : delete symbol before the cursor + / remove selected text and put it to the clipboard (cut) + - : delete previous word + / remove selected text and put it to the clipboard (cut) + - : delete text from the cursor to the beginning of the line + / remove selected text and put it to the clipboard (cut) + - : delete symbol after the cursor + / remove selected text and put it to the clipboard (cut) + - : delete next word + / remove selected text and put it to the clipboard (cut) + - : delete text from the cursor to the end of the line + / remove selected text and put it to the clipboard (cut) + - : copy + - : paste + - : paste + - : copy + - : cut + - : paste + + TODO: + - paste multiline text: process each line as separate command + (including mouse middle-button click pasting) + - the same for drag-n-drop of multiline text +*/ + +#include "PyConsole_Interp.h" // !!! WARNING !!! THIS INCLUDE MUST BE THE VERY FIRST !!! +#include "PyConsole_Editor.h" +#include + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +static QString READY_PROMPT = ">>> "; +static QString DOTS_PROMPT = "... "; +#define PROMPT_SIZE myPrompt.length() + +/*! + \class ExecCommand + \brief Python command execution request [internal]. + */ +class ExecCommand : public PyInterp_LockRequest +{ +public: + /*! + \brief Constructor. + + Creates new python command execution request. + \param theInterp python interpreter + \param theCommand python command + \param theListener widget to get the notification messages + \param sync if True the request is processed synchronously + */ + ExecCommand( PyInterp_Interp* theInterp, + const QString& theCommand, + PyConsole_Editor* theListener, + bool sync = false ) + : PyInterp_LockRequest( theInterp, theListener, sync ), + myCommand( theCommand ), myState( PyInterp_Event::OK ) + {} + +protected: + /*! + \brief Execute the python command in the interpreter and + get its execution status. + */ + virtual void execute() + { + if ( myCommand != "" ) + { + int ret = getInterp()->run( myCommand.toLatin1() ); + if ( ret < 0 ) + myState = PyInterp_Event::ERROR; + else if ( ret > 0 ) + myState = PyInterp_Event::INCOMPLETE; + myError = getInterp()->getverr().c_str(); + myOutput = getInterp()->getvout().c_str(); + } + else + { + myError = ""; + myOutput = ""; + } + } + + /*! + \brief Create and return a notification event. + \return new notification event + */ + virtual QEvent* createEvent() const + { + return new PyInterp_Event( myState, (PyInterp_Request*)this ); + } + +public: + QString myError; //!< Python command error message + QString myOutput; //!< Python command output log + +private: + QString myCommand; //!< Python command + int myState; //!< Python command execution status +}; + +/*! + \brief Constructor. + + Creates python editor window. + \param theInterp python interper + \param theParent parent widget +*/ +PyConsole_Editor::PyConsole_Editor( PyConsole_Interp* theInterp, + QWidget* theParent ) +: QTextEdit( theParent ), + myInterp( 0 ), + myCmdInHistory( -1 ), + myEventLoop( 0 ), + myIsSync( false ) +{ + QString fntSet( "" ); + QFont aFont = SUIT_Tools::stringToFont( fntSet ); + setFont( aFont ); + setUndoRedoEnabled( false ); + + myPrompt = READY_PROMPT; + setLineWrapMode( QTextEdit::NoWrap ); + setWordWrapMode( QTextOption::NoWrap ); + setAcceptRichText( false ); + + // san - This is necessary for troubleless initialization + onPyInterpChanged( theInterp ); +} + +/*! + \brief Destructor. + + Does nothing for the moment. +*/ +PyConsole_Editor::~PyConsole_Editor() +{ +} + +/*! + \brief Get synchronous mode flag value. + + \sa setIsSync() + \return True if python console works in synchronous mode +*/ +bool PyConsole_Editor::isSync() const +{ + return myIsSync; +} + +/*! + \brief Set synchronous mode flag value. + + In synhronous mode the Python commands are executed in the GUI thread + and the GUI is blocked until the command is finished. In the asynchronous + mode each Python command is executed in the separate thread that does not + block the main GUI loop. + + \param on synhronous mode flag +*/ +void PyConsole_Editor::setIsSync( const bool on ) +{ + myIsSync = on; +} + +/*! + \brief Put the string \a str to the python editor. + \param str string to be put in the command line of the editor + \param newBlock if True, then the string is printed on a new line +*/ +void PyConsole_Editor::addText( const QString& str, + const bool newBlock ) +{ + moveCursor( QTextCursor::End ); + if ( newBlock ) + textCursor().insertBlock(); + textCursor().insertText( str ); + moveCursor( QTextCursor::End ); + ensureCursorVisible(); +} + +/*! + \brief Convenient method for executing a Python command, + as if the user typed it manually. + \param command python command to be executed +*/ +void PyConsole_Editor::exec( const QString& command ) +{ + if ( isReadOnly() ) { + // some interactive command is being executed in this editor... + // shedule the command to the queue + myQueue.push_back( command ); + return; + } + // remove last line + moveCursor( QTextCursor::End ); + moveCursor( QTextCursor::StartOfBlock, QTextCursor::KeepAnchor ); + textCursor().removeSelectedText(); + // set "ready" prompt + myPrompt = READY_PROMPT; + // clear command buffer + myCommandBuffer.truncate( 0 ); + // unset history browsing mode + myCmdInHistory = -1; + // print command line by line + QString cmd = command; + if ( !cmd.endsWith( "\n" ) ) cmd += "\n"; + QStringList lines = command.split( "\n" ); + for ( int i = 0; i < lines.size(); i++ ) { + if ( !lines[i].trimmed().isEmpty() ) + myHistory.push_back( lines[i] ); + addText( ( i == 0 ? READY_PROMPT : DOTS_PROMPT ) + lines[i], i != 0 ); + } + // set read-only mode + setReadOnly( true ); + // set busy cursor + setCursor( Qt::BusyCursor ); + + // post a request to execute Python command; + // editor will be informed via a custom event that execution has been completed + PyInterp_Dispatcher::Get()->Exec( createRequest( cmd ) ); +} + +/*! + \brief Create request to the python dispatcher for the command execution. + + \param command python command to be executed + */ +PyInterp_Request* PyConsole_Editor::createRequest( const QString& command ) +{ + return new ExecCommand( myInterp, command, this, isSync() ); +} + +/*! + \brief Execute command in the python interpreter + and wait until it is finished. + + \param command python command to be executed + */ +void PyConsole_Editor::execAndWait( const QString& command ) +{ + // already running ? + if( myEventLoop ) + return; + + // create new event loop + myEventLoop = new QEventLoop( this ); + // execute command + exec( command ); + // run event loop + myEventLoop->exec(); + // delete event loop after command is processed + delete myEventLoop; + myEventLoop = 0; +} + +/*! + \brief Process "Enter" key press event. + + Execute the command entered by the user. +*/ +void PyConsole_Editor::handleReturn() +{ + // get last line + QTextBlock par = document()->end().previous(); + if ( !par.isValid() ) return; + + // get command + QString cmd = par.text().remove( 0, PROMPT_SIZE ); + // extend the command buffer with the current command + myCommandBuffer.append( cmd ); + // add command to the history + if ( !cmd.trimmed().isEmpty() ) + myHistory.push_back( cmd ); + + // set read-only mode + setReadOnly( true ); + // set busy cursor + setCursor( Qt::BusyCursor ); + + // post a request to execute Python command; + // editor will be informed via a custom event that execution has been completed + PyInterp_Dispatcher::Get()->Exec( createRequest( myCommandBuffer ) ); +} + +/*! + \brief Process drop event. + + Paste dragged text. + \param event drop event +*/ +void PyConsole_Editor::dropEvent( QDropEvent* event ) +{ + // get the initial drop position + QPoint pos = event->pos(); + QTextCursor cur = cursorForPosition( event->pos() ); + // if the position is not in the last line move it to the end of the command line + if ( cur.position() < document()->end().previous().position() + PROMPT_SIZE ) { + moveCursor( QTextCursor::End ); + pos = cursorRect().center(); + } + // create new drop event and use it instead of the original + QDropEvent de( pos, + event->possibleActions(), + event->mimeData(), + event->mouseButtons(), + event->keyboardModifiers(), + event->type() ); + QTextEdit::dropEvent( &de ); + // accept the original event + event->acceptProposedAction(); +} + +/*! + \brief Process mouse button release event. + + Left mouse button: copy selection to the clipboard. + Middle mouse button: paste clipboard's contents. + \param event mouse event +*/ +void PyConsole_Editor::mouseReleaseEvent( QMouseEvent* event ) +{ + if ( event->button() == Qt::LeftButton ) { + QTextEdit::mouseReleaseEvent( event ); + copy(); + } + else if ( event->button() == Qt::MidButton ) { + QString text; + if ( QApplication::clipboard()->supportsSelection() ) + text = QApplication::clipboard()->text( QClipboard::Selection ); + if ( text.isEmpty() ) + text = QApplication::clipboard()->text( QClipboard::Clipboard ); + QTextCursor cur = cursorForPosition( event->pos() ); + // if the position is not in the last line move it to the end of the command line + if ( cur.position() < document()->end().previous().position() + PROMPT_SIZE ) { + moveCursor( QTextCursor::End ); + } + else { + setTextCursor( cur ); + } + textCursor().clearSelection(); + textCursor().insertText( text ); + } + else { + QTextEdit::mouseReleaseEvent( event ); + } +} + +/*! + \brief Check if the string is command. + + Return True if the string \a str is likely to be the command + (i.e. it is started from the '>>>' or '...'). + \param str string to be checked +*/ +bool PyConsole_Editor::isCommand( const QString& str ) const +{ + return str.startsWith( READY_PROMPT ) || str.startsWith( DOTS_PROMPT ); +} + +/*! + \brief Handle keyboard event. + + Implement navigation, history browsing, copy/paste and other common + operations. + \param event keyboard event +*/ +void PyConsole_Editor::keyPressEvent( QKeyEvent* event ) +{ + // get cursor position + QTextCursor cur = textCursor(); + int curLine = cur.blockNumber(); + int curCol = cur.columnNumber(); + + // get last edited line + int endLine = document()->blockCount()-1; + + // get pressed key code + int aKey = event->key(); + + // check if is pressed + bool ctrlPressed = event->modifiers() & Qt::ControlModifier; + // check if is pressed + bool shftPressed = event->modifiers() & Qt::ShiftModifier; + + if ( aKey == Qt::Key_Escape || ctrlPressed && aKey == -1 ) { + // process + key-binding and key: clear current command + myCommandBuffer.truncate( 0 ); + myPrompt = READY_PROMPT; + addText( myPrompt, true ); + horizontalScrollBar()->setValue( horizontalScrollBar()->minimum() ); + return; + } + else if ( ctrlPressed && aKey == Qt::Key_C ) { + // process + key-binding : copy + copy(); + return; + } + else if ( ctrlPressed && aKey == Qt::Key_X ) { + // process + key-binding : cut + cut(); + return; + } + else if ( ctrlPressed && aKey == Qt::Key_V ) { + // process + key-binding : paste + paste(); + return; + } + + // check for printed key + aKey = ( aKey < Qt::Key_Space || aKey > Qt::Key_ydiaeresis ) ? aKey : 0; + + switch ( aKey ) { + case 0 : + // any printed key: just print it + { + if ( curLine < endLine || curCol < PROMPT_SIZE ) { + moveCursor( QTextCursor::End ); + } + QTextEdit::keyPressEvent( event ); + break; + } + case Qt::Key_Return: + case Qt::Key_Enter: + // key: process the current command + { + handleReturn(); + break; + } + case Qt::Key_Up: + // arrow key: process as follows: + // - without , modifiers: previous command in history + // - with modifier key pressed: move cursor one row up without selection + // - with modifier key pressed: move cursor one row up with selection + // - with + modifier keys pressed: scroll one row up + { + if ( ctrlPressed && shftPressed ) { + int value = verticalScrollBar()->value(); + int spacing = fontMetrics().lineSpacing(); + verticalScrollBar()->setValue( value > spacing ? value-spacing : 0 ); + } + else if ( shftPressed || ctrlPressed ) { + if ( curLine > 0 ) + moveCursor( QTextCursor::Up, + shftPressed ? QTextCursor::KeepAnchor : QTextCursor::MoveAnchor ); + } + else { + if ( myCmdInHistory < 0 && myHistory.count() > 0 ) { + // set history browsing mode + myCmdInHistory = myHistory.count(); + // remember current command + QTextBlock par = document()->end().previous(); + myCurrentCommand = par.text().remove( 0, PROMPT_SIZE ); + } + if ( myCmdInHistory > 0 ) { + myCmdInHistory--; + // get previous command in the history + QString previousCommand = myHistory.at( myCmdInHistory ); + // print previous command + moveCursor( QTextCursor::End ); + moveCursor( QTextCursor::StartOfBlock, QTextCursor::KeepAnchor ); + textCursor().removeSelectedText(); + addText( myPrompt + previousCommand ); + // move cursor to the end + moveCursor( QTextCursor::End ); + } + } + break; + } + case Qt::Key_Down: + // arrow key: process as follows: + // - without , modifiers: next command in history + // - with modifier key pressed: move cursor one row down without selection + // - with modifier key pressed: move cursor one row down with selection + // - with + modifier keys pressed: scroll one row down + { + if ( ctrlPressed && shftPressed ) { + int value = verticalScrollBar()->value(); + int maxval = verticalScrollBar()->maximum(); + int spacing = fontMetrics().lineSpacing(); + verticalScrollBar()->setValue( value+spacing < maxval ? value+spacing : maxval ); + } + else if ( shftPressed || ctrlPressed) { + if ( curLine < endLine ) + moveCursor( QTextCursor::Down, + shftPressed ? QTextCursor::KeepAnchor : QTextCursor::MoveAnchor ); + } + else { + if ( myCmdInHistory >= 0 ) { + // get next command in the history + myCmdInHistory++; + QString nextCommand; + if ( myCmdInHistory < myHistory.count() ) { + // next command in history + nextCommand = myHistory.at( myCmdInHistory ); + } + else { + // end of history is reached + // last printed command + nextCommand = myCurrentCommand; + // unset history browsing mode + myCmdInHistory = -1; + } + // print next or current command + moveCursor( QTextCursor::End ); + moveCursor( QTextCursor::StartOfBlock, QTextCursor::KeepAnchor ); + textCursor().removeSelectedText(); + addText( myPrompt + nextCommand ); + // move cursor to the end + moveCursor( QTextCursor::End ); + } + } + break; + } + case Qt::Key_Left: + // arrow key: process as follows: + // - without , modifiers: move one symbol left (taking into account prompt) + // - with modifier key pressed: move one word left (taking into account prompt) + // - with modifier key pressed: move one symbol left with selection + // - with + modifier keys pressed: move one word left with selection + { + QString txt = textCursor().block().text(); + if ( !shftPressed && isCommand( txt ) && curCol <= PROMPT_SIZE ) { + moveCursor( QTextCursor::Up ); + moveCursor( QTextCursor::EndOfBlock ); + } + else { + QTextEdit::keyPressEvent( event ); + } + break; + } + case Qt::Key_Right: + // arrow key: process as follows: + // - without , modifiers: move one symbol right (taking into account prompt) + // - with modifier key pressed: move one word right (taking into account prompt) + // - with modifier key pressed: move one symbol right with selection + // - with + modifier keys pressed: move one word right with selection + { + QString txt = textCursor().block().text(); + if ( !shftPressed ) { + if ( curCol < txt.length() ) { + if ( isCommand( txt ) && curCol < PROMPT_SIZE ) { + cur.setPosition( cur.block().position() + PROMPT_SIZE ); + setTextCursor( cur ); + break; + } + } + else { + if ( curLine < endLine && isCommand( textCursor().block().next().text() ) ) { + cur.setPosition( cur.position() + PROMPT_SIZE+1 ); + setTextCursor( cur ); + horizontalScrollBar()->setValue( horizontalScrollBar()->minimum() ); + break; + } + } + } + QTextEdit::keyPressEvent( event ); + break; + } + case Qt::Key_PageUp: + // key: process as follows: + // - without , modifiers: first command in history + // - with modifier key pressed: move cursor one page up without selection + // - with modifier key pressed: move cursor one page up with selection + // - with + modifier keys pressed: scroll one page up + { + if ( ctrlPressed && shftPressed ) { + verticalScrollBar()->triggerAction(QAbstractSlider::SliderPageStepSub); + } + else if ( shftPressed || ctrlPressed ) { + bool moved = false; + qreal lastY = cursorRect( cur ).top(); + qreal distance = 0; + // move using movePosition to keep the cursor's x + do { + qreal y = cursorRect( cur ).top(); + distance += qAbs( y - lastY ); + lastY = y; + moved = cur.movePosition( QTextCursor::Up, + shftPressed ? QTextCursor::KeepAnchor : + QTextCursor::MoveAnchor ); + } while ( moved && distance < viewport()->height() ); + if ( moved ) { + cur.movePosition( QTextCursor::Down, + shftPressed ? QTextCursor::KeepAnchor : + QTextCursor::MoveAnchor ); + verticalScrollBar()->triggerAction( QAbstractSlider::SliderPageStepSub ); + } + setTextCursor( cur ); + } + else { + if ( myCmdInHistory < 0 && myHistory.count() > 0 ) { + // set history browsing mode + myCmdInHistory = myHistory.count(); + // remember current command + QTextBlock par = document()->end().previous(); + myCurrentCommand = par.text().remove( 0, PROMPT_SIZE ); + } + if ( myCmdInHistory > 0 ) { + myCmdInHistory = 0; + // get very first command in the history + QString firstCommand = myHistory.at( myCmdInHistory ); + // print first command + moveCursor( QTextCursor::End ); + moveCursor( QTextCursor::StartOfBlock, QTextCursor::KeepAnchor ); + textCursor().removeSelectedText(); + addText( myPrompt + firstCommand ); + // move cursor to the end + moveCursor( QTextCursor::End ); + } + } + break; + } + case Qt::Key_PageDown: + // key: process as follows: + // - without , modifiers: last command in history + // - with modifier key pressed: move cursor one page down without selection + // - with modifier key pressed: move cursor one page down with selection + // - with + modifier keys pressed: scroll one page down + { + if ( ctrlPressed && shftPressed ) { + verticalScrollBar()->triggerAction(QAbstractSlider::SliderPageStepAdd); + } + else if ( shftPressed || ctrlPressed ) { + bool moved = false; + qreal lastY = cursorRect( cur ).top(); + qreal distance = 0; + // move using movePosition to keep the cursor's x + do { + qreal y = cursorRect( cur ).top(); + distance += qAbs( y - lastY ); + lastY = y; + moved = cur.movePosition( QTextCursor::Down, + shftPressed ? QTextCursor::KeepAnchor : + QTextCursor::MoveAnchor ); + } while ( moved && distance < viewport()->height() ); + if ( moved ) { + cur.movePosition( QTextCursor::Up, + shftPressed ? QTextCursor::KeepAnchor : + QTextCursor::MoveAnchor ); + verticalScrollBar()->triggerAction( QAbstractSlider::SliderPageStepSub ); + } + setTextCursor( cur ); + } + else { + if ( myCmdInHistory >= 0 ) { + // unset history browsing mode + myCmdInHistory = -1; + // print current command + moveCursor( QTextCursor::End ); + moveCursor( QTextCursor::StartOfBlock, QTextCursor::KeepAnchor ); + textCursor().removeSelectedText(); + addText( myPrompt + myCurrentCommand ); + // move cursor to the end + moveCursor( QTextCursor::End ); + } + } + break; + } + case Qt::Key_Home: + // key: process as follows: + // - without , modifiers: move cursor to the beginning of the current line without selection + // - with modifier key pressed: move cursor to the very first symbol without selection + // - with modifier key pressed: move cursor to the beginning of the current line with selection + // - with + modifier keys pressed: move cursor to the very first symbol with selection + { + if ( ctrlPressed ) { + moveCursor( QTextCursor::Start, + shftPressed ? QTextCursor::KeepAnchor : QTextCursor::MoveAnchor ); + } + else { + QString txt = textCursor().block().text(); + if ( isCommand( txt ) ) { + if ( shftPressed ) { + if ( curCol > PROMPT_SIZE ) { + cur.movePosition( QTextCursor::StartOfLine, QTextCursor::KeepAnchor ); + cur.movePosition( QTextCursor::Right, QTextCursor::KeepAnchor, PROMPT_SIZE ); + } + } + else { + cur.movePosition( QTextCursor::StartOfLine ); + cur.movePosition( QTextCursor::Right, QTextCursor::MoveAnchor, PROMPT_SIZE ); + } + setTextCursor( cur ); + } + else { + moveCursor( QTextCursor::StartOfBlock, + shftPressed ? QTextCursor::KeepAnchor : QTextCursor::MoveAnchor ); + } + horizontalScrollBar()->setValue( horizontalScrollBar()->minimum() ); + } + break; + } + case Qt::Key_End: + // key: process as follows: + // - without , modifiers: move cursor to the end of the current line without selection + // - with modifier key pressed: move cursor to the very last symbol without selection + // - with modifier key pressed: move cursor to the end of the current line with selection + // - with + modifier keys pressed: move cursor to the very last symbol with selection + { + moveCursor( ctrlPressed ? QTextCursor::End : QTextCursor::EndOfBlock, + shftPressed ? QTextCursor::KeepAnchor : QTextCursor::MoveAnchor ); + break; + } + case Qt::Key_Backspace : + // key: process as follows + // - without any modifiers : delete symbol before the cursor / selection (taking into account prompt) + // - with modifier key pressed: delete previous word + // - with modifier key pressed: delete text from the cursor to the line beginning + // works only for last (command) line + { + if ( cur.hasSelection() ) { + cut(); + } + else if ( cur.position() > document()->end().previous().position() + PROMPT_SIZE ) { + if ( shftPressed ) { + moveCursor( QTextCursor::PreviousWord, QTextCursor::KeepAnchor ); + textCursor().removeSelectedText(); + } + else if ( ctrlPressed ) { + cur.setPosition( document()->end().previous().position() + PROMPT_SIZE, + QTextCursor::KeepAnchor ); + setTextCursor( cur ); + textCursor().removeSelectedText(); + } + else { + QTextEdit::keyPressEvent( event ); + } + } + else { + cur.setPosition( document()->end().previous().position() + PROMPT_SIZE ); + setTextCursor( cur ); + horizontalScrollBar()->setValue( horizontalScrollBar()->minimum() ); + } + break; + } + case Qt::Key_Delete : + // key: process as follows + // - without any modifiers : delete symbol after the cursor / selection (taking into account prompt) + // - with modifier key pressed: delete next word + // - with modifier key pressed: delete text from the cursor to the end of line + // works only for last (command) line + { + if ( cur.hasSelection() ) { + cut(); + } + else if ( cur.position() > document()->end().previous().position() + PROMPT_SIZE-1 ) { + if ( shftPressed ) { + moveCursor( QTextCursor::NextWord, QTextCursor::KeepAnchor ); + textCursor().removeSelectedText(); + } + else if ( ctrlPressed ) { + moveCursor( QTextCursor::EndOfBlock, QTextCursor::KeepAnchor ); + textCursor().removeSelectedText(); + } + else { + QTextEdit::keyPressEvent( event ); + } + } + else { + cur.setPosition( document()->end().previous().position() + PROMPT_SIZE ); + setTextCursor( cur ); + horizontalScrollBar()->setValue( horizontalScrollBar()->minimum() ); + } + break; + } + case Qt::Key_Insert : + // key: process as follows + // - with modifier key pressed: copy() + // - with modifier key pressed: paste() to the command line + { + if ( ctrlPressed ) { + copy(); + } + else if ( shftPressed ) { + paste(); + } + else + QTextEdit::keyPressEvent( event ); + break; + } + } +} + +/*! + \brief Handle notification event coming from Python dispatcher. + \param event notification event +*/ +void PyConsole_Editor::customEvent( QEvent* event ) +{ + switch( event->type() ) + { + case PyInterp_Event::OK: + case PyInterp_Event::ERROR: + { + PyInterp_Event* pe = dynamic_cast( event ); + if ( pe ) + { + ExecCommand* ec = dynamic_cast( pe->GetRequest() ); + if ( ec ) + { + // The next line has appeared dangerous in case if + // Python command execution has produced very large output. + // A more clever approach is needed... + // print python output + addText( ec->myOutput, true ); + addText( ec->myError ); + } + } + // clear command buffer + myCommandBuffer.truncate( 0 ); + // set "ready" prompt + myPrompt = READY_PROMPT; + addText( myPrompt ); + // unset busy cursor + unsetCursor(); + // stop event loop (if running) + if ( myEventLoop ) + myEventLoop->exit(); + break; + } + case PyInterp_Event::INCOMPLETE: + { + // extend command buffer (multi-line command) + myCommandBuffer.append( "\n" ); + // set "dot" prompt + myPrompt = DOTS_PROMPT; + addText( myPrompt, true ); + // unset busy cursor + unsetCursor(); + // stop event loop (if running) + if ( myEventLoop ) + myEventLoop->exit(); + break; + } + default: + QTextEdit::customEvent( event ); + } + + // unset read-only state + setReadOnly( false ); + // unset history browsing mode + myCmdInHistory = -1; + + if ( (int)event->type() == (int)PyInterp_Event::OK && myQueue.count() > 0 ) + { + // process the next sheduled command from the queue (if there is any) + QString nextcmd = myQueue[0]; + myQueue.pop_front(); + exec( nextcmd ); + } +} + +/*! + \brief Handle Python interpreter change. + + Perform initialization actions if the interpreter is changed. + \param interp python interpreter is being set +*/ +void PyConsole_Editor::onPyInterpChanged( PyConsole_Interp* interp ) +{ + if ( myInterp != interp + // Force read-only state and wait cursor when myInterp is NULL + || !myInterp ) { + myInterp = interp; + if ( myInterp ) { + // print banner + myBanner = myInterp->getbanner().c_str(); + addText( myBanner ); + // clear command buffer + myCommandBuffer.truncate(0); + // unset read-only state + setReadOnly( false ); + // unset history browsing mode + myCmdInHistory = -1; + // add prompt + addText( myPrompt ); + // unset busy cursor + viewport()->unsetCursor(); + // stop event loop (if running) + if( myEventLoop) + myEventLoop->exit(); + } + else { + // clear contents + clear(); + // set read-only state + setReadOnly( true ); + // set busy cursor + setCursor( Qt::WaitCursor ); + } + } +} + +/*! + \brief "Copy" operation. + + Reimplemented from Qt. + Warning! In Qt4 this method is not virtual. + */ +void PyConsole_Editor::cut() +{ + QTextCursor cur = textCursor(); + if ( cur.hasSelection() ) { + QApplication::clipboard()->setText( cur.selectedText() ); + int startSelection = cur.selectionStart(); + if ( startSelection < document()->end().previous().position() + PROMPT_SIZE ) + startSelection = document()->end().previous().position() + PROMPT_SIZE; + int endSelection = cur.selectionEnd(); + if ( endSelection < document()->end().previous().position() + PROMPT_SIZE ) + endSelection = document()->end().previous().position() + PROMPT_SIZE; + cur.setPosition( startSelection ); + cur.setPosition( endSelection, QTextCursor::KeepAnchor ); + horizontalScrollBar()->setValue( horizontalScrollBar()->minimum() ); + setTextCursor( cur ); + textCursor().removeSelectedText(); + } +} + +/*! + \brief "Paste" operation. + + Reimplemented from Qt. + Warning! In Qt4 this method is not virtual. + */ +void PyConsole_Editor::paste() +{ + QTextCursor cur = textCursor(); + if ( cur.hasSelection() ) { + int startSelection = cur.selectionStart(); + if ( startSelection < document()->end().previous().position() + PROMPT_SIZE ) + startSelection = document()->end().previous().position() + PROMPT_SIZE; + int endSelection = cur.selectionEnd(); + if ( endSelection < document()->end().previous().position() + PROMPT_SIZE ) + endSelection = document()->end().previous().position() + PROMPT_SIZE; + cur.setPosition( startSelection ); + cur.setPosition( endSelection, QTextCursor::KeepAnchor ); + horizontalScrollBar()->setValue( horizontalScrollBar()->minimum() ); + setTextCursor( cur ); + textCursor().removeSelectedText(); + } + if ( textCursor().position() < document()->end().previous().position() + PROMPT_SIZE ) + moveCursor( QTextCursor::End ); + QTextEdit::paste(); +} + +/*! + \brief "Clear" operation. + + Reimplemented from Qt. + Warning! In Qt4 this method is not virtual. + */ +void PyConsole_Editor::clear() +{ + QTextEdit::clear(); + addText( myBanner ); + myPrompt = READY_PROMPT; + addText( myPrompt ); +} diff --git a/src/PyConsole/PyConsole_Editor.h b/src/PyConsole/PyConsole_Editor.h new file mode 100644 index 000000000..0e4c17028 --- /dev/null +++ b/src/PyConsole/PyConsole_Editor.h @@ -0,0 +1,83 @@ +// SALOME SALOMEGUI : implementation of desktop and GUI kernel +// +// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// 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 +// +// File : PyConsole_Editor.h +// Author : Vadim SANDLER +// Module : SALOME + +#ifndef PYCONSOLE_EDITOR_H +#define PYCONSOLE_EDITOR_H + +#include "PyConsole.h" + +#include + +class PyConsole_Interp; +class PyInterp_Request; +class QEventLoop; + +class PYCONSOLE_EXPORT PyConsole_Editor : public QTextEdit +{ + Q_OBJECT; + +public: + PyConsole_Editor( PyConsole_Interp* theInterp, QWidget *theParent = 0 ); + ~PyConsole_Editor(); + + virtual void addText( const QString& str, const bool newBlock = false ); + bool isCommand( const QString& str ) const; + + virtual void exec( const QString& command ); + void execAndWait( const QString& command ); + + bool isSync() const; + void setIsSync( const bool ); + +protected: + virtual void dropEvent( QDropEvent* event ); + virtual void mouseReleaseEvent( QMouseEvent* event ); + virtual void keyPressEvent ( QKeyEvent* event); + virtual void customEvent( QEvent* event); + + virtual PyInterp_Request* createRequest( const QString& ); + +public slots: + void cut(); + void paste(); + void clear(); + void handleReturn(); + void onPyInterpChanged( PyConsole_Interp* ); + +private: + PyConsole_Interp* myInterp; //!< python interpreter + + QString myCommandBuffer; //!< python comman buffer + QString myCurrentCommand; //!< currently being printed command + QString myPrompt; //!< current command line prompt + int myCmdInHistory; //!< current history command index + QStringList myHistory; //!< commands history buffer + QEventLoop* myEventLoop; //!< internal event loop + QString myBanner; //!< current banner + QStringList myQueue; //!< python commands queue + bool myIsSync; //!< synchronous mode flag +}; + +#endif // PYCONSOLE_EDITOR_H diff --git a/src/PyConsole/PyConsole_Interp.cxx b/src/PyConsole/PyConsole_Interp.cxx new file mode 100644 index 000000000..234e55973 --- /dev/null +++ b/src/PyConsole/PyConsole_Interp.cxx @@ -0,0 +1,130 @@ +// SALOME SALOMEGUI : implementation of desktop and GUI kernel +// +// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// 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 +// +// File : PyConsole_Interp.cxx +// Author : Nicolas REJNERI +// Module : SALOME + +#include "PyConsole_Interp.h" + +/*! + \class PyConsole_Interp + \brief Python interpreter to be embedded to the SALOME study's GUI. + + Python interpreter is created one per SALOME study. + + Call initialize method defined in the base class PyInterp_Interp, + to intialize interpreter after instance creation. + + The method initialize() calls virtuals methods + - initPython() to initialize global Python interpreter + - initState() to initialize embedded interpreter state + - initContext() to initialize interpreter internal context + - initRun() to prepare interpreter for running commands + + /EDF-CCAR/ + When SALOME uses multi Python interpreter feature, + every study has its own interpreter and thread state (_tstate = Py_NewInterpreter()). + This is fine because every study has its own modules (sys.modules) stdout and stderr. + + But some Python modules must be imported only once. In multi interpreter + context Python modules (*.py) are imported several times. + For example, the PyQt module must be imported only once because + it registers classes in a C module. + + It's quite the same with omniorb modules (internals and generated with omniidl). + + This problem is handled with "shared modules" defined in salome_shared_modules.py. + These "shared modules" are imported only once and only copied in all + the other interpreters. + + But it's not the only problem. Every interpreter has its own + __builtin__ module. That's fine but if we have copied some modules + and imported others problems may arise with operations that are not allowed + in restricted execution environment. So we must impose that all interpreters + have identical __builtin__ module. +*/ + +/*! + \brief Constructor. + + Creates new python interpreter. +*/ +PyConsole_Interp::PyConsole_Interp(): PyInterp_Interp() +{ +} + +/*! + \brief Destructor. + + Does nothing for the moment. +*/ +PyConsole_Interp::~PyConsole_Interp() +{ +} + +/*! + \brief Initialize internal Python interpreter state. + \return \c true on success +*/ +bool PyConsole_Interp::initState() +{ + // The GIL is acquired and will be held on initState output + // It is the caller responsability to release the lock if needed + PyEval_AcquireLock(); + _tstate = Py_NewInterpreter(); // create an interpreter and save current state + PySys_SetArgv(PyInterp_Interp::_argc,PyInterp_Interp::_argv); // initialize sys.argv + + //If builtinmodule has been initialized all the sub interpreters + // will have the same __builtin__ module + if(builtinmodule){ + PyObject *m = PyImport_GetModuleDict(); + PyDict_SetItemString(m, "__builtin__", builtinmodule); + _tstate->interp->builtins = PyModule_GetDict(builtinmodule); + Py_INCREF(_tstate->interp->builtins); + } + PyEval_ReleaseThread(_tstate); + return true; +} + +/*! + \brief Initialize python interpeter context. + + The GIL is assumed to be held. + It is the caller responsability caller to acquire the GIL. + It will still be held on initContext() exit. + + \return \c true on success +*/ +bool PyConsole_Interp::initContext() +{ + PyObject *m = PyImport_AddModule("__main__"); // interpreter main module (module context) + if(!m){ + PyErr_Print(); + return false; + } + _g = PyModule_GetDict(m); // get interpreter dictionnary context + + if(builtinmodule){ + PyDict_SetItemString(_g, "__builtins__", builtinmodule); // assign singleton __builtin__ module + } + return true; +} diff --git a/src/PyConsole/PyConsole_Interp.h b/src/PyConsole/PyConsole_Interp.h new file mode 100644 index 000000000..5e0b1f645 --- /dev/null +++ b/src/PyConsole/PyConsole_Interp.h @@ -0,0 +1,44 @@ +// SALOME SALOMEGUI : implementation of desktop and GUI kernel +// +// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// 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 +// +// File : PyConsole_Interp.h +// Author : Nicolas REJNERI +// Module : SALOME + +#ifndef PYCONSOLE_INTERP_H +#define PYCONSOLE_INTERP_H + +#include "PyConsole.h" + +#include /// !!! WARNING !!! THIS INCLUDE MUST BE VERY FIRST !!! + +class PYCONSOLE_EXPORT PyConsole_Interp : public PyInterp_Interp +{ +public: + PyConsole_Interp(); + ~PyConsole_Interp(); + +protected: + virtual bool initState(); + virtual bool initContext(); +}; + +#endif // PYCONSOLE_INTERP_H diff --git a/src/PyConsole/resources/PyConsole_msg_en.ts b/src/PyConsole/resources/PyConsole_msg_en.ts new file mode 100644 index 000000000..f016fe6b3 --- /dev/null +++ b/src/PyConsole/resources/PyConsole_msg_en.ts @@ -0,0 +1,26 @@ + + + + PythonConsole + + + EDIT_COPY_CMD + Copy + + + + EDIT_PASTE_CMD + Paste + + + + EDIT_CLEAR_CMD + Clear + + + + EDIT_SELECTALL_CMD + Select All + + + diff --git a/src/PythonConsole/Makefile.am b/src/PythonConsole/Makefile.am deleted file mode 100755 index 8884cfa45..000000000 --- a/src/PythonConsole/Makefile.am +++ /dev/null @@ -1,50 +0,0 @@ -# Copyright (C) 2005 CEA/DEN, EDF R&D, OPEN CASCADE, 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 -# -# File : Makefile.in -# Author : Vladimir Klyachin (OCN) -# Module : PythonConsole -# $Header$ - -include $(top_srcdir)/adm_local/unix/make_common_starter.am - -lib_LTLIBRARIES = libPythonConsole.la - -salomeinclude_HEADERS= \ - PythonConsole.h \ - PythonConsole_PyConsole.h \ - PythonConsole_PyEditor.h \ - PythonConsole_PyInterp.h - -dist_libPythonConsole_la_SOURCES= \ - PythonConsole_PyConsole.cxx \ - PythonConsole_PyEditor.cxx \ - PythonConsole_PyInterp.cxx - -MOC_FILES= \ - PythonConsole_PyEditor_moc.cxx \ - PythonConsole_PyConsole_moc.cxx -nodist_libPythonConsole_la_SOURCES= $(MOC_FILES) - - -libPythonConsole_la_CPPFLAGS= $(PYTHON_INCLUDES) $(QT_INCLUDES) \ - -I$(srcdir)/../PyInterp -I$(srcdir)/../SUIT -I$(srcdir)/../Qtx - -libPythonConsole_la_LDFLAGS= $(PYTHON_LIBS) $(QT_MT_LIBS) - - diff --git a/src/PythonConsole/PythonConsole.h b/src/PythonConsole/PythonConsole.h deleted file mode 100755 index 8e1db3946..000000000 --- a/src/PythonConsole/PythonConsole.h +++ /dev/null @@ -1,61 +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 -// -#if !defined ( _PYTHONCONSOLE_H ) -#define _PYTHONCONSOLE_H - -// ======================================================== -// set dllexport type for Win platform -#ifdef WNT - -#ifdef PYTHONCONSOLE_EXPORTS -#define PYCONSOLE_EXPORT __declspec(dllexport) -#else -#define PYCONSOLE_EXPORT __declspec(dllimport) -#endif - -#else // WNT - -#define PYCONSOLE_EXPORT - -#endif // WNT - -// ======================================================== -// little trick - if we do not have debug python libraries -#ifdef _DEBUG -#ifndef HAVE_DEBUG_PYTHON -#undef _DEBUG -#endif -#endif - -//#include - -#ifdef _DEBUG -#ifndef HAVE_DEBUG_PYTHON -#define _DEBUG -#endif -#endif - -// ======================================================== -// avoid warning messages -#ifdef WNT -#pragma warning (disable : 4786) -#pragma warning (disable : 4251) -#endif - -#endif // _PYTHONCONSOLE_H diff --git a/src/PythonConsole/PythonConsole_PyConsole.cxx b/src/PythonConsole/PythonConsole_PyConsole.cxx deleted file mode 100755 index 9c8f85237..000000000 --- a/src/PythonConsole/PythonConsole_PyConsole.cxx +++ /dev/null @@ -1,97 +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 -// - -#include -#include "PythonConsole_PyConsole.h" -#include "PythonConsole_PyEditor.h" -#include "PyInterp_base.h" - -#include "SUIT_Desktop.h" - -#include - -using namespace std; - -/*! - Constructor -*/ -PythonConsole::PythonConsole(QWidget* parent, PyInterp_base* interp) -: QWidget(parent), myEditor( 0 ) -{ - // create python interpreter - myInterp = interp; - if ( !myInterp ) - myInterp = new PythonConsole_PyInterp(); - - // initialize Python interpretator - myInterp->initialize(); - - // create editor console - QVBoxLayout* lay = new QVBoxLayout( this ); - myEditor = new PythonConsole_PyEditor(myInterp, this,"Python Interpreter"); - lay->addWidget( myEditor ); -} - -/*! - Destructor -*/ -PythonConsole::~PythonConsole() -{ -} - -/*! - Executes command - \param command - string with command and arguments -*/ -void PythonConsole::exec( const QString& command ) -{ - if ( myEditor ) - myEditor->exec( command ); -} - -/*! - Blocks execution of main application until command is executed - \param command - string with command and arguments -*/ -void PythonConsole::execAndWait( const QString& command ) -{ - if ( myEditor ) - myEditor->execAndWait( command ); -} - -/*! - Changes font of python console - \param f - new font -*/ -void PythonConsole::setFont( const QFont& f ) -{ - if( myEditor ) - myEditor->setFont( f ); -} - -/*! - \return font of python console -*/ -QFont PythonConsole::font() const -{ - QFont res; - if( myEditor ) - res = myEditor->font(); - return res; -} diff --git a/src/PythonConsole/PythonConsole_PyConsole.h b/src/PythonConsole/PythonConsole_PyConsole.h deleted file mode 100755 index b3364e597..000000000 --- a/src/PythonConsole/PythonConsole_PyConsole.h +++ /dev/null @@ -1,49 +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 -// -#ifndef PythonConsole_PyConsole_H -#define PythonConsole_PyConsole_H - -#include "PythonConsole.h" - -#include - -class PythonConsole_PyEditor; -class PyInterp_base; - -class PYCONSOLE_EXPORT PythonConsole: public QWidget -{ - Q_OBJECT; - -public: - PythonConsole(QWidget* parent, PyInterp_base* interp = 0 ); - virtual ~PythonConsole(); - - PyInterp_base* getInterp() { return myInterp; } - QFont font() const; - virtual void setFont( const QFont& ); - - void exec( const QString& command ); - void execAndWait( const QString& command ); -protected: - PyInterp_base* myInterp; - PythonConsole_PyEditor* myEditor; -}; - - -#endif diff --git a/src/PythonConsole/PythonConsole_PyEditor.cxx b/src/PythonConsole/PythonConsole_PyEditor.cxx deleted file mode 100755 index 30291e0c4..000000000 --- a/src/PythonConsole/PythonConsole_PyEditor.cxx +++ /dev/null @@ -1,764 +0,0 @@ -// SALOME SALOMEGUI : implementation of desktop and GUI kernel -// -// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, -// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS -// -// 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 -// -// -// -// File : PythonConsole_PyEditor.cxx -// Author : Nicolas REJNERI -// Module : SALOME - -#include // this include must be first (see PyInterp_base.h)! - -#include - -#include -#include - -#include -#include -#include -#include -#include - -using namespace std; - -//#ifdef _DEBUG_ -//static int MYDEBUG = 1; -//#else -//static int MYDEBUG = 0; -//#endif - - -enum { IdCopy, IdPaste, IdClear, IdSelectAll }; - - -static QString READY_PROMPT = ">>> "; -static QString DOTS_PROMPT = "... "; - -#define PROMPT_SIZE (int)_currentPrompt.length() - -class ExecCommand : public PyInterp_LockRequest -{ -public: - ExecCommand(PyInterp_base* theInterp, const char* theCommand, - PythonConsole_PyEditor* theListener, bool sync = false) - : PyInterp_LockRequest( theInterp, theListener, sync ), - myCommand( theCommand ), myState( PyInterp_Event::OK ) - {} - -protected: - virtual void execute(){ - if(myCommand != ""){ -// if(MYDEBUG) MESSAGE("*** ExecCommand::execute() started"); - SUIT_Session::SetPythonExecuted(true); // disable GUI user actions - int ret = getInterp()->run( myCommand.latin1() ); - SUIT_Session::SetPythonExecuted(false); // enable GUI user actions -// if(MYDEBUG) MESSAGE("ExecCommand::execute() - myInterp = "< 0) - myState = PyInterp_Event::INCOMPLETE; - myError = getInterp()->getverr().c_str(); - myOutput = getInterp()->getvout().c_str(); -// if(MYDEBUG) MESSAGE("*** ExecCommand::execute() finished"); - }else{ - myError = ""; - myOutput = ""; - } - } - - virtual QEvent* createEvent() const - { - return new PyInterp_Event( myState, (PyInterp_Request*)this ); - } - -public: - QString myError; - QString myOutput; - -private: - QString myCommand; - int myState; -}; - - -/*! - Constructor -*/ -PythonConsole_PyEditor::PythonConsole_PyEditor(PyInterp_base* theInterp, QWidget *theParent, const char* theName): - QTextEdit(theParent,theName), - myInterp( 0 ), - myIsInLoop( false ) -{ - QString fntSet( "" ); - QFont aFont = SUIT_Tools::stringToFont( fntSet ); - setFont(aFont); - //setTextFormat(QTextEdit::PlainText); - setUndoRedoEnabled( false ); - - _currentPrompt = READY_PROMPT; - setWordWrap(NoWrap); - - connect(this,SIGNAL(returnPressed()),this,SLOT(handleReturn()) ); - - // san - This is necessary for troubleless initialization - onPyInterpChanged( theInterp ); -} - -/*! - Destructor -*/ -PythonConsole_PyEditor::~PythonConsole_PyEditor() -{ -// if(MYDEBUG) MESSAGE("PythonConsole_PyEditor::~PythonConsole_PyEditor()"); -} - -/*! - Called to insert a string s -*/ -void PythonConsole_PyEditor::setText(QString s) -{ - int para=paragraphs()-1; - int col=paragraphLength(para); - insertAt(s,para,col); - int n = paragraphs()-1; - setCursorPosition( n, paragraphLength(n)); -} - -/*! - Convenient method for executing a Python command, - as if the user typed it manually -*/ -void PythonConsole_PyEditor::exec( const QString& command ) -{ - // Some interactive command is being executed in this editor -> do nothing - if ( isReadOnly() ) { - myQueue.push_back( command ); - return; - } - int para=paragraphs()-1; - removeParagraph( para ); - _currentPrompt = READY_PROMPT; - _buf.truncate(0); - _isInHistory = false; - setText( "\n" + _currentPrompt); - setText( command + "\n" ); - handleReturn(); -} - -void PythonConsole_PyEditor::execAndWait( const QString& command ) -{ - if( myIsInLoop ) - return; - - myIsInLoop = true; - exec( command ); - qApp->enter_loop(); - myIsInLoop = false; -} - -/*! - Called when an handleReturn -*/ -void PythonConsole_PyEditor::handleReturn() -{ - int para=paragraphs()-2; - _buf.append(text(para).remove(0,PROMPT_SIZE)); - _buf.truncate( _buf.length() - 1 ); - setReadOnly( true ); - viewport()->setCursor( waitCursor ); - - // Post a request to execute Python command - // Editor will be informed via a custom event that execution has been completed - PyInterp_Dispatcher::Get()->Exec( new ExecCommand( myInterp, _buf.latin1(), this ) ); -} - -/*! - Processes drop event: paste dragged text -*/ -void PythonConsole_PyEditor::contentsDropEvent( QDropEvent* event ) -{ - event->acceptAction(); - QString text; - if ( QTextDrag::decode( event, text ) ) { - int par, col; - int endLine = paragraphs() -1; - col = charAt( event->pos(), &par ); - - if ( col >= 0 && par >= 0 ) { - if ( par != endLine || col < PROMPT_SIZE ) { - par = endLine; - col = paragraphLength( endLine ); - } - setCursorPosition( par, col ); - insertAt( text, par, col ); - removeSelection(); - } - } -} - -/*! - Processes middle button release event - paste clipboard's contents -*/ -void PythonConsole_PyEditor::contentsMouseReleaseEvent( QMouseEvent* event ) -{ - if ( event->button() == LeftButton ) { - QTextEdit::contentsMouseReleaseEvent(event); - copy(); - } - if ( event->button() == MidButton ) { - if (QApplication::clipboard()->supportsSelection()) { - int par, col; - int endLine = paragraphs() -1; - col = charAt( event->pos(), &par ); - if ( col >= 0 && par >= 0 ) { - // PAL12896 --> - if ( par != endLine || col < PROMPT_SIZE ) { - QPoint aPos = paragraphRect(endLine).bottomRight(); - QMouseEvent* e = new QMouseEvent(event->type(),aPos,event->button(),event->state()); - QTextEdit::contentsMouseReleaseEvent(e); - } - else - QTextEdit::contentsMouseReleaseEvent(event); - // PAL12896 <-- - } - } - } - else { - QTextEdit::contentsMouseReleaseEvent(event); - } -} - -/* - Processes own popup menu -*/ -void PythonConsole_PyEditor::mousePressEvent (QMouseEvent* event) -{ - if ( event->button() == RightButton ) { - QPopupMenu *popup = new QPopupMenu( this ); - QMap idMap; - - int para1, col1, para2, col2; - getSelection(¶1, &col1, ¶2, &col2); - bool allSelected = hasSelectedText() && - para1 == 0 && para2 == paragraphs()-1 && col1 == 0 && para2 == paragraphLength(para2); - int id; - id = popup->insertItem( tr( "EDIT_COPY_CMD" ) ); - idMap.insert(IdCopy, id); - id = popup->insertItem( tr( "EDIT_PASTE_CMD" ) ); - idMap.insert(IdPaste, id); - id = popup->insertItem( tr( "EDIT_CLEAR_CMD" ) ); - idMap.insert(IdClear, id); - popup->insertSeparator(); - id = popup->insertItem( tr( "EDIT_SELECTALL_CMD" ) ); - idMap.insert(IdSelectAll, id); - popup->setItemEnabled( idMap[ IdCopy ], hasSelectedText() ); - popup->setItemEnabled( idMap[ IdPaste ], - !isReadOnly() && (bool)QApplication::clipboard()->text().length() ); - popup->setItemEnabled( idMap[ IdSelectAll ], - (bool)text().length() && !allSelected ); - - int r = popup->exec( event->globalPos() ); - delete popup; - - if ( r == idMap[ IdCopy ] ) { - copy(); - } - else if ( r == idMap[ IdPaste ] ) { - paste(); - } - else if ( r == idMap[ IdClear ] ) { - clear(); - setText(myBanner); - _currentPrompt = READY_PROMPT; - setText(_currentPrompt); - } - else if ( r == idMap[ IdSelectAll ] ) { - selectAll(); - } - } - else { - QTextEdit::mousePressEvent(event); - } -} - -/*! - Checks, is the string a command line or not. -*/ - -bool PythonConsole_PyEditor::isCommand( const QString& str) const -{ - // prompt may be '>>> ' or for '... ' - return ( str.find( READY_PROMPT ) == 0 || str.find( DOTS_PROMPT ) == 0 ); -} - - -/*! - Called when a keyPress event -*/ -void PythonConsole_PyEditor::keyPressEvent( QKeyEvent* e ) -{ - // get cursor position - int curLine, curCol; - getCursorPosition(&curLine, &curCol); - - // get last edited line - int endLine = paragraphs() -1; - - // get pressed key code - int aKey = e->key(); - - // check if is pressed - bool ctrlPressed = e->state() & ControlButton; - // check if is pressed - bool shftPressed = e->state() & ShiftButton; - - // process + key-bindings - if ( aKey == Key_C && ctrlPressed ) { - _buf.truncate(0); - setText("\n"); - _currentPrompt = READY_PROMPT; - setText(_currentPrompt); - return; - } - - // check for printed key - aKey = ( aKey < Key_Space || aKey > Key_ydiaeresis ) ? aKey : 0; - - switch ( aKey ) { - case 0 : - // any printed key - { - if ( curLine < endLine || curCol < PROMPT_SIZE ) - moveCursor( QTextEdit::MoveEnd, false ); - QTextEdit::keyPressEvent( e ); - break; - } - case Key_Return: - case Key_Enter: - // key - { - moveCursor( QTextEdit::MoveEnd, false ); - QTextEdit::keyPressEvent( e ); - break; - } - case Key_Up: - // arrow key: process as follows: - // - without , modifiers: previous command in history - // - with modifier key pressed: move cursor one row up without selection - // - with modifier key pressed: move cursor one row up with selection - // - with + modifier keys pressed: scroll one row up - { - if ( ctrlPressed && shftPressed ) { - scrollBy( 0, -QFontMetrics( font() ).lineSpacing() ); - } - else if ( shftPressed ) { - if ( curLine > 0 ) - moveCursor( QTextEdit::MoveUp, true ); - } - else if ( ctrlPressed ) { - moveCursor( QTextEdit::MoveUp, false ); - } - else { - QString histLine = _currentPrompt; - if ( ! _isInHistory ) { - _isInHistory = true; - _currentCommand = text( endLine ).remove( 0, PROMPT_SIZE ); - _currentCommand.truncate( _currentCommand.length() - 1 ); - } - QString previousCommand = myInterp->getPrevious(); - if ( previousCommand.compare( BEGIN_HISTORY_PY ) != 0 ) - { - removeParagraph( endLine ); - histLine.append( previousCommand ); - append( histLine ); - } - moveCursor( QTextEdit::MoveEnd, false ); - } - break; - } - case Key_Down: - // arrow key: process as follows: - // - without , modifiers: next command in history - // - with modifier key pressed: move cursor one row down without selection - // - with modifier key pressed: move cursor one row down with selection - // - with + modifier keys pressed: scroll one row down - { - if ( ctrlPressed && shftPressed ) { - scrollBy( 0, QFontMetrics( font() ).lineSpacing() ); - } - else if ( shftPressed ) { - if ( curLine < endLine ) - moveCursor( QTextEdit::MoveDown, true ); - } - else if ( ctrlPressed ) { - moveCursor( QTextEdit::MoveDown, false ); - } - else { - QString histLine = _currentPrompt; - QString nextCommand = myInterp->getNext(); - if ( nextCommand.compare( TOP_HISTORY_PY ) != 0 ) { - removeParagraph( endLine ); - histLine.append( nextCommand ); - append( histLine ); - } - else { - if (_isInHistory) { - _isInHistory = false; - removeParagraph( endLine ); - histLine.append( _currentCommand ); - append( histLine ); - } - } - moveCursor( QTextEdit::MoveEnd, false ); - } - break; - } - case Key_Left: - // arrow key: process as follows: - // - without , modifiers: move one symbol left (taking into account prompt) - // - with modifier key pressed: move one word left (taking into account prompt) - // - with modifier key pressed: move one symbol left with selection - // - with + modifier keys pressed: move one word left with selection - { - if ( !shftPressed && isCommand( text( curLine ) ) && curCol <= PROMPT_SIZE ) { - setCursorPosition( curLine-1, 0 ); - moveCursor( QTextEdit::MoveLineEnd, false ); - } - else { - QTextEdit::keyPressEvent( e ); - } - break; - } - case Key_Right: - // arrow key: process as follows: - // - without , modifiers: move one symbol right (taking into account prompt) - // - with modifier key pressed: move one word right (taking into account prompt) - // - with modifier key pressed: move one symbol right with selection - // - with + modifier keys pressed: move one word right with selection - { - if ( !shftPressed ) { - if ( curCol < paragraphLength( curLine ) ) { - if ( isCommand( text( curLine ) ) && curCol < PROMPT_SIZE ) { - setCursorPosition( curLine, PROMPT_SIZE ); - break; - } - } - else { - if ( curLine < endLine && isCommand( text( curLine+1 ) ) ) { - setCursorPosition( curLine+1, PROMPT_SIZE ); - break; - } - } - } - QTextEdit::keyPressEvent( e ); - break; - } - case Key_PageUp: - // key: process as follows: - // - without , modifiers: first command in history - // - with modifier key pressed: move cursor one page up without selection - // - with modifier key pressed: move cursor one page up with selection - // - with + modifier keys pressed: scroll one page up - { - if ( ctrlPressed && shftPressed ) { - scrollBy( 0, -visibleHeight() ); - } - else if ( shftPressed ) { - if ( curLine > 0 ) - moveCursor( QTextEdit::MovePgUp, true ); - } - else if ( ctrlPressed ) { - moveCursor( QTextEdit::MovePgUp, false ); - } - else { - QString histLine = _currentPrompt; - if ( ! _isInHistory ) { - _isInHistory = true; - _currentCommand = text( endLine ).remove( 0, PROMPT_SIZE ); - _currentCommand.truncate( _currentCommand.length() - 1 ); - } - QString firstCommand = myInterp->getPrevious(); - QString pcmd; - while ( ( pcmd = QString( myInterp->getPrevious() ) ).compare( BEGIN_HISTORY_PY ) != 0 ) - firstCommand = pcmd; - if ( firstCommand.compare( BEGIN_HISTORY_PY ) != 0 ) { - removeParagraph( endLine ); - histLine.append( firstCommand ); - insertParagraph( histLine, -1 ); - } - moveCursor( QTextEdit::MoveEnd, false ); - } - break; - } - case Key_PageDown: - // key: process as follows: - // - without , modifiers: last command in history - // - with modifier key pressed: move cursor one page down without selection - // - with modifier key pressed: move cursor one page down with selection - // - with + modifier keys pressed: scroll one page down - { - if ( ctrlPressed && shftPressed ) { - scrollBy( 0, visibleHeight() ); - } - else if ( shftPressed ) { - if ( curLine < endLine ) - moveCursor( QTextEdit::MovePgDown, true ); - } - else if ( ctrlPressed ) { - moveCursor( QTextEdit::MovePgDown, false ); - } - else { - if ( _isInHistory ) { - QString histLine = _currentPrompt; - while ( QString( myInterp->getNext() ).compare( TOP_HISTORY_PY ) != 0 ); - _isInHistory = false; - removeParagraph( endLine ); - histLine.append( _currentCommand ); - insertParagraph( histLine, -1 ); - } - moveCursor( QTextEdit::MoveEnd, false ); - } - break; - } - case Key_Home: - // key: process as follows: - // - without , modifiers: move cursor to the beginning of the current line without selection - // - with modifier key pressed: move cursor to the very first symbol without selection - // - with modifier key pressed: move cursor to the beginning of the current line with selection - // - with + modifier keys pressed: move cursor to the very first symbol with selection - { - if ( ctrlPressed ) { - moveCursor( QTextEdit::MoveHome, shftPressed ); - } - else { - if ( isCommand( text( curLine ) ) ) { - int ps1, ps2, cs1, cs2; - bool hasSelection = hasSelectedText(); - if ( hasSelection ) - getSelection( &ps1, &cs1, &ps2, &cs2 ); - removeSelection(); - horizontalScrollBar()->setValue( horizontalScrollBar()->minValue() ); - if ( curCol > PROMPT_SIZE && shftPressed ) - setSelection( curLine, PROMPT_SIZE, curLine, ( hasSelection && ps1 == ps2 && ps1 == curLine && cs2 > PROMPT_SIZE ) ? cs2 : curCol ); - setCursorPosition( curLine, PROMPT_SIZE ); - } - else { - moveCursor( QTextEdit::MoveLineStart, shftPressed ); - } - } - break; - } - case Key_End: - // key: process as follows: - // - without , modifiers: move cursor to the end of the current line without selection - // - with modifier key pressed: move cursor to the very last symbol without selection - // - with modifier key pressed: move cursor to the end of the current line with selection - // - with + modifier keys pressed: move cursor to the very last symbol with selection - { - if ( ctrlPressed ) { - moveCursor( QTextEdit::MoveEnd, shftPressed ); - } - else { - moveCursor( QTextEdit::MoveLineEnd, shftPressed ); - } - break; - } - case Key_Backspace : - // key: process as follows - // - without any modifiers : delete symbol before the cursor / selection (taking into account prompt) - // - with modifier key pressed: delete previous word - // works only for last (command) line - { - if ( curLine == endLine && ( curCol > PROMPT_SIZE || curCol >= PROMPT_SIZE && hasSelectedText() ) ) { - if ( ctrlPressed && !hasSelectedText() ) { - QString txt = text( curLine ); - int ind = curCol-1; - while ( ind > 0 && txt[ ind ] == ' ' ) ind--; - ind = txt.findRev( ' ', ind ) + 1; - if ( ind > PROMPT_SIZE-1 ) { - setSelection( curLine, ind, curLine, curCol ); - removeSelectedText(); - } - else { - QTextEdit::keyPressEvent( e ); - } - } - else { - QTextEdit::keyPressEvent( e ); - } - } - break; - } - case Key_Delete : - // key: process as follows - // - without any modifiers : delete symbol after the cursor / selection (taking into account prompt) - // - with modifier key pressed: delete next word - // works only for last (command) line - { - if ( curLine == endLine && curCol > PROMPT_SIZE-1 ) { - if ( ctrlPressed && !hasSelectedText() ) { - QString txt = text( curLine ); - int ind = curCol; - while ( ind < (int)( txt.length() - 1 ) && txt[ind] == ' ' ) ind++; - ind = txt.find( ' ', ind ); - while ( ind < (int)( txt.length() - 1 ) && txt[ ind ] == ' ' ) ind++; - if ( ind > PROMPT_SIZE-1 ) { - setSelection( curLine, curCol, curLine, ind ); - removeSelectedText(); - } - else { - QTextEdit::keyPressEvent( e ); - } - } - else { - QTextEdit::keyPressEvent( e ); - } - } - break; - } - case Key_Insert : - // key: process as follows - // - with modifier key pressed: copy() - // - with modifier key pressed: paste() to the command line - { - if ( ctrlPressed ) { - copy(); - } - else if ( shftPressed ) { - if ( curLine != endLine || curCol < PROMPT_SIZE ) - moveCursor( QTextEdit::MoveEnd, false ); - paste(); - } - else - QTextEdit::keyPressEvent( e ); - break; - } - } -} - -/*! - Handles notifications coming from Python dispatcher -*/ -void PythonConsole_PyEditor::customEvent(QCustomEvent* e) -{ - switch( e->type() ) { - case PyInterp_Event::OK: - case PyInterp_Event::ERROR: - { - PyInterp_Event* pe = dynamic_cast( e ); - if ( pe ){ - ExecCommand* ec = dynamic_cast( pe->GetRequest() ); - if ( ec ){ - // The next line has appeared dangerous in case if - // Python command execution has produced very large output. - // A more clever approach is needed... - setText(ec->myOutput); - setText(ec->myError); - } - } - _buf.truncate(0); - _currentPrompt = READY_PROMPT; - setText(_currentPrompt); - viewport()->unsetCursor(); - if( myIsInLoop ) - qApp->exit_loop(); - break; - } - case PyInterp_Event::INCOMPLETE: - { - _buf.append("\n"); - _currentPrompt = DOTS_PROMPT; - setText(_currentPrompt); - viewport()->unsetCursor(); - if( myIsInLoop ) - qApp->exit_loop(); - break; - } - default: - QTextEdit::customEvent( e ); - } - - setReadOnly( false ); - _isInHistory = false; - - if ( e->type() == PyInterp_Event::OK && myQueue.count() > 0 ) { - QString nextcmd = myQueue[0]; - myQueue.pop_front(); - exec( nextcmd ); - } -} - -/*! - Handles Python interpreter change -*/ -void PythonConsole_PyEditor::onPyInterpChanged( PyInterp_base* interp ) -{ - if ( myInterp != interp - // Force read-only state and wait cursor when myInterp is NULL - || !myInterp ){ - myInterp = interp; - if ( myInterp ){ - myBanner = myInterp->getbanner().c_str(); - setText(myBanner); - _buf.truncate(0); - setReadOnly( false ); - _isInHistory = false; - setText(_currentPrompt); - viewport()->unsetCursor(); - if( myIsInLoop ) - qApp->exit_loop(); - } - else { - clear(); - setReadOnly( true ); - viewport()->setCursor( waitCursor ); - } - } -} - -/*! - Creates popup menu -*/ -QPopupMenu* PythonConsole_PyEditor::createPopupMenu( const QPoint& pos ) -{ - QPopupMenu* popup = QTextEdit::createPopupMenu( pos ); - - QValueList ids; - for ( int i = 0; popup && i < (int)popup->count(); i++ ) - { - if ( !popup->isItemEnabled( popup->idAt( i ) ) ) - ids.append( popup->idAt( i ) ); - } - - for ( QValueList::const_iterator it = ids.begin(); it != ids.end(); ++it ) - popup->removeItem( *it ); - - SUIT_Tools::simplifySeparators( popup ); - - if ( !popup->count() ) - { - delete popup; - popup = 0; - } - - return popup; -} diff --git a/src/PythonConsole/PythonConsole_PyEditor.h b/src/PythonConsole/PythonConsole_PyEditor.h deleted file mode 100755 index b353ee4da..000000000 --- a/src/PythonConsole/PythonConsole_PyEditor.h +++ /dev/null @@ -1,79 +0,0 @@ -// SALOME SALOMEGUI : implementation of desktop and GUI kernel -// -// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, -// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS -// -// 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 -// -// -// -// File : PythonConsole_PyEditor.h -// Author : Nicolas REJNERI -// Module : SALOME - -#ifndef PythonConsole_PyEditor_H -#define PythonConsole_PyEditor_H - -#include "PythonConsole_PyInterp.h" // this include must be first (see PyInterp_base.h)! - -#include -#include - -class PythonConsole_PyInterp; - -class PYCONSOLE_EXPORT PythonConsole_PyEditor : public QTextEdit -{ - Q_OBJECT; - -public: - PythonConsole_PyEditor(PyInterp_base* theInterp, QWidget *theParent = 0, const char* theName = ""); - ~PythonConsole_PyEditor(); - - virtual void setText(QString s); - bool isCommand(const QString& str) const; - - virtual void exec( const QString& command ); - void execAndWait( const QString& command ); - -protected: - virtual void contentsDropEvent( QDropEvent* event ); - virtual void contentsMouseReleaseEvent( QMouseEvent* event ); - virtual void keyPressEvent (QKeyEvent* event); - virtual void mousePressEvent (QMouseEvent* event); - virtual void customEvent (QCustomEvent* event); - -public slots: - void handleReturn(); - void onPyInterpChanged( PyInterp_base* ); - - virtual QPopupMenu* createPopupMenu( const QPoint& ); - -private: - QString _buf; - QString _currentCommand; - QString _currentPrompt; - bool _isInHistory, myIsInLoop; - - PyInterp_base* myInterp; - - QString myBanner; - QString myOutput; - QString myError; - QStringList myQueue; -}; - -#endif diff --git a/src/PythonConsole/PythonConsole_PyInterp.cxx b/src/PythonConsole/PythonConsole_PyInterp.cxx deleted file mode 100755 index da23b5f04..000000000 --- a/src/PythonConsole/PythonConsole_PyInterp.cxx +++ /dev/null @@ -1,134 +0,0 @@ -// SALOME SALOMEGUI : implementation of desktop and GUI kernel -// -// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, -// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS -// -// 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 -// -// -// -// File : PythonConsole_PyInterp.cxx -// Author : Nicolas REJNERI -// Module : SALOME -// $Header$ - -#include "PythonConsole_PyInterp.h" -//#include "utilities.h" - -using namespace std; - - -//#ifdef _DEBUG_ -//static int MYDEBUG = 0; -//#else -//static int MYDEBUG = 0; -//#endif - - -/*! - * constructor : multi Python interpreter, one per SALOME study. - * calls initialize method defined in base class, which calls virtual methods - * initstate & initcontext redefined here. - */ -PythonConsole_PyInterp::PythonConsole_PyInterp(): PyInterp_base() -{ -} - -/*! - Destructor -*/ -PythonConsole_PyInterp::~PythonConsole_PyInterp() -{ -} - -/*! - * EDF-CCAR - * When SALOME uses multi Python interpreter feature, - * Every study has its own interpreter and thread state (_tstate = Py_NewInterpreter()) - * This is fine because every study has its own modules (sys.modules) stdout and stderr - * BUT some Python modules must be imported only once. In multi interpreter context Python - * modules (*.py) are imported several times. - * The pyqt module must be imported only once because it registers classes in a C module. - * It's quite the same with omniorb modules (internals and generated with omniidl) - * This problem is handled with "shared modules" defined in salome_shared_modules.py - * These "shared modules" are imported only once and only copied in all the other interpreters - * BUT it's not the only problem. Every interpreter has its own __builtin__ module. That's fine - * but if we have copied some modules and imported others problems may arise with operations that - * are not allowed in restricted execution environment. So we must impose that all interpreters - * have identical __builtin__ module. - * That's all, for the moment ... - */ - -bool PythonConsole_PyInterp::initState() -{ - /* - * The GIL is acquired and will be held on initState output - * It is the caller responsability to release the lock if needed - */ - PyEval_AcquireLock(); -#ifdef WNT - _tstate = PyGILState_GetThisThreadState(); - // if no thread state defined - if ( _tstate ) - PyThreadState_Swap(_tstate); - else -#endif - { - _tstate = Py_NewInterpreter(); // create an interpreter and save current state - PySys_SetArgv(PyInterp_base::_argc,PyInterp_base::_argv); // initialize sys.argv - //if(MYDEBUG) MESSAGE("PythonConsole_PyInterp::initState - this = "<ob_refcnt); // builtinmodule reference counter - _tstate->interp->builtins = PyModule_GetDict(builtinmodule); - Py_INCREF(_tstate->interp->builtins); - } - PyEval_ReleaseThread(_tstate); - return true; -} - -/*! - The GIL is assumed to be held - It is the caller responsability caller to acquire the GIL - It will still be held on initContext output -*/ -bool PythonConsole_PyInterp::initContext() -{ - PyObject *m = PyImport_AddModule("__main__"); // interpreter main module (module context) - if(!m){ -// if(MYDEBUG) MESSAGE("problem..."); - PyErr_Print(); -// ASSERT(0); - return false; - } - _g = PyModule_GetDict(m); // get interpreter dictionnary context -// if(MYDEBUG) MESSAGE("PythonConsole_PyInterp::initContext - this = "< // this include must be first (see PyInterp_base.h)! - -class PYCONSOLE_EXPORT PythonConsole_PyInterp : public PyInterp_base -{ -public: - PythonConsole_PyInterp(); - ~PythonConsole_PyInterp(); - -protected: - virtual bool initState(); - virtual bool initContext(); -}; - -#endif diff --git a/src/QDS/QDS_ComboBox.h b/src/QDS/QDS_ComboBox.h index 2a8791702..1f0b90fc2 100644 --- a/src/QDS/QDS_ComboBox.h +++ b/src/QDS/QDS_ComboBox.h @@ -27,7 +27,7 @@ #include -#ifdef WNT +#ifdef WIN32 #pragma warning( disable:4251 ) #endif @@ -103,7 +103,7 @@ private: QStringList myUserNames; }; -#ifdef WNT +#ifdef WIN32 #pragma warning( default:4251 ) #endif diff --git a/src/QDS/QDS_RadioBox.h b/src/QDS/QDS_RadioBox.h index 862b6ab4f..da0cc82f0 100644 --- a/src/QDS/QDS_RadioBox.h +++ b/src/QDS/QDS_RadioBox.h @@ -27,7 +27,7 @@ #include #include -#ifdef WNT +#ifdef WIN32 #pragma warning( disable:4251 ) #endif @@ -86,7 +86,7 @@ private: QStringList myUserNames; }; -#ifdef WNT +#ifdef WIN32 #pragma warning( default:4251 ) #endif diff --git a/src/RegistryDisplay/IntervalWindow.hxx b/src/RegistryDisplay/IntervalWindow.hxx index 420ce5a0a..7e746ed51 100755 --- a/src/RegistryDisplay/IntervalWindow.hxx +++ b/src/RegistryDisplay/IntervalWindow.hxx @@ -30,7 +30,7 @@ # include # include -#ifndef WNT +#ifndef WIN32 using namespace std; #endif diff --git a/src/RegistryDisplay/RegWidget.cxx b/src/RegistryDisplay/RegWidget.cxx index 413dca711..bd6da2cda 100755 --- a/src/RegistryDisplay/RegWidget.cxx +++ b/src/RegistryDisplay/RegWidget.cxx @@ -808,7 +808,7 @@ QString findFile( QString filename ) QString addSlash( const QString& path ) { if (!path.isNull()) { -#ifdef WNT +#ifdef WIN32 QChar slash ('\\'); #else QChar slash ('/'); diff --git a/src/RegistryDisplay/RegWidget.h b/src/RegistryDisplay/RegWidget.h index 3a1431777..c3f2015c7 100755 --- a/src/RegistryDisplay/RegWidget.h +++ b/src/RegistryDisplay/RegWidget.h @@ -43,9 +43,7 @@ class QWidget; class QTimer; class QCloseEvent; class QTextView; -#if QT_VERSION > 300 class QPushButton; -#endif class HelpWindow; class InfoWindow; diff --git a/src/SALOME_PYQT/SALOME_PYQT_GUI/SALOME_PYQT_GUI.h b/src/SALOME_PYQT/SALOME_PYQT_GUI/SALOME_PYQT_GUI.h index 8c436985c..0b646291a 100644 --- a/src/SALOME_PYQT/SALOME_PYQT_GUI/SALOME_PYQT_GUI.h +++ b/src/SALOME_PYQT/SALOME_PYQT_GUI/SALOME_PYQT_GUI.h @@ -21,7 +21,7 @@ // ======================================================== // set dllexport type for Win platform -#ifdef WNT +#ifdef WIN32 #ifdef SALOME_PYQT_EXPORTS #define SALOME_PYQT_EXPORT __declspec(dllexport) @@ -29,15 +29,15 @@ #define SALOME_PYQT_EXPORT __declspec(dllimport) #endif -#else // WNT +#else // WIN32 #define SALOME_PYQT_EXPORT -#endif // WNT +#endif // WIN32 // ======================================================== // avoid warning messages -#ifdef WNT +#ifdef WIN32 #pragma warning (disable : 4786) #pragma warning (disable : 4251) #endif diff --git a/src/SOCC/SOCC.h b/src/SOCC/SOCC.h index 99e77291a..40d28ff8a 100755 --- a/src/SOCC/SOCC.h +++ b/src/SOCC/SOCC.h @@ -16,7 +16,7 @@ // // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // -#ifdef WNT +#ifdef WIN32 #ifdef SOCC_EXPORTS #define SOCC_EXPORT __declspec(dllexport) #else @@ -26,6 +26,6 @@ #define SOCC_EXPORT #endif -#if defined WNT +#if defined WIN32 #pragma warning ( disable: 4251 ) #endif diff --git a/src/SPlot2d/SPlot2d.h b/src/SPlot2d/SPlot2d.h index 39e4c1245..475bc6cf3 100644 --- a/src/SPlot2d/SPlot2d.h +++ b/src/SPlot2d/SPlot2d.h @@ -16,7 +16,7 @@ // // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // -#ifdef WNT +#ifdef WIN32 #ifdef SPLOT2D_EXPORTS #define SPLOT2D_EXPORT __declspec(dllexport) #else @@ -26,6 +26,6 @@ #define SPLOT2D_EXPORT #endif -#if defined WNT +#if defined WIN32 #pragma warning ( disable: 4251 ) #endif diff --git a/src/SPlot2d/SPlot2d_Prs.cxx b/src/SPlot2d/SPlot2d_Prs.cxx index 68739a0c6..e61efbc3f 100644 --- a/src/SPlot2d/SPlot2d_Prs.cxx +++ b/src/SPlot2d/SPlot2d_Prs.cxx @@ -21,7 +21,7 @@ // Module : SUIT #include "SPlot2d_Prs.h" -#ifndef WNT +#ifndef WIN32 using namespace std; #endif diff --git a/src/SUPERVGraph/SUPERVGraph.h b/src/SUPERVGraph/SUPERVGraph.h index eef17b998..22ca3c4fd 100755 --- a/src/SUPERVGraph/SUPERVGraph.h +++ b/src/SUPERVGraph/SUPERVGraph.h @@ -32,7 +32,7 @@ #include "SUIT_Desktop.h" #include "SUIT_ViewWindow.h" -#ifdef WNT +#ifdef WIN32 #ifdef SUPERVGRAPH_EXPORTS #define SUPERVGRAPH_EXPORT __declspec(dllexport) #else @@ -42,7 +42,7 @@ #define SUPERVGRAPH_EXPORT #endif -#if defined WNT +#if defined WIN32 #pragma warning ( disable: 4251 ) #endif diff --git a/src/SVTK/SVTK.h b/src/SVTK/SVTK.h index b07763c0b..970bd3889 100755 --- a/src/SVTK/SVTK.h +++ b/src/SVTK/SVTK.h @@ -21,7 +21,7 @@ #include "VTKViewer.h" -#ifdef WNT +#ifdef WIN32 # ifdef SVTK_EXPORTS # define SVTK_EXPORT __declspec(dllexport) # else @@ -31,7 +31,7 @@ # define SVTK_EXPORT #endif -#if defined WNT +#if defined WIN32 #pragma warning ( disable: 4251 ) #pragma warning ( disable: 4786 ) #endif diff --git a/src/SVTK/SVTK_CubeAxesActor2D.cxx b/src/SVTK/SVTK_CubeAxesActor2D.cxx index 823c07224..4f109801c 100644 --- a/src/SVTK/SVTK_CubeAxesActor2D.cxx +++ b/src/SVTK/SVTK_CubeAxesActor2D.cxx @@ -205,7 +205,7 @@ static void ChangeValues(vtkFloatingPointType* aArray1, for (int i=0; i<4; i++){ tmp = aArray1[i]; aArray1[i] = aArray2[i]; aArray2[i] = tmp; } -#ifndef WNT +#ifndef WIN32 for(int i=0;i<2; i++){ #else for(i=0;i<2; i++){ @@ -450,7 +450,7 @@ int SVTK_CubeAxesActor2D::RenderOpaqueGeometry(vtkViewport *viewport) // XCoords coordinates for X grid vtkFloatArray *XCoords = vtkFloatArray::New(); -#ifndef WNT +#ifndef WIN32 for(int i=0;iGetValue(numOfLabelsY-1); p[5][2] = aMiddleZ; -#ifndef WNT +#ifndef WIN32 for(int i=0;i<3;i++) #else for(i=0;i<3;i++) diff --git a/src/SVTK/SVTK_CubeAxesActor2D.h b/src/SVTK/SVTK_CubeAxesActor2D.h index 445f6d71e..0443f0b28 100644 --- a/src/SVTK/SVTK_CubeAxesActor2D.h +++ b/src/SVTK/SVTK_CubeAxesActor2D.h @@ -48,7 +48,7 @@ class VTKViewer_Transform; #pragma warning ( disable:4251 ) #endif -#ifndef WNT +#ifndef WIN32 class VTK_HYBRID_EXPORT SVTK_CubeAxesActor2D : public vtkCubeAxesActor2D #else class SVTK_EXPORT SVTK_CubeAxesActor2D : public vtkCubeAxesActor2D diff --git a/src/SVTK/SVTK_InteractorStyle.cxx b/src/SVTK/SVTK_InteractorStyle.cxx index 2746a24e6..bfaac1f2b 100644 --- a/src/SVTK/SVTK_InteractorStyle.cxx +++ b/src/SVTK/SVTK_InteractorStyle.cxx @@ -60,13 +60,9 @@ #include #include -//VRV: porting on Qt 3.0.5 -#if QT_VERSION >= 0x030005 #include -#endif -//VRV: porting on Qt 3.0.5 -#include +#include #include using namespace std; diff --git a/src/SVTK/SVTK_RenderWindowInteractor.cxx b/src/SVTK/SVTK_RenderWindowInteractor.cxx index 647fbc554..e473cdd69 100644 --- a/src/SVTK/SVTK_RenderWindowInteractor.cxx +++ b/src/SVTK/SVTK_RenderWindowInteractor.cxx @@ -75,7 +75,7 @@ QVTK_RenderWindowInteractor myRenderWindow->Delete(); myRenderWindow->DoubleBufferOn(); -#ifndef WNT +#ifndef WIN32 myRenderWindow->SetDisplayId((void*)x11Display()); #endif myRenderWindow->SetWindowId((void*)winId()); diff --git a/src/SalomeApp/SalomeApp.h b/src/SalomeApp/SalomeApp.h index 130299b08..7f6c74cef 100644 --- a/src/SalomeApp/SalomeApp.h +++ b/src/SalomeApp/SalomeApp.h @@ -28,7 +28,7 @@ // that uses this DLL. This way any other project whose source files include this file see // SalomeApp_API functions as being imported from a DLL, wheras this DLL sees symbols // defined with this macro as being exported. -#ifdef WNT +#ifdef WIN32 #ifdef SALOMEAPP_EXPORTS #define SALOMEAPP_EXPORT __declspec(dllexport) @@ -38,11 +38,11 @@ #else #define SALOMEAPP_EXPORT -#endif //WNT +#endif //WIN32 #define APP_VERSION "0.1" -#if defined WNT +#if defined WIN32 #pragma warning ( disable: 4251 ) #endif diff --git a/src/SalomeApp/SalomeApp_Application.cxx b/src/SalomeApp/SalomeApp_Application.cxx index 93f1e10aa..643aab333 100644 --- a/src/SalomeApp/SalomeApp_Application.cxx +++ b/src/SalomeApp/SalomeApp_Application.cxx @@ -414,7 +414,7 @@ void SalomeApp_Application::onLoadDoc() return; name = studyname; -#ifndef WNT +#ifndef WIN32 //this code replace marker of windows drive and path become invalid therefore // defines placed there name.replace( QRegExp(":"), "/" ); diff --git a/src/SalomeApp/SalomeApp_DataObject.cxx b/src/SalomeApp/SalomeApp_DataObject.cxx index dd9ff8960..1f1c6ae5a 100644 --- a/src/SalomeApp/SalomeApp_DataObject.cxx +++ b/src/SalomeApp/SalomeApp_DataObject.cxx @@ -129,7 +129,7 @@ QString SalomeApp_DataObject::text( const int id ) const switch ( id ) { case CT_Value: -#ifndef WNT +#ifndef WIN32 if ( componentObject() != this ) #else if ( componentObject() != (SUIT_DataObject*)this ) diff --git a/src/SalomeApp/SalomeApp_EventFilter.h b/src/SalomeApp/SalomeApp_EventFilter.h index e8849e231..8edb2102c 100755 --- a/src/SalomeApp/SalomeApp_EventFilter.h +++ b/src/SalomeApp/SalomeApp_EventFilter.h @@ -22,7 +22,7 @@ #include "SalomeApp.h" #include -#if defined WNT +#if defined WIN32 #pragma warning( disable: 4251 ) #endif @@ -50,7 +50,7 @@ private: static SalomeApp_EventFilter* myFilter; }; -#if defined WNT +#if defined WIN32 #pragma warning( default: 4251 ) #endif diff --git a/src/SalomeApp/SalomeApp_ExceptionHandler.cxx b/src/SalomeApp/SalomeApp_ExceptionHandler.cxx index 90de9c62d..9fd7d40c6 100644 --- a/src/SalomeApp/SalomeApp_ExceptionHandler.cxx +++ b/src/SalomeApp/SalomeApp_ExceptionHandler.cxx @@ -87,7 +87,7 @@ bool SalomeApp_ExceptionHandler::handle( QObject* o, QEvent* e ) { showMessage( title, QString( e.GetMessageString() ) ); } -#ifndef WNT +#ifndef WIN32 catch(...) { showMessage( title, "Unknown Exception" ); diff --git a/src/SalomeApp/SalomeApp_ImportOperation.cxx b/src/SalomeApp/SalomeApp_ImportOperation.cxx index 5d19bf6f0..5047ca732 100644 --- a/src/SalomeApp/SalomeApp_ImportOperation.cxx +++ b/src/SalomeApp/SalomeApp_ImportOperation.cxx @@ -29,7 +29,7 @@ #include "SalomeApp_ImportOperation.h" #include -#ifndef WNT +#ifndef WIN32 using namespace std; #endif diff --git a/src/SalomeApp/SalomeApp_ListView.h b/src/SalomeApp/SalomeApp_ListView.h index 3fa857bb0..ef6ebc99b 100644 --- a/src/SalomeApp/SalomeApp_ListView.h +++ b/src/SalomeApp/SalomeApp_ListView.h @@ -32,12 +32,7 @@ #include #include #include - -//VRV: porting on Qt 3.0.5 -#if QT_VERSION >= 0x030005 #include -#endif -//VRV: porting on Qt 3.0.5 #include #include diff --git a/src/SalomeApp/SalomeApp_PyInterp.cxx b/src/SalomeApp/SalomeApp_PyInterp.cxx index 67606feae..2f9e02040 100755 --- a/src/SalomeApp/SalomeApp_PyInterp.cxx +++ b/src/SalomeApp/SalomeApp_PyInterp.cxx @@ -44,7 +44,8 @@ using namespace std; * calls initialize method defined in base class, which calls virtual methods * initstate & initcontext redefined here. */ -SalomeApp_PyInterp::SalomeApp_PyInterp(): PythonConsole_PyInterp() +SalomeApp_PyInterp::SalomeApp_PyInterp(): + PythonConsole_PyInterp(), myFirstRun( true ) { } @@ -112,12 +113,31 @@ bool SalomeApp_PyInterp::initContext() Do nothing The initialization has been done in main */ -void SalomeApp_PyInterp::init_python() +void SalomeApp_PyInterp::initPython() { - MESSAGE("PyInterp_base::init_python"); + MESSAGE("PyInterp_base::initPython"); ASSERT(KERNEL_PYTHON::_gtstate); // initialisation in main SCRUTE(KERNEL_PYTHON::_gtstate); _gtstate=KERNEL_PYTHON::_gtstate; _interp=KERNEL_PYTHON::_interp; } +/*! + Called before each Python command running. +*/ +int SalomeApp_PyInterp::beforeRun() +{ + if ( myFirstRun ) { + myFirstRun = false; + int ret = simpleRun( "from Help import *", false ); + if ( ret ) + return ret; + ret = simpleRun( "import salome", false ); + if (ret) + return ret; + ret = simpleRun( "salome.salome_init(0,1)", false ); + if (ret) + return ret; + } + return true; +} diff --git a/src/SalomeApp/SalomeApp_PyInterp.h b/src/SalomeApp/SalomeApp_PyInterp.h index a0db6377f..c704482a4 100755 --- a/src/SalomeApp/SalomeApp_PyInterp.h +++ b/src/SalomeApp/SalomeApp_PyInterp.h @@ -37,10 +37,14 @@ public: SalomeApp_PyInterp(); virtual ~SalomeApp_PyInterp(); - virtual void init_python(); + virtual void initPython(); protected: virtual bool initContext(); + virtual bool beforeRun(); + +private: + bool myFirstRun; }; #endif diff --git a/src/Session/InquireServersQThread.cxx b/src/Session/InquireServersQThread.cxx index 61fdc3eff..b72253e1d 100755 --- a/src/Session/InquireServersQThread.cxx +++ b/src/Session/InquireServersQThread.cxx @@ -35,13 +35,7 @@ #include #include #include - -//VRV: porting on Qt 3.0.5 -#if QT_VERSION >= 0x030005 #include -#endif -//VRV: porting on Qt 3.0.5 - #include #include @@ -137,12 +131,7 @@ InquireServersGUI::InquireServersGUI() aHBoxLayout->addItem( new QSpacerItem( 0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum ) ); //Center widget -#if QT_VERSION >= 0x030005 QDesktopWidget *d = QApplication::desktop(); -#else - QWidget *d = QApplication::desktop(); -#endif -//VRV: porting on Qt 3.0.5 int w = d->width(); // returns desktop width int h = d->height(); // returns desktop height @@ -371,14 +360,14 @@ bool InquireServersQThread::AskServer(int iteration, QString ** errMessage) //will be set true if we get response from server bool IsPassed = false; QString errDescription; -#ifdef WNT +#ifdef WIN32 int i; #endif switch (iteration) { case 1: //First checking - existence of Naming Service -#ifndef WNT +#ifndef WIN32 for (int i = myRepeat; i ; i--) #else for (i = myRepeat; i ; i--) diff --git a/src/Session/SALOME_Session.hxx b/src/Session/SALOME_Session.hxx index 78c89d6d3..22bb8ffa2 100755 --- a/src/Session/SALOME_Session.hxx +++ b/src/Session/SALOME_Session.hxx @@ -26,22 +26,14 @@ #ifndef _SALOME_Session_HXX_ #define _SALOME_Session_HXX_ -#ifdef WNT - #if defined SESSION_EXPORTS - #if defined WIN32 - #define SESSION_EXPORT __declspec( dllexport ) - #else - #define SESSION_EXPORT - #endif - #else - #if defined WIN32 - #define SESSION_EXPORT __declspec( dllimport ) - #else - #define SESSION_EXPORT - #endif - #endif -#else - #define SESSION_EXPORT -#endif +#if defined WIN32 +# if defined SESSION_EXPORTS +# define SESSION_EXPORT __declspec( dllexport ) +# else +# define SESSION_EXPORT __declspec( dllimport ) +# endif +#else // WIN32 +# define SESSION_EXPORT +#endif // WIN32 -#endif \ No newline at end of file +#endif diff --git a/src/Session/SALOME_Session_Server.cxx b/src/Session/SALOME_Session_Server.cxx index 8ae6b7d2f..8520c96d2 100755 --- a/src/Session/SALOME_Session_Server.cxx +++ b/src/Session/SALOME_Session_Server.cxx @@ -32,7 +32,7 @@ #include "SALOMETraceCollector.hxx" #include -#ifndef WNT +#ifndef WIN32 #include #endif diff --git a/src/Session/Session_ServerThread.cxx b/src/Session/Session_ServerThread.cxx index 9c6f7c838..d5b5a6437 100755 --- a/src/Session/Session_ServerThread.cxx +++ b/src/Session/Session_ServerThread.cxx @@ -113,7 +113,7 @@ void Session_ServerThread::Init() MESSAGE("Session_ServerThread::Init "<< _argv[0]); for (int i=0; i<_argc; i++) SCRUTE(_argv[i]); -#ifndef WNT +#ifndef WIN32 for (int i=0; i # include -#ifndef WNT +#ifndef WIN32 using namespace std; #endif diff --git a/src/TOOLSGUI/ToolsGUI_RegWidget.h b/src/TOOLSGUI/ToolsGUI_RegWidget.h index be40bc8a2..c3c746e40 100755 --- a/src/TOOLSGUI/ToolsGUI_RegWidget.h +++ b/src/TOOLSGUI/ToolsGUI_RegWidget.h @@ -41,9 +41,7 @@ class QWidget; class QTimer; class QCloseEvent; class QTextView; -#if QT_VERSION > 300 class QPushButton; -#endif #include diff --git a/src/VTKViewer/VTKViewer.h b/src/VTKViewer/VTKViewer.h index 77de94830..c17912df9 100755 --- a/src/VTKViewer/VTKViewer.h +++ b/src/VTKViewer/VTKViewer.h @@ -20,7 +20,7 @@ #ifndef VTKVIEWER_H #define VTKVIEWER_H -#ifdef WNT +#ifdef WIN32 # ifdef VTKVIEWER_EXPORTS # define VTKVIEWER_EXPORT __declspec( dllexport ) # else diff --git a/src/VTKViewer/VTKViewer_ConvexTool.cxx b/src/VTKViewer/VTKViewer_ConvexTool.cxx index 1ecabea6e..9dfa3b47f 100644 --- a/src/VTKViewer/VTKViewer_ConvexTool.cxx +++ b/src/VTKViewer/VTKViewer_ConvexTool.cxx @@ -32,7 +32,7 @@ #include #include -#ifdef WNT +#ifdef WIN32 #include #endif diff --git a/src/VTKViewer/VTKViewer_InteractorStyle.cxx b/src/VTKViewer/VTKViewer_InteractorStyle.cxx index 6bc13e78e..04a02f180 100644 --- a/src/VTKViewer/VTKViewer_InteractorStyle.cxx +++ b/src/VTKViewer/VTKViewer_InteractorStyle.cxx @@ -51,11 +51,8 @@ #include #include -//VRV: porting on Qt 3.0.5 -#if QT_VERSION >= 0x030005 #include -#endif -//VRV: porting on Qt 3.0.5 + #include //#include "utilities.h" diff --git a/src/VTKViewer/VTKViewer_RenderWindow.cxx b/src/VTKViewer/VTKViewer_RenderWindow.cxx index 82bcf80ec..0ca9f7be7 100755 --- a/src/VTKViewer/VTKViewer_RenderWindow.cxx +++ b/src/VTKViewer/VTKViewer_RenderWindow.cxx @@ -20,6 +20,7 @@ #include #include +#include #include #include @@ -27,17 +28,13 @@ #include #include #include -#ifndef WNT +#ifndef WIN32 #include //#include //#include //#include #endif -#if QT_VERSION > 300 -#include -#endif - /*!Constructor. Create render window with parant \a parent and name \a name. *\param parent - parent window *\param name - render window name. @@ -48,7 +45,7 @@ QWidget(parent, name, Qt::WResizeNoErase | Qt::WRepaintNoErase) { myRW = vtkRenderWindow::New(); -#ifndef WNT +#ifndef WIN32 myRW->SetDisplayId((void*)x11Display()); #endif myRW->SetWindowId((void*)winId());