X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2FPythonConsole%2FPythonConsole_PyEditor.cxx;h=73b9c7904d2592a89fad329c6c124afaf3cae956;hb=1e121ed2fda87a3fbf0c4a9b9ff04983bbf8f8da;hp=cbb4627f79e708eff7c4140a5191b3760d855998;hpb=773cc3efce8987710d8501fafc95d4d795b3949d;p=modules%2Fgui.git diff --git a/src/PythonConsole/PythonConsole_PyEditor.cxx b/src/PythonConsole/PythonConsole_PyEditor.cxx index cbb4627f7..73b9c7904 100755 --- a/src/PythonConsole/PythonConsole_PyEditor.cxx +++ b/src/PythonConsole/PythonConsole_PyEditor.cxx @@ -38,8 +38,16 @@ 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() @@ -95,7 +103,7 @@ PythonConsole_PyEditor::PythonConsole_PyEditor(PyInterp_base* theInterp, QWidget QString fntSet( "" ); QFont aFont = SUIT_Tools::stringToFont( fntSet ); setFont(aFont); - setTextFormat(QTextEdit::PlainText); + //setTextFormat(QTextEdit::PlainText); setUndoRedoEnabled( false ); _currentPrompt = READY_PROMPT; @@ -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( "\n" + _currentPrompt); + setText( command + "\n" ); + handleReturn(); +} + /*! Called when an handleReturn */ @@ -677,13 +704,23 @@ 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 ) ) ) - popup->removeItemAt( i ); + ids.append( popup->idAt( i ) ); } + for ( QValueList::const_iterator it = ids.begin(); it != ids.end(); ++it ) + popup->removeItem( *it ); + SUIT_Tools::simplifySeparators( popup ); + if ( !popup->count() ) + { + delete popup; + popup = 0; + } + return popup; }