1 // Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // File : PyConsole_Editor.h
23 // Author : Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com)
25 #ifndef PYCONSOLE_EDITOR_H
26 #define PYCONSOLE_EDITOR_H
28 #include "PyConsole.h"
30 #include "PyInterp_RefCounterObj.h"
35 class PyConsole_Interp;
36 class PyInterp_Request;
39 class PYCONSOLE_EXPORT PyConsole_Editor : public QTextEdit
44 PyConsole_Editor( QWidget* = 0 );
45 PyConsole_Editor( QWidget*, PyConsole_Interp* );
48 PyConsole_Interp* getInterp() const;
50 virtual void addText( const QString&, const bool = false, const bool = false );
51 bool isCommand( const QString& ) const;
53 virtual void exec( const QString& );
54 void execAndWait( const QString& );
57 void setIsSync( const bool );
59 bool isSuppressOutput() const;
60 void setIsSuppressOutput( const bool );
62 bool isShowBanner() const;
63 void setIsShowBanner( const bool );
65 void setAutoCompletion( bool );
66 bool autoCompletion() const;
68 bool isLogging() const;
70 virtual QSize sizeHint() const;
72 bool startLog( const QString& );
73 bool dump( const QString& );
76 void updateDoc( const QString& );
87 virtual void dropEvent( QDropEvent* );
88 virtual void mousePressEvent( QMouseEvent* );
89 virtual void mouseReleaseEvent( QMouseEvent* );
90 virtual void keyPressEvent ( QKeyEvent* );
91 virtual void customEvent( QEvent* );
93 virtual void insertFromMimeData( const QMimeData* );
95 void putLog( const QString& );
97 virtual QString getDumpFileName();
98 virtual QString getLogFileName();
103 void multilinePaste( const QString& );
104 void multiLineProcessNextLine();
108 void handleBackTab();
109 void clearCompletion();
110 QString formatCompletion( const QStringList& ) const;
111 QString formatDocHTML( const QString& ) const;
112 QString extractCommon( const QStringList& ) const;
114 PyInterp_Request* createCmdRequest( const QString& );
115 PyInterp_Request* createTabRequest( const QString& );
117 QString banner() const;
118 inline int promptSize() const { return myPrompt.size(); }
120 PyInterp_Auto<PyConsole_Interp> myInterp; //!< python interpreter
121 QString myCommandBuffer; //!< python command buffer
122 QString myCurrentCommand; //!< currently being printed command
123 QString myPrompt; //!< current command line prompt
124 int myCmdInHistory; //!< current history command index
125 QString myLogFile; //!< current output log
126 QStringList myHistory; //!< commands history buffer
127 QEventLoop* myEventLoop; //!< internal event loop
128 bool myShowBanner; //!< 'show banner' flag
129 QStringList myQueue; //!< python commands queue
130 bool myIsSync; //!< synchronous mode flag
131 bool myIsSuppressOutput; //!< suppress output flag
132 bool myMultiLinePaste; //!< true when pasting several lines
133 QQueue<QString> myMultiLineContent; //!< queue of lines being pasted
134 bool myAutoCompletion; //!< auto-completion mode flag
135 bool myTabMode; //!< flag that is \c true when editor performs completion
136 QString myComplBeforePoint; //!< string on which the dir() command is executed
137 QString myComplAfterPoint; //!< string on which the results of the dir() are matched
138 int myComplCursorPos; //!< cursor position when <TAB> is hit
140 friend void PyConsole_CallbackStdout( void*, char* );
141 friend void PyConsole_CallbackStderr( void*, char* );
144 #endif // PYCONSOLE_EDITOR_H