Synchronisation with phimeca sources.
// ========================================================
// set dllexport type for Win platform
-#ifdef WIN32
+#if !defined(PYCONSOLE_STATIC) && defined(_WIN32)
# if defined PYCONSOLE_EXPORTS || defined PyConsole_EXPORTS
# define PYCONSOLE_EXPORT __declspec(dllexport)
# else
// create editor console
QVBoxLayout* lay = new QVBoxLayout( this );
- lay->setMargin( 0 );
+ lay->setContentsMargins( 0, 0, 0 ,0 );
myEditor = editor ? editor : new PyConsole_Editor( this, interp );
myEditor->setContextMenuPolicy( Qt::NoContextMenu );
lay->addWidget( myEditor );
Creates python editor window.
\param parent parent widget
- \param interp python interper
+ \param interp python interpreter
*/
PyConsole_Editor::PyConsole_Editor( QWidget* parent,
PyConsole_Interp* interp )
setWordWrapMode( QTextOption::WrapAnywhere );
setAcceptRichText( false );
- // set callbacks to interpeter
+ // set callbacks to interpreter
myInterp->setvoutcb( PyConsole_CallbackStdout, this );
myInterp->setverrcb( PyConsole_CallbackStderr, this );
// print banner
{
if ( isReadOnly() ) {
// some interactive command is being executed in this editor...
- // shedule the command to the queue
+ // schedule the command to the queue
myQueue.push_back( command );
return;
}
void PyConsole_Editor::dropEvent( QDropEvent* event )
{
// get the initial drop position
+#if QT_VERSION >= 0x060000
+ QPoint pos = event->position().toPoint();
+#else
QPoint pos = event->pos();
- QTextCursor aCursor = cursorForPosition( event->pos() );
+#endif
+ QTextCursor aCursor = cursorForPosition( pos );
// if the position is not in the last line move it to the end of the command line
if ( aCursor.position() < document()->end().previous().position() + promptSize() ) {
QDropEvent de( pos,
event->possibleActions(),
event->mimeData(),
+#if QT_VERSION >= 0x060000
+ event->buttons(),
+ event->modifiers(),
+#else
event->mouseButtons(),
event->keyboardModifiers(),
+#endif
event->type() );
QTextEdit::dropEvent( &de );
if ( event->button() == Qt::LeftButton ) {
QTextEdit::mouseReleaseEvent( event );
}
- else if ( event->button() == Qt::MidButton ) {
+ else if ( event->button() == Qt::MiddleButton ) {
QTextCursor aCursor = cursorForPosition( event->pos() );
// if the position is not in the last line move it to the end of the command line
if ( aCursor.position() < document()->end().previous().position() + promptSize() ) {
if ( (int)event->type() == (int)PyInterp_Event::ES_OK && myQueue.count() > 0 )
{
- // process the next sheduled command from the queue (if there is any)
+ // process the next scheduled command from the queue (if there is any)
QString nextcmd = myQueue[0];
myQueue.pop_front();
exec( nextcmd );
if ( file.open( QFile::WriteOnly ) ) {
QTextStream out( &file );
for ( int i = 0; i < myHistory.count(); i++ ) {
-#if QT_VERSION >= QT_VERSION_CHECK(5,15,0)
+#if QT_VERSION >= QT_VERSION_CHECK(5,14,0)
out << myHistory[i] << Qt::endl;
#else
out << myHistory[i] << endl;
class PYCONSOLE_EXPORT PyConsole_Editor : public QTextEdit
{
- Q_OBJECT
+ Q_OBJECT;
public:
PyConsole_Editor( QWidget* = 0 );
// Author : Nicolas REJNERI (OPEN CASCADE), Adrien BRUNETON (CEA/DEN), Vadim SANDLER (OPEN CASCADE)
#include "PyConsole_Interp.h"
+#include <QRegularExpression>
/*!
\class PyConsole_Interp
\internal
\param dirArgument Python expression to pass to the dir command. The parsing of what the
user actually started typing is dedicated to the caller
- \param startMatch string representing the begining of the patter to be completed. For example, when
+ \param startMatch string representing the beginning of the pattern to be completed. For example, when
the user types "a_string_variable.rsp <TAB>", this is "rsp".
\param[out] matches resulting list of matches
\param[out] docString resulting docstring of single match
QStringList& result,
bool discardSwig ) const
{
- QRegExp re( "^[A-Z].+_[A-Z]+[a-z]+.+$" ); // REX to discard SWIG static method, e.g. MEDCouplingUMesh_Blabla
+ QRegularExpression re( "^[A-Z].+_[A-Z]+[a-z]+.+$" ); // REX to discard SWIG static method, e.g. MEDCouplingUMesh_Blabla
// Execute dir() command
QString command( "dir(" + dirArgument + ")" );
// if the method is not from swig, not static (guessed from the reg exp) and matches
// what is already there
if ( s.startsWith( startMatch ) ) {
- if ( !discardSwig || ( !re.exactMatch( s ) && !s.contains( "swig" ) ) )
+ if ( !discardSwig || ( !re.match( s ).hasMatch() && !s.contains( "swig" ) ) )
result.append( s );
}
Py_DECREF( it );
void PyConsole_ExecCommand::execute()
{
if ( myCommand != "" ) {
- int ret = getInterp()->run( myCommand.toUtf8().data() );
+ int ret = getInterp()->run(myCommand.toUtf8());
if ( ret < 0 )
myState = PyInterp_Event::ES_ERROR;
else if ( ret > 0 )
private:
QString myDirArg; //!< String to be passed to the dir() comman
- QString myStartMatch; //!< Begining of the command (as typed by the user)
+ QString myStartMatch; //!< Beginning of the command (as typed by the user)
bool myStatus; //!< Status of completion command execution
QStringList myMatches; //!< Matches
QString myDoc; //!< Docstring of single match
// ========================================================
// set dllexport type for Win platform
-#ifdef WIN32
+#if !defined(PYINTERP_STATIC) && defined(_WIN32)
# if defined PYINTERP_EXPORTS || defined PyInterp_EXPORTS
# define PYINTERP_EXPORT __declspec(dllexport)
# else
#include <sstream>
#include <algorithm>
-#include <QRegExp>
+#include <QRegularExpression>
#include <QStringList>
#define TOP_HISTORY_PY "--- top of history ---"
\brief Basic constructor.
After construction the interpreter instance successor classes
- must call virtual method initalize().
+ must call virtual method initialize().
*/
PyInterp_Interp::PyInterp_Interp():
_vout(0), _verr(0), _global_context(0), _local_context(0), _initialized(false)
/*!
\brief Initialize embedded interpreter.
- This method shoud be called after construction of the interpreter.
+ This method should be called after construction of the interpreter.
The method initialize() calls virtuals methods
- initPython() to initialize global Python interpreter
- initContext() to initialize interpreter internal context
/*!
\brief Compile Python command and evaluate it in the
python dictionary contexts if possible. This is not thread-safe.
- This is the caller's responsability to make this thread-safe.
+ This is the caller's responsibility to make this thread-safe.
\internal
\param command Python command string
\return -1 on fatal error, 1 if command is incomplete and 0
QString singleCommand = command;
QString commandArgs = "";
- QRegExp rx("exec\\s*\\(.*open\\s*\\(\\s*(.*)\\s*\\)\\s*\\.\\s*read\\s*\\(\\)(\\s*,\\s*args\\s*=\\s*\\(.*\\))\\s*\\)");
- if (rx.indexIn(command) != -1) {
- commandArgs = rx.cap(2).remove(0, rx.cap(2).indexOf("(")); // arguments of command
- commandArgs.insert(commandArgs.indexOf('(')+1, rx.cap(1).split(",")[0].trimmed() + ","); // prepend arguments list by the script file itself
- singleCommand = singleCommand.remove(rx.pos(2), rx.cap(2).size()); // command for execution without arguments
+ QRegularExpression rx("exec\\s*\\(.*open\\s*\\(\\s*(.*)\\s*\\)\\s*\\.\\s*read\\s*\\(\\)(\\s*,\\s*args\\s*=\\s*\\(.*\\))\\s*\\)");
+ QRegularExpressionMatch match = rx.match(command);
+ if (match.hasMatch()) {
+ commandArgs = match.captured(2).remove(0, match.captured(2).indexOf("(")); // arguments of command
+ commandArgs.insert(commandArgs.indexOf('(')+1, match.captured(1).split(",")[0].trimmed() + ","); // prepend arguments list by the script file itself
+ singleCommand = singleCommand.remove(match.capturedStart(2), match.captured(2).size()); // command for execution without arguments
}
if (commandArgs.isEmpty()) {
}
/**
- * Called before a command is run (when calling run() method). Not thread-safe. Caller's responsability
+ * Called before a command is run (when calling run() method). Not thread-safe. Caller's responsibility
* to acquire GIL if needed.
*/
int PyInterp_Interp::beforeRun()
}
/**
- * Called after a command is run (when calling run() method). Not thread-safe. Caller's responsability
+ * Called after a command is run (when calling run() method). Not thread-safe. Caller's responsibility
* to acquire GIL if needed.
*/
int PyInterp_Interp::afterRun()
}
/*!
- \brief Run Python command (used internally). Not thread-safe. GIL acquisition is caller's responsability.
+ \brief Run Python command (used internally). Not thread-safe. GIL acquisition is caller's responsibility.
\param command Python command
\param addToHistory if \c true (default), the command is added to the commands history
\return command status
* Utility class wrapping the Python GIL acquisition. This makes use of the high level
* API (PyGILState_Ensure and PyGILState_Release), and is hence compatible with only
* one running Python interpreter (no call to Py_NewInterpreter()).
- * When the class is instanciated the lock is acquired. It is released at destruction time.
+ * When the class is instantiated the lock is acquired. It is released at destruction time.
* Copy construction (and hence assignation) is forbidden.
*/
class PYINTERP_EXPORT PyLockWrapper