#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
#define true 1
#endif
-#if defined WNT
+#if defined WIN32
#pragma warning ( disable: 4251 )
#endif
class CAF_Application;
-#if defined WNT
+#if defined WIN32
#pragma warning ( disable: 4251 )
#endif
friend class CAF_Operation;
};
-#if defined WNT
+#if defined WIN32
#pragma warning ( default: 4251 )
#endif
#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
#define true 1
#endif
-#if defined WNT
+#if defined WIN32
#pragma warning ( disable: 4251 )
#endif
// 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)
#else
#define EVENT_EXPORT
-#endif //WNT
+#endif //WIN32
#define APP_VERSION "0.1"
-#if defined WNT
+#if defined WIN32
#pragma warning ( disable: 4251 )
#endif
// Created: November, 2004
//! Macro for exports
-#ifdef WNT
+#ifdef WIN32
#ifdef GLVIEWER_EXPORTS
#define GLVIEWER_API __declspec(dllexport)
#else
#define GLVIEWER_API
-#endif // WNT
+#endif // WIN32
#include <qcolor.h>
-#ifdef WNT
+#ifdef WIN32
#pragma warning( disable:4251 )
#endif
int myLineType;
};
-#ifdef WNT
+#ifdef WIN32
#pragma warning ( default:4251 )
#endif
class GLViewer_AspectLine;
-#ifdef WNT
+#ifdef WIN32
#pragma warning( disable:4251 )
#endif
void updateObjects();
};
-#ifdef WNT
+#ifdef WIN32
#pragma warning ( default:4251 )
#endif
#include <TColStd_SequenceOfInteger.hxx>
-#ifdef WNT
+#ifdef WIN32
#pragma warning( disable:4251 )
#endif
int myHeight;
};
-#ifdef WNT
+#ifdef WIN32
#pragma warning ( default:4251 )
#endif
#include <qcolor.h>
-#ifdef WNT
+#ifdef WIN32
#pragma warning( disable:4251 )
#endif
bool isGenereted;
};
-#ifdef WNT
+#ifdef WIN32
#pragma warning ( default:4251 )
#endif
#ifndef GLVIEWER_CONTEXT_H
#define GLVIEWER_CONTEXT_H
-#ifdef WNT
+#ifdef WIN32
#include "windows.h"
#endif
class GLViewer_Viewer2d;
-#ifdef WNT
+#ifdef WIN32
#pragma warning( disable:4251 )
#endif
int myTolerance;
};
-#ifdef WNT
+#ifdef WIN32
#pragma warning ( default:4251 )
#endif
#include "GLViewer.h"
-#ifdef WNT
+#ifdef WIN32
#pragma warning( disable:4251 )
#endif
virtual void fromReference( double& x, double& y );
};
-#ifdef WNT
+#ifdef WIN32
#pragma warning ( default:4251 )
#endif
#ifndef GLVIEWER_DRAWER_H
#define GLVIEWER_DRAWER_H
-#ifdef WNT
+#ifdef WIN32
#include "windows.h"
#endif
class GLViewer_Rect;
class GLViewer_CoordSystem;
-#ifdef WNT
+#ifdef WIN32
#pragma warning( disable:4251 )
#endif
/*!
GLfloat myTextScale;
};
-#ifdef WNT
+#ifdef WIN32
#pragma warning ( default:4251 )
#endif
#include <math.h>
-#ifdef WNT
+#ifdef WIN32
#pragma warning( disable:4251 )
#endif
GLViewer_PntList* myPoints;
};
-#ifdef WNT
+#ifdef WIN32
#pragma warning ( default:4251 )
#endif
#ifndef GLVIEWER_GRID_H
#define GLVIEWER_GRID_H
-#ifdef WNT
+#ifdef WIN32
#include "windows.h"
#endif
#include <GL/gl.h>
#include <GL/glu.h>
-#ifdef WNT
+#ifdef WIN32
#pragma warning( disable:4251 )
#endif
GLboolean myIsUpdate;
};
-#ifdef WNT
+#ifdef WIN32
#pragma warning ( default:4251 )
#endif
#include <list>
#include "GLViewer.h"
-#ifdef WNT
+#ifdef WIN32
#pragma warning( disable:4251 )
#endif
#ifndef GLVIEWER_MIMESOURCE_H
#define GLVIEWER_MIMESOURCE_H
-#ifdef WNT
+#ifdef WIN32
#include <windows.h>
#endif
#include <qmime.h>
#include <qvaluelist.h>
-#ifdef WNT
+#ifdef WIN32
#pragma warning( disable:4251 )
#endif
QByteArray myByteArray;
};
-#ifdef WNT
+#ifdef WIN32
#pragma warning ( default:4251 )
#endif
#ifndef GLVIEWER_OBJECT_H
#define GLVIEWER_OBJECT_H
-#ifdef WNT
+#ifdef WIN32
#include <windows.h>
#endif
#include <qstring.h>
#include <qrect.h>
-#ifdef WNT
+#ifdef WIN32
#pragma warning( disable:4251 )
#endif
GLViewer_Group* myGroup;
};
-#ifdef WNT
+#ifdef WIN32
#pragma warning ( default:4251 )
#endif
#ifndef GLVIEWER_SELECTOR2D_H
#define GLVIEWER_SELECTOR2D_H
-#ifdef WNT
+#ifdef WIN32
#include "windows.h"
#endif
#ifndef GLVIEWER_TEXT_H
#define GLVIEWER_TEXT_H
-#ifdef WNT
+#ifdef WIN32
#include <windows.h>
#endif
#include <qcolor.h>
#include <qfontmetrics.h>
-#ifdef WNT
+#ifdef WIN32
#pragma warning( disable:4251 )
#endif
DisplayTextFormat myDTF;
};
-#ifdef WNT
+#ifdef WIN32
#pragma warning ( default:4251 )
#endif
#ifndef GLVIEWER_TOOLS_H
#define GLVIEWER_TOOLS_H
-#ifdef WNT
+#ifdef WIN32
#include "windows.h"
#endif
imageBits = new unsigned char[imageSize];
-#ifdef WNT
+#ifdef WIN32
int num;
HBITMAP hBmp;
aFileName += ".png";
aSaveOp = "PNG";
-//#ifdef WNT
+//#ifdef WIN32
// if( !anImage.save( aFileName, aSaveOp ) )
//#else
if( !aWidget->grabFrameBuffer().save( aFileName, aSaveOp ) )
#include <qaction.h>
-#ifdef WNT
+#ifdef WIN32
#pragma warning( disable:4251 )
#endif
};
-#ifdef WNT
+#ifdef WIN32
#pragma warning ( default:4251 )
#endif
//#include <GLViewerAfx.h>
-#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"
#include <stdlib.h>
-#if !defined WNT
+#if !defined WIN32
#include <GL/glx.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
*/
void GLViewer_ViewPort::selectVisualId( ViewType type )
{
-#if !defined WNT
+#if !defined WIN32
XVisualInfo* pVisualInfo;
if ( x11Display() )
{
class GLViewer_ViewSketcher;
class GLViewer_ViewTransformer;
-#ifdef WNT
+#ifdef WIN32
#pragma warning( disable:4251 )
#endif
static QCursor* sketchCursor;
};
-#ifdef WNT
+#ifdef WIN32
#pragma warning ( default:4251 )
#endif
#ifndef GLVIEWER_VIEWPORT2D_H
#define GLVIEWER_VIEWPORT2D_H
-#ifdef WNT
+#ifdef WIN32
#include <windows.h>
#endif
#include <qwidget.h>
#include <qpaintdevice.h>
-#ifdef WNT
+#ifdef WIN32
#pragma warning( disable:4251 )
#endif
bool myIsMouseReleaseBlock;
};
-#ifdef WNT
+#ifdef WIN32
#pragma warning ( default:4251 )
#endif
class SUIT_Desktop;
class SUIT_ViewWindow;
-#ifdef WNT
+#ifdef WIN32
#pragma warning( disable:4251 )
#endif
int myButtonState;
};
-#ifdef WNT
+#ifdef WIN32
#pragma warning ( default:4251 )
#endif
#ifndef GLVIEWER_VIEWER2D_H
#define GLVIEWER_VIEWER2D_H
-#ifdef WNT
+#ifdef WIN32
#include <windows.h>
#endif
/* A5 */ 148.5, 210.0
};
-#ifdef WNT
+#ifdef WIN32
#pragma warning( disable:4251 )
#endif
static int rotateBtn;
};
-#ifdef WNT
+#ifdef WIN32
#pragma warning ( default:4251 )
#endif
// 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)
#else
#define LIGHTAPP_EXPORT
-#endif //WNT
+#endif //WIN32
#define APP_VERSION "0.1"
aCurrentPos += aBufferSize[i];
}
-#ifdef WNT
+#ifdef WIN32
ofstream aFile(theFileName, ios::out | ios::binary);
#else
ofstream aFile(theFileName);
*/
bool LightApp_Driver::ReadDatasFromFile( const char* theFileName, bool isMultiFile )
{
-#ifdef WNT
+#ifdef WIN32
ifstream aFile(theFileName, ios::binary);
#else
ifstream aFile(theFileName);
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());
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());
TCollection_AsciiString aFullPath = aTmpDir + aFileName;
-#ifdef WNT
+#ifdef WIN32
ofstream aFile(aFullPath.ToCString(), ios::out | ios::binary);
#else
ofstream aFile(aFullPath.ToCString());
#include <qobject.h>
-#if defined WNT
+#if defined WIN32
#pragma warning( disable: 4251 )
#endif
static LightApp_EventFilter* myFilter;
};
-#if defined WNT
+#if defined WIN32
#pragma warning( default: 4251 )
#endif
}
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 );
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 )
{
//
// 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
#define OCCVIEWER_EXPORT
#endif
-#if defined WNT
+#if defined WIN32
#pragma warning ( disable: 4251 )
#endif
#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
#define true 1
#endif
-#if defined WNT
+#if defined WIN32
#pragma warning ( disable: 4251 )
#endif
#include <SUIT_DataObjectKey.h>
#include <SUIT_PopupClient.h>
-#ifdef WNT
+#ifdef WIN32
#pragma warning( disable:4251 )
#endif
#include <iostream>
using namespace std;
-#ifdef WNT
+#ifdef WIN32
#define min(a, b) (((a) < (b)) ? (a) : (b))
#endif
*/
OB_CheckListItem::OB_CheckListItem( SUIT_DataObject* obj, QListView* parent, QListViewItem* after, Type type )
: ListItemF<QCheckListItem>( this, obj),
-#if defined(QT_VERSION) && QT_VERSION >= 0x030101
QCheckListItem( parent, after, "", type )
-#else
- QCheckListItem( parent, "", type )
-#endif
{
update();
}
*/
OB_CheckListItem::OB_CheckListItem( SUIT_DataObject* obj, QListViewItem* parent, QListViewItem* after, Type type )
: ListItemF<QCheckListItem>( this, obj),
-#if defined(QT_VERSION) && QT_VERSION >= 0x030101
QCheckListItem( parent, after, "", type )
-#else
- QCheckListItem( parent, "", type )
-#endif
{
update();
}
//
// 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
#define PLOT2D_EXPORT
#endif
-#if defined WNT
+#if defined WIN32
#pragma warning ( disable: 4251 )
#endif
#include <qgroupbox.h>
#include <qcolordialog.h>
-#ifndef WNT
+#ifndef WIN32
using namespace std;
#endif
#ifndef SALOME_PRS_H
#define SALOME_PRS_H
-#ifdef WNT
+#ifdef WIN32
#ifdef PRS_EXPORTS
#define PRS_EXPORT __declspec(dllexport)
#else
--- /dev/null
+# 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
--- /dev/null
+// 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
--- /dev/null
+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
--- /dev/null
+// 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 <Qtx.h>
+
+#include <QAction>
+#include <QApplication>
+#include <QClipboard>
+#include <QEvent>
+#include <QMenu>
+#include <QVBoxLayout>
+
+/*!
+ \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() );
+}
--- /dev/null
+// 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 <SUIT_PopupClient.h>
+#include <QFrame>
+#include <QMap>
+
+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<int, QAction*> myActions; //!< menu actions list
+};
+
+#endif // PYCONSOLE_CONSOLE_H
--- /dev/null
+// 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:
+ - <Enter> : execute current command
+ - <Ctrl><Break> : clear current command
+ - <Escape> : clear current command
+ - <Up> : previous command in the history
+ - <Shift><Up> : move cursor one row up with selection
+ - <Ctrl><Up> : move cursor one row up without selection
+ - <Ctrl><Shift><Up> : move cursor one row up with selection
+ - <Down> : next command in the history
+ - <Shift><Down> : move cursor one row down with selection
+ - <Ctrl><Down> : move cursor one row down without selection
+ - <Ctrl><Shift><Down> : move cursor one row down with selection
+ - <Left> : move one symbol left without selection
+ - <Shift><Left> : move one symbol left with selection
+ - <Ctrl><Left> : move one word left without selection
+ - <Ctrl><Shift><Left> : move one word left with selection
+ - <Right> : move one symbol right without selection
+ - <Shift><Right> : move one symbol right with selection
+ - <Ctrl><Right> : move one word right without selection
+ - <Ctrl><Shift><Right> : move one word right with selection
+ - <PgUp> : first command in the history
+ - <Shift><PgUp> : move one page up with selection
+ - <Ctrl><PgUp> : move one page up without selection
+ - <Ctrl><Shift><PgUp> : scroll one page up
+ - <PgDn> : last command in the history
+ - <Shift><PgDn> : move one page down with selection
+ - <Ctrl><PgDn> : move one page down without selection
+ - <Ctrl><Shift><PgDn> : scroll one page down
+ - <Home> : move to the beginning of the line without selection
+ - <Shift><Home> : move to the beginning of the line with selection
+ - <Ctrl><Home> : move to the very first symbol without selection
+ - <Ctrl><Shift><Home> : move to the very first symbol with selection
+ - <End> : move to the end of the line without selection
+ - <Shift><End> : move to the end of the line with selection
+ - <Ctrl><End> : move to the very last symbol without selection
+ - <Ctrl><Shift><End> : move to the very last symbol with selection
+ - <Backspace> : delete symbol before the cursor
+ / remove selected text and put it to the clipboard (cut)
+ - <Shift><Backspace> : delete previous word
+ / remove selected text and put it to the clipboard (cut)
+ - <Ctrl><Backspace> : delete text from the cursor to the beginning of the line
+ / remove selected text and put it to the clipboard (cut)
+ - <Delete> : delete symbol after the cursor
+ / remove selected text and put it to the clipboard (cut)
+ - <Shift><Delete> : delete next word
+ / remove selected text and put it to the clipboard (cut)
+ - <Ctrl><Delete> : delete text from the cursor to the end of the line
+ / remove selected text and put it to the clipboard (cut)
+ - <Ctrl><Insert> : copy
+ - <Shift><Insert> : paste
+ - <Ctrl><V> : paste
+ - <Ctrl><C> : copy
+ - <Ctrl><X> : cut
+ - <Ctrl><V> : 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 <PyInterp_Dispatcher.h>
+
+#include <SUIT_Tools.h>
+
+#include <QApplication>
+#include <QClipboard>
+#include <QDropEvent>
+#include <QEvent>
+#include <QKeyEvent>
+#include <QMouseEvent>
+#include <QScrollBar>
+#include <QTextBlock>
+#include <QTextCursor>
+#include <QTextDocument>
+
+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 <Ctrl> is pressed
+ bool ctrlPressed = event->modifiers() & Qt::ControlModifier;
+ // check if <Shift> is pressed
+ bool shftPressed = event->modifiers() & Qt::ShiftModifier;
+
+ if ( aKey == Qt::Key_Escape || ctrlPressed && aKey == -1 ) {
+ // process <Ctrl>+<Break> key-binding and <Escape> 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 <Ctrl>+<C> key-binding : copy
+ copy();
+ return;
+ }
+ else if ( ctrlPressed && aKey == Qt::Key_X ) {
+ // process <Ctrl>+<X> key-binding : cut
+ cut();
+ return;
+ }
+ else if ( ctrlPressed && aKey == Qt::Key_V ) {
+ // process <Ctrl>+<V> 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:
+ // <Enter> key: process the current command
+ {
+ handleReturn();
+ break;
+ }
+ case Qt::Key_Up:
+ // <Up> arrow key: process as follows:
+ // - without <Ctrl>, <Shift> modifiers: previous command in history
+ // - with <Ctrl> modifier key pressed: move cursor one row up without selection
+ // - with <Shift> modifier key pressed: move cursor one row up with selection
+ // - with <Ctrl>+<Shift> 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:
+ // <Down> arrow key: process as follows:
+ // - without <Ctrl>, <Shift> modifiers: next command in history
+ // - with <Ctrl> modifier key pressed: move cursor one row down without selection
+ // - with <Shift> modifier key pressed: move cursor one row down with selection
+ // - with <Ctrl>+<Shift> 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:
+ // <Left> arrow key: process as follows:
+ // - without <Ctrl>, <Shift> modifiers: move one symbol left (taking into account prompt)
+ // - with <Ctrl> modifier key pressed: move one word left (taking into account prompt)
+ // - with <Shift> modifier key pressed: move one symbol left with selection
+ // - with <Ctrl>+<Shift> 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:
+ // <Right> arrow key: process as follows:
+ // - without <Ctrl>, <Shift> modifiers: move one symbol right (taking into account prompt)
+ // - with <Ctrl> modifier key pressed: move one word right (taking into account prompt)
+ // - with <Shift> modifier key pressed: move one symbol right with selection
+ // - with <Ctrl>+<Shift> 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:
+ // <PageUp> key: process as follows:
+ // - without <Ctrl>, <Shift> modifiers: first command in history
+ // - with <Ctrl> modifier key pressed: move cursor one page up without selection
+ // - with <Shift> modifier key pressed: move cursor one page up with selection
+ // - with <Ctrl>+<Shift> 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:
+ // <PageDown> key: process as follows:
+ // - without <Ctrl>, <Shift> modifiers: last command in history
+ // - with <Ctrl> modifier key pressed: move cursor one page down without selection
+ // - with <Shift> modifier key pressed: move cursor one page down with selection
+ // - with <Ctrl>+<Shift> 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:
+ // <Home> key: process as follows:
+ // - without <Ctrl>, <Shift> modifiers: move cursor to the beginning of the current line without selection
+ // - with <Ctrl> modifier key pressed: move cursor to the very first symbol without selection
+ // - with <Shift> modifier key pressed: move cursor to the beginning of the current line with selection
+ // - with <Ctrl>+<Shift> 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:
+ // <End> key: process as follows:
+ // - without <Ctrl>, <Shift> modifiers: move cursor to the end of the current line without selection
+ // - with <Ctrl> modifier key pressed: move cursor to the very last symbol without selection
+ // - with <Shift> modifier key pressed: move cursor to the end of the current line with selection
+ // - with <Ctrl>+<Shift> 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 :
+ // <Backspace> key: process as follows
+ // - without any modifiers : delete symbol before the cursor / selection (taking into account prompt)
+ // - with <Shift> modifier key pressed: delete previous word
+ // - with <Ctrl> 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 :
+ // <Delete> key: process as follows
+ // - without any modifiers : delete symbol after the cursor / selection (taking into account prompt)
+ // - with <Shift> modifier key pressed: delete next word
+ // - with <Ctrl> 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 :
+ // <Insert> key: process as follows
+ // - with <Ctrl> modifier key pressed: copy()
+ // - with <Shift> 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<PyInterp_Event*>( event );
+ if ( pe )
+ {
+ ExecCommand* ec = dynamic_cast<ExecCommand*>( 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 );
+}
--- /dev/null
+// 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 <QTextEdit>
+
+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
--- /dev/null
+// 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.
+
+ <b>But</b> 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.
+
+ <b>But</b> 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;
+}
--- /dev/null
+// 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 <PyInterp_Interp.h> /// !!! 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
--- /dev/null
+<?xml version="1.0" encoding="utf-8"?>
+<!DOCTYPE TS><TS version="1.1">
+<context>
+ <name>PythonConsole</name>
+ <message>
+ <location filename="PyConsole_Editor.cxx" line="411"/>
+ <source>EDIT_COPY_CMD</source>
+ <translation>Copy</translation>
+ </message>
+ <message>
+ <location filename="PyConsole_Editor.cxx" line="415"/>
+ <source>EDIT_PASTE_CMD</source>
+ <translation>Paste</translation>
+ </message>
+ <message>
+ <location filename="PyConsole_Editor.cxx" line="419"/>
+ <source>EDIT_CLEAR_CMD</source>
+ <translation>Clear</translation>
+ </message>
+ <message>
+ <location filename="PyConsole_Editor.cxx" line="425"/>
+ <source>EDIT_SELECTALL_CMD</source>
+ <translation>Select All</translation>
+ </message>
+</context>
+</TS>
+++ /dev/null
-# 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)
-
-
+++ /dev/null
-// 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 <Python.h>
-
-#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
+++ /dev/null
-// 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 <Python.h>
-#include "PythonConsole_PyConsole.h"
-#include "PythonConsole_PyEditor.h"
-#include "PyInterp_base.h"
-
-#include "SUIT_Desktop.h"
-
-#include <qlayout.h>
-
-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;
-}
+++ /dev/null
-// 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 <qwidget.h>
-
-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
+++ /dev/null
-// 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 <PythonConsole_PyEditor.h> // this include must be first (see PyInterp_base.h)!
-
-#include <PyInterp_Dispatcher.h>
-
-#include <SUIT_Tools.h>
-#include <SUIT_Session.h>
-
-#include <qmap.h>
-#include <qclipboard.h>
-#include <qdragobject.h>
-#include <qapplication.h>
-#include <qpopupmenu.h>
-
-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 = "<<getInterp()<<"; myCommand = '"<<myCommand.latin1()<<"' - "<<ret);
- 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();
-// 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<int, int> 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 <Ctrl> is pressed
- bool ctrlPressed = e->state() & ControlButton;
- // check if <Shift> is pressed
- bool shftPressed = e->state() & ShiftButton;
-
- // process <Ctrl>+<C> 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:
- // <Enter> key
- {
- moveCursor( QTextEdit::MoveEnd, false );
- QTextEdit::keyPressEvent( e );
- break;
- }
- case Key_Up:
- // <Up> arrow key: process as follows:
- // - without <Ctrl>, <Shift> modifiers: previous command in history
- // - with <Ctrl> modifier key pressed: move cursor one row up without selection
- // - with <Shift> modifier key pressed: move cursor one row up with selection
- // - with <Ctrl>+<Shift> 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:
- // <Down> arrow key: process as follows:
- // - without <Ctrl>, <Shift> modifiers: next command in history
- // - with <Ctrl> modifier key pressed: move cursor one row down without selection
- // - with <Shift> modifier key pressed: move cursor one row down with selection
- // - with <Ctrl>+<Shift> 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:
- // <Left> arrow key: process as follows:
- // - without <Ctrl>, <Shift> modifiers: move one symbol left (taking into account prompt)
- // - with <Ctrl> modifier key pressed: move one word left (taking into account prompt)
- // - with <Shift> modifier key pressed: move one symbol left with selection
- // - with <Ctrl>+<Shift> 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:
- // <Right> arrow key: process as follows:
- // - without <Ctrl>, <Shift> modifiers: move one symbol right (taking into account prompt)
- // - with <Ctrl> modifier key pressed: move one word right (taking into account prompt)
- // - with <Shift> modifier key pressed: move one symbol right with selection
- // - with <Ctrl>+<Shift> 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:
- // <PageUp> key: process as follows:
- // - without <Ctrl>, <Shift> modifiers: first command in history
- // - with <Ctrl> modifier key pressed: move cursor one page up without selection
- // - with <Shift> modifier key pressed: move cursor one page up with selection
- // - with <Ctrl>+<Shift> 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:
- // <PageDown> key: process as follows:
- // - without <Ctrl>, <Shift> modifiers: last command in history
- // - with <Ctrl> modifier key pressed: move cursor one page down without selection
- // - with <Shift> modifier key pressed: move cursor one page down with selection
- // - with <Ctrl>+<Shift> 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:
- // <Home> key: process as follows:
- // - without <Ctrl>, <Shift> modifiers: move cursor to the beginning of the current line without selection
- // - with <Ctrl> modifier key pressed: move cursor to the very first symbol without selection
- // - with <Shift> modifier key pressed: move cursor to the beginning of the current line with selection
- // - with <Ctrl>+<Shift> 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:
- // <End> key: process as follows:
- // - without <Ctrl>, <Shift> modifiers: move cursor to the end of the current line without selection
- // - with <Ctrl> modifier key pressed: move cursor to the very last symbol without selection
- // - with <Shift> modifier key pressed: move cursor to the end of the current line with selection
- // - with <Ctrl>+<Shift> 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 :
- // <Backspace> key: process as follows
- // - without any modifiers : delete symbol before the cursor / selection (taking into account prompt)
- // - with <Ctrl> 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 :
- // <Delete> key: process as follows
- // - without any modifiers : delete symbol after the cursor / selection (taking into account prompt)
- // - with <Ctrl> 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 :
- // <Insert> key: process as follows
- // - with <Ctrl> modifier key pressed: copy()
- // - with <Shift> 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<PyInterp_Event*>( e );
- if ( pe ){
- ExecCommand* ec = dynamic_cast<ExecCommand*>( 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<int> ids;
- for ( int i = 0; popup && i < (int)popup->count(); i++ )
- {
- if ( !popup->isItemEnabled( popup->idAt( i ) ) )
- ids.append( popup->idAt( i ) );
- }
-
- for ( QValueList<int>::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;
-}
+++ /dev/null
-// 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 <qevent.h>
-#include <qtextedit.h>
-
-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
+++ /dev/null
-// 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 = "<<this<<"; _tstate = "<<_tstate);
- }
-
- /*
- * 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);
-// SCRUTE(builtinmodule->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<<"; _g = "<<_g);
-
- if(builtinmodule){
- PyDict_SetItemString(_g, "__builtins__", builtinmodule); // assign singleton __builtin__ module
- }
- return true;
-}
+++ /dev/null
-// 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.h
-// Author : Nicolas REJNERI
-// Module : SALOME
-// $Header$
-
-#ifndef _PythonConsole_PYINTERP_H_
-#define _PythonConsole_PYINTERP_H_
-
-#include "PythonConsole.h"
-
-#include <PyInterp_base.h> // 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
#include <QtxComboBox.h>
-#ifdef WNT
+#ifdef WIN32
#pragma warning( disable:4251 )
#endif
QStringList myUserNames;
};
-#ifdef WNT
+#ifdef WIN32
#pragma warning( default:4251 )
#endif
#include <qpixmap.h>
#include <qstringlist.h>
-#ifdef WNT
+#ifdef WIN32
#pragma warning( disable:4251 )
#endif
QStringList myUserNames;
};
-#ifdef WNT
+#ifdef WIN32
#pragma warning( default:4251 )
#endif
# include <qpushbutton.h>
# include <qspinbox.h>
-#ifndef WNT
+#ifndef WIN32
using namespace std;
#endif
QString addSlash( const QString& path )
{
if (!path.isNull()) {
-#ifdef WNT
+#ifdef WIN32
QChar slash ('\\');
#else
QChar slash ('/');
class QTimer;
class QCloseEvent;
class QTextView;
-#if QT_VERSION > 300
class QPushButton;
-#endif
class HelpWindow;
class InfoWindow;
// ========================================================
// set dllexport type for Win platform
-#ifdef WNT
+#ifdef WIN32
#ifdef SALOME_PYQT_EXPORTS
#define SALOME_PYQT_EXPORT __declspec(dllexport)
#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
//
// 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
#define SOCC_EXPORT
#endif
-#if defined WNT
+#if defined WIN32
#pragma warning ( disable: 4251 )
#endif
//
// 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
#define SPLOT2D_EXPORT
#endif
-#if defined WNT
+#if defined WIN32
#pragma warning ( disable: 4251 )
#endif
// Module : SUIT
#include "SPlot2d_Prs.h"
-#ifndef WNT
+#ifndef WIN32
using namespace std;
#endif
#include "SUIT_Desktop.h"
#include "SUIT_ViewWindow.h"
-#ifdef WNT
+#ifdef WIN32
#ifdef SUPERVGRAPH_EXPORTS
#define SUPERVGRAPH_EXPORT __declspec(dllexport)
#else
#define SUPERVGRAPH_EXPORT
#endif
-#if defined WNT
+#if defined WIN32
#pragma warning ( disable: 4251 )
#endif
#include "VTKViewer.h"
-#ifdef WNT
+#ifdef WIN32
# ifdef SVTK_EXPORTS
# define SVTK_EXPORT __declspec(dllexport)
# else
# define SVTK_EXPORT
#endif
-#if defined WNT
+#if defined WIN32
#pragma warning ( disable: 4251 )
#pragma warning ( disable: 4786 )
#endif
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++){
// XCoords coordinates for X grid
vtkFloatArray *XCoords = vtkFloatArray::New();
-#ifndef WNT
+#ifndef WIN32
for(int i=0;i<numOfLabelsX;i++){
#else
for(i=0;i<numOfLabelsX;i++){
}
// YCoords coordinates for Y grid
vtkFloatArray *YCoords = vtkFloatArray::New();
-#ifndef WNT
+#ifndef WIN32
for(int i=0;i<numOfLabelsX;i++){
#else
for(i=0;i<numOfLabelsX;i++){
}
// ZCoords coordinates for Z grid
vtkFloatArray *ZCoords = vtkFloatArray::New();
-#ifndef WNT
+#ifndef WIN32
for(int i=0;i<numOfLabelsZ;i++){
#else
for(i=0;i<numOfLabelsZ;i++){
p[5][1] = YCoords->GetValue(numOfLabelsY-1);
p[5][2] = aMiddleZ;
-#ifndef WNT
+#ifndef WIN32
for(int i=0;i<3;i++)
#else
for(i=0;i<3;i++)
#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
#include <qapplication.h>
#include <qpixmap.h>
-//VRV: porting on Qt 3.0.5
-#if QT_VERSION >= 0x030005
#include <qpainter.h>
-#endif
-//VRV: porting on Qt 3.0.5
-#include <algorithm>
+#include <algorithm>
#include <iostream>
using namespace std;
myRenderWindow->Delete();
myRenderWindow->DoubleBufferOn();
-#ifndef WNT
+#ifndef WIN32
myRenderWindow->SetDisplayId((void*)x11Display());
#endif
myRenderWindow->SetWindowId((void*)winId());
// 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)
#else
#define SALOMEAPP_EXPORT
-#endif //WNT
+#endif //WIN32
#define APP_VERSION "0.1"
-#if defined WNT
+#if defined WIN32
#pragma warning ( disable: 4251 )
#endif
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(":"), "/" );
switch ( id )
{
case CT_Value:
-#ifndef WNT
+#ifndef WIN32
if ( componentObject() != this )
#else
if ( componentObject() != (SUIT_DataObject*)this )
#include "SalomeApp.h"
#include <qobject.h>
-#if defined WNT
+#if defined WIN32
#pragma warning( disable: 4251 )
#endif
static SalomeApp_EventFilter* myFilter;
};
-#if defined WNT
+#if defined WIN32
#pragma warning( default: 4251 )
#endif
{
showMessage( title, QString( e.GetMessageString() ) );
}
-#ifndef WNT
+#ifndef WIN32
catch(...)
{
showMessage( title, "Unknown Exception" );
#include "SalomeApp_ImportOperation.h"
#include <SUIT_Application.h>
-#ifndef WNT
+#ifndef WIN32
using namespace std;
#endif
#include <qpixmap.h>
#include <qlineedit.h>
#include <qcombobox.h>
-
-//VRV: porting on Qt 3.0.5
-#if QT_VERSION >= 0x030005
#include <qtoolbutton.h>
-#endif
-//VRV: porting on Qt 3.0.5
#include <TColStd_ListOfInteger.hxx>
#include <TColStd_ListOfReal.hxx>
* 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 )
{
}
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;
+}
SalomeApp_PyInterp();
virtual ~SalomeApp_PyInterp();
- virtual void init_python();
+ virtual void initPython();
protected:
virtual bool initContext();
+ virtual bool beforeRun();
+
+private:
+ bool myFirstRun;
};
#endif
#include <qstringlist.h>
#include <qlabel.h>
#include <qprogressbar.h>
-
-//VRV: porting on Qt 3.0.5
-#if QT_VERSION >= 0x030005
#include <qdesktopwidget.h>
-#endif
-//VRV: porting on Qt 3.0.5
-
#include <qsize.h>
#include <SALOMEconfig.h>
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
//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--)
#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
#include "SALOMETraceCollector.hxx"
#include <iostream>
-#ifndef WNT
+#ifndef WIN32
#include <unistd.h>
#endif
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<NB_SRV_TYP; i++)
#else
for (i=0; i<NB_SRV_TYP; i++)
# include <qpushbutton.h>
# include <qspinbox.h>
-#ifndef WNT
+#ifndef WIN32
using namespace std;
#endif
class QTimer;
class QCloseEvent;
class QTextView;
-#if QT_VERSION > 300
class QPushButton;
-#endif
#include <Standard_Macro.hxx>
#ifndef VTKVIEWER_H
#define VTKVIEWER_H
-#ifdef WNT
+#ifdef WIN32
# ifdef VTKVIEWER_EXPORTS
# define VTKVIEWER_EXPORT __declspec( dllexport )
# else
#include <set>
#include <map>
-#ifdef WNT
+#ifdef WIN32
#include <algorithm>
#endif
#include <vtkProperty.h>
#include <qapplication.h>
-//VRV: porting on Qt 3.0.5
-#if QT_VERSION >= 0x030005
#include <qpainter.h>
-#endif
-//VRV: porting on Qt 3.0.5
+
#include <algorithm>
//#include "utilities.h"
#include <qcolordialog.h>
#include <qpopupmenu.h>
+#include <qcursor.h>
#include <stdlib.h>
#include <math.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkRendererCollection.h>
#include <vtkCamera.h>
-#ifndef WNT
+#ifndef WIN32
#include <vtkXOpenGLRenderWindow.h>
//#include <GL/gl.h>
//#include <GL/glu.h>
//#include <qgl.h>
#endif
-#if QT_VERSION > 300
-#include <qcursor.h>
-#endif
-
/*!Constructor. Create render window with parant \a parent and name \a name.
*\param parent - parent window
*\param name - render window name.
Qt::WResizeNoErase | Qt::WRepaintNoErase)
{
myRW = vtkRenderWindow::New();
-#ifndef WNT
+#ifndef WIN32
myRW->SetDisplayId((void*)x11Display());
#endif
myRW->SetWindowId((void*)winId());