#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 _currentPrompt.length()
class ExecCommand : public PyInterp_LockRequest
{
public:
- ExecCommand(PyInterp_base* theInterp, const char* theCommand, PythonConsole_PyEditor* theListener)
-: PyInterp_LockRequest( theInterp, theListener ), myCommand(theCommand), myState( PyInterp_Event::OK )
+ 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:
QString fntSet( "" );
QFont aFont = SUIT_Tools::stringToFont( fntSet );
setFont(aFont);
- setTextFormat(QTextEdit::PlainText);
+ //setTextFormat(QTextEdit::PlainText);
setUndoRedoEnabled( false );
_currentPrompt = READY_PROMPT;
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
*/
{
QPopupMenu* popup = QTextEdit::createPopupMenu( pos );
+ QValueList<int> 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<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;
}