From 4b982d1ff3276521cbf4b95fd1b7483394845f44 Mon Sep 17 00:00:00 2001 From: san Date: Fri, 3 Jun 2005 11:01:49 +0000 Subject: [PATCH] exec() method added --- src/PythonConsole/PythonConsole_PyConsole.cxx | 8 ++- src/PythonConsole/PythonConsole_PyConsole.h | 2 + src/PythonConsole/PythonConsole_PyEditor.cxx | 56 +++++++++++-------- src/PythonConsole/PythonConsole_PyEditor.h | 4 +- 4 files changed, 44 insertions(+), 26 deletions(-) diff --git a/src/PythonConsole/PythonConsole_PyConsole.cxx b/src/PythonConsole/PythonConsole_PyConsole.cxx index 250ddff2a..fed5b9bd4 100755 --- a/src/PythonConsole/PythonConsole_PyConsole.cxx +++ b/src/PythonConsole/PythonConsole_PyConsole.cxx @@ -10,7 +10,7 @@ using namespace std; //**************************************************************** PythonConsole::PythonConsole(QWidget* parent, PyInterp_base* interp) -: QWidget(parent) +: QWidget(parent), myEditor( 0 ) { // create python interpreter myInterp = interp; @@ -31,3 +31,9 @@ PythonConsole::~PythonConsole() { } +//**************************************************************** +void PythonConsole::exec( const QString& command ) +{ + if ( myEditor ) + myEditor->exec( command ); +} diff --git a/src/PythonConsole/PythonConsole_PyConsole.h b/src/PythonConsole/PythonConsole_PyConsole.h index f18bc4023..a35d213c6 100755 --- a/src/PythonConsole/PythonConsole_PyConsole.h +++ b/src/PythonConsole/PythonConsole_PyConsole.h @@ -16,6 +16,8 @@ public: PyInterp_base* getInterp() { return myInterp; } + void exec( const QString& command ); + protected: PyInterp_base* myInterp; PythonConsole_PyEditor* myEditor; diff --git a/src/PythonConsole/PythonConsole_PyEditor.cxx b/src/PythonConsole/PythonConsole_PyEditor.cxx index da6b4df66..ba55b25ca 100755 --- a/src/PythonConsole/PythonConsole_PyEditor.cxx +++ b/src/PythonConsole/PythonConsole_PyEditor.cxx @@ -24,22 +24,31 @@ // File : PythonConsole_PyEditor.cxx // Author : Nicolas REJNERI // Module : SALOME +// $Header$ #include // this include must be first (see PyInterp_base.h)! - #include - #include +#include #include #include #include -#include +//#include "utilities.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 _currentPrompt.length() @@ -96,7 +105,6 @@ PythonConsole_PyEditor::PythonConsole_PyEditor(PyInterp_base* theInterp, QWidget QFont aFont = SUIT_Tools::stringToFont( fntSet ); setFont(aFont); setTextFormat(QTextEdit::PlainText); - setUndoRedoEnabled( false ); _currentPrompt = READY_PROMPT; setWordWrap(NoWrap); @@ -127,6 +135,25 @@ void PythonConsole_PyEditor::setText(QString s) 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() ) + return; + int para=paragraphs()-1; + removeParagraph( para ); + _currentPrompt = READY_PROMPT; + _buf.truncate(0); + _isInHistory = false; + setText(_currentPrompt); + setText( command + "\n" ); + handleReturn(); +} + /*! Called when an handleReturn */ @@ -280,6 +307,8 @@ void PythonConsole_PyEditor::keyPressEvent( QKeyEvent* e ) bool ctrlPressed = e->state() & ControlButton; // check if is pressed bool shftPressed = e->state() & ShiftButton; + // check if is pressed + bool altPressed = e->state() & AltButton; // process + key-bindings if ( aKey == Key_C && ctrlPressed ) { @@ -672,22 +701,3 @@ void PythonConsole_PyEditor::onPyInterpChanged( PyInterp_base* interp ) } } } - -QPopupMenu* PythonConsole_PyEditor::createPopupMenu( const QPoint& pos ) -{ - QPopupMenu* popup = QTextEdit::createPopupMenu( pos ); - - QValueList ids; - for ( int i = 0; popup && i < popup->count(); i++ ) - { - if ( !popup->isItemEnabled( popup->idAt( i ) ) ) - ids.append( popup->idAt( i ) ); - } - - for ( QValueList::const_iterator it = ids.begin(); it != ids.end(); ++it ) - popup->removeItem( *it ); - - SUIT_Tools::simplifySeparators( popup ); - - return popup; -} diff --git a/src/PythonConsole/PythonConsole_PyEditor.h b/src/PythonConsole/PythonConsole_PyEditor.h index 5fab9f0a7..821fdec87 100755 --- a/src/PythonConsole/PythonConsole_PyEditor.h +++ b/src/PythonConsole/PythonConsole_PyEditor.h @@ -46,6 +46,8 @@ public: virtual void setText(QString s); bool isCommand(const QString& str) const; + + virtual void exec( const QString& command ); protected: virtual void contentsDropEvent( QDropEvent* event ); @@ -57,8 +59,6 @@ protected: public slots: void handleReturn(); void onPyInterpChanged( PyInterp_base* ); - - virtual QPopupMenu* createPopupMenu( const QPoint& ); private: QString _buf; -- 2.39.2