Salome HOME
Merge remote branch 'origin/Doc_update_ver741' into V7_5_BR
[modules/gui.git] / src / PyConsole / PyConsole_Console.cxx
old mode 100755 (executable)
new mode 100644 (file)
index a14eca1..5ec6eb5
 PyConsole_Console::PyConsole_Console( QWidget* parent, PyConsole_Interp* interp )
 : 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))
   {
@@ -78,8 +75,8 @@ PyConsole_Console::PyConsole_Console( QWidget* parent, PyConsole_Interp* interp
 /**
  * Protected constructor.
  */
-PyConsole_Console::PyConsole_Console( QWidget* parent, PyConsole_Interp* i,  PyConsole_Editor* e)
-  : QWidget (parent), myEditor(e), myInterp(i)
+PyConsole_Console::PyConsole_Console( QWidget* parent, PyConsole_Interp* /*i*/,  PyConsole_Editor* e )
+  : QWidget (parent), myEditor(e)
 {}
 
 /*!
@@ -91,6 +88,11 @@ PyConsole_Console::~PyConsole_Console()
 {
 }
 
+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
@@ -248,6 +250,10 @@ void PyConsole_Console::contextMenuPopup( QMenu* menu )
   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 );
 
@@ -269,6 +275,8 @@ void PyConsole_Console::setMenuActions( const int flags )
   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 );
 }
 
 /*!
@@ -284,6 +292,8 @@ int PyConsole_Console::menuActions() const
   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;
 }
 
@@ -318,6 +328,16 @@ void PyConsole_Console::createActions()
   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 );
 }
 
 /*!
@@ -332,27 +352,41 @@ void PyConsole_Console::updateActions()
   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_EnhInterp* interp)
-  : PyConsole_Console(parent, interp, 0)
+PyConsole_EnhConsole::PyConsole_EnhConsole( QWidget* parent, PyConsole_Interp* interp )
+  : PyConsole_Console( parent, interp, 0 )
 {
-  // create python interpreter
-  myInterp = interp;
-  if ( !myInterp )
-    myInterp = new PyConsole_EnhInterp();
+  PyConsole_Interp* anInterp = interp ? interp : new PyConsole_EnhInterp();
 
   // initialize Python interpretator
-  myInterp->initialize();
+  anInterp->initialize();
 
   // create editor console
   QVBoxLayout* lay = new QVBoxLayout( this );
   lay->setMargin( 0 );
-  myEditor = new PyConsole_EnhEditor( static_cast<PyConsole_EnhInterp*>(myInterp), this );
+  myEditor = new PyConsole_EnhEditor( anInterp, this );
   char* synchronous = getenv("PYTHON_CONSOLE_SYNC");
   if (synchronous && atoi(synchronous))
   {