-// Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2014 CEA/DEN, EDF R&D, OPEN CASCADE
//
// Copyright (C) 2003-2007 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.
+// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
#include "PyConsole_Interp.h" /// !!! WARNING !!! THIS INCLUDE MUST BE VERY FIRST !!!
#include "PyConsole_Console.h"
-#include "PyConsole_Editor.h"
+#include "PyConsole_EnhEditor.h"
+#include "PyConsole_EnhInterp.h"
#include <Qtx.h>
\param interp python interpreter
*/
PyConsole_Console::PyConsole_Console( QWidget* parent, PyConsole_Interp* interp )
-: QWidget( parent ),
- myEditor( 0 )
+: QWidget( parent )
{
- // create python interpreter
- myInterp = interp;
- if ( !myInterp )
- myInterp = new PyConsole_Interp();
+ PyConsole_Interp* anInterp = interp ? interp : new PyConsole_Interp();
// initialize Python interpretator
- myInterp->initialize();
+ anInterp->initialize();
// create editor console
QVBoxLayout* lay = new QVBoxLayout( this );
lay->setMargin( 0 );
- myEditor = new PyConsole_Editor( myInterp, this );
+ myEditor = new PyConsole_Editor( anInterp, this );
char* synchronous = getenv("PYTHON_CONSOLE_SYNC");
if (synchronous && atoi(synchronous))
{
createActions();
}
+/**
+ * Protected constructor.
+ */
+PyConsole_Console::PyConsole_Console( QWidget* parent, PyConsole_Interp* /*i*/, PyConsole_Editor* e )
+ : QWidget (parent), myEditor(e)
+{}
+
/*!
\brief Destructor.
{
}
+PyConsole_Interp* PyConsole_Console::getInterp() const
+{
+ return myEditor ? myEditor->getInterp() : 0;
+}
+
/*!
\brief Execute python command in the interpreter.
\param command string with command and arguments
menu->addAction( myActions[SelectAllId] );
menu->addSeparator();
menu->addAction( myActions[DumpCommandsId] );
+ if ( !myEditor->isLogging() )
+ menu->addAction( myActions[StartLogId] );
+ else
+ menu->addAction( myActions[StopLogId] );
Qtx::simplifySeparators( menu );
myActions[ClearId]->setVisible( flags & ClearId );
myActions[SelectAllId]->setVisible( flags & SelectAllId );
myActions[DumpCommandsId]->setVisible( flags & DumpCommandsId );
+ myActions[StartLogId]->setVisible( flags & StartLogId );
+ myActions[StopLogId]->setVisible( flags & StopLogId );
}
/*!
ret = ret | ( myActions[ClearId]->isVisible() ? ClearId : 0 );
ret = ret | ( myActions[SelectAllId]->isVisible() ? SelectAllId : 0 );
ret = ret | ( myActions[DumpCommandsId]->isVisible() ? DumpCommandsId : 0 );
+ ret = ret | ( myActions[StartLogId]->isVisible() ? StartLogId : 0 );
+ ret = ret | ( myActions[StopLogId]->isVisible() ? StopLogId : 0 );
return ret;
}
a->setStatusTip( tr( "EDIT_DUMPCOMMANDS_CMD" ) );
connect( a, SIGNAL( triggered( bool ) ), myEditor, SLOT( dump() ) );
myActions.insert( DumpCommandsId, a );
+
+ a = new QAction( tr( "EDIT_STARTLOG_CMD" ), this );
+ a->setStatusTip( tr( "EDIT_STARTLOG_CMD" ) );
+ connect( a, SIGNAL( triggered( bool ) ), myEditor, SLOT( startLog() ) );
+ myActions.insert( StartLogId, a );
+
+ a = new QAction( tr( "EDIT_STOPLOG_CMD" ), this );
+ a->setStatusTip( tr( "EDIT_STOPLOG_CMD" ) );
+ connect( a, SIGNAL( triggered( bool ) ), myEditor, SLOT( stopLog() ) );
+ myActions.insert( StopLogId, a );
}
/*!
myActions[PasteId]->setEnabled( !myEditor->isReadOnly() && !QApplication::clipboard()->text().isEmpty() );
myActions[SelectAllId]->setEnabled( !myEditor->document()->isEmpty() );
}
+
+/*!
+ \brief Start python trace logging
+ \param fileName the path to the log file
+*/
+void PyConsole_Console::startLog( const QString& fileName )
+{
+ myEditor->startLog( fileName );
+}
+
+/*!
+ \brief Stop python trace logging
+*/
+void PyConsole_Console::stopLog()
+{
+ myEditor->stopLog();
+}
+
+/**
+ * Similar to constructor of the base class but using enhanced objects.
+ * TODO: this should really be done in a factory to avoid code duplication.
+ * @param parent
+ * @param interp
+ */
+PyConsole_EnhConsole::PyConsole_EnhConsole( QWidget* parent, PyConsole_Interp* interp )
+ : PyConsole_Console( parent, interp, 0 )
+{
+ PyConsole_Interp* anInterp = interp ? interp : new PyConsole_EnhInterp();
+
+ // initialize Python interpretator
+ anInterp->initialize();
+
+ // create editor console
+ QVBoxLayout* lay = new QVBoxLayout( this );
+ lay->setMargin( 0 );
+ myEditor = new PyConsole_EnhEditor( anInterp, this );
+ char* synchronous = getenv("PYTHON_CONSOLE_SYNC");
+ if (synchronous && atoi(synchronous))
+ {
+ myEditor->setIsSync(true);
+ }
+ myEditor->viewport()->installEventFilter( this );
+ lay->addWidget( myEditor );
+
+ createActions();
+}