]> SALOME platform Git repositories - modules/gui.git/commitdiff
Salome HOME
exec() method added
authorsan <san@opencascade.com>
Fri, 3 Jun 2005 11:01:49 +0000 (11:01 +0000)
committersan <san@opencascade.com>
Fri, 3 Jun 2005 11:01:49 +0000 (11:01 +0000)
src/PythonConsole/PythonConsole_PyConsole.cxx
src/PythonConsole/PythonConsole_PyConsole.h
src/PythonConsole/PythonConsole_PyEditor.cxx
src/PythonConsole/PythonConsole_PyEditor.h

index 250ddff2adf5e7a09d7206090d19026847729788..fed5b9bd47ca71d58f166147ab8e511c554dcd68 100755 (executable)
@@ -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 );
+}
index f18bc40239ffb999738f394c0cae685d16bb8b9b..a35d213c67c8eb7c630ce9465aa868e2f2f8f235 100755 (executable)
@@ -16,6 +16,8 @@ public:
 
   PyInterp_base* getInterp() { return myInterp; } 
 
+  void           exec( const QString& command );
+
 protected:
   PyInterp_base*          myInterp;
   PythonConsole_PyEditor* myEditor;
index da6b4df6605303b0c7035c9e4427b514894b803d..ba55b25ca3e2ad99d427102bfa77edc6c6e72f59 100755 (executable)
 //  File   : PythonConsole_PyEditor.cxx
 //  Author : Nicolas REJNERI
 //  Module : SALOME
+//  $Header$
 
 #include <PythonConsole_PyEditor.h> // this include must be first (see PyInterp_base.h)!
-
 #include <PyInterp_Dispatcher.h>
-
 #include <SUIT_Tools.h>
 
+#include <qapplication.h>
 #include <qmap.h>
 #include <qclipboard.h>
 #include <qdragobject.h>
-#include <qapplication.h>
 
+//#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 <Shift> is pressed
   bool shftPressed = e->state() & ShiftButton;
+  // check if <Alt> is pressed
+  bool altPressed = e->state() & AltButton;
 
   // process <Ctrl>+<C> 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<int> ids;
-  for ( int i = 0; popup && i < popup->count(); i++ )
-  {
-    if ( !popup->isItemEnabled( popup->idAt( 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 );
-
-  return popup;
-}
index 5fab9f0a7f88a67ae45f7fc553c78f173efc40f3..821fdec8752ee218884d4236e130b63776764cf4 100755 (executable)
@@ -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;