]> SALOME platform Git repositories - modules/gui.git/blob - tools/PyConsole/src/PyConsole_Editor.h
Salome HOME
774e101af0c46b767ffd3430056945003b875a17
[modules/gui.git] / tools / PyConsole / src / PyConsole_Editor.h
1 // Copyright (C) 2007-2016  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
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.
10 //
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.
15 //
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
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 // File   : PyConsole_Editor.h
23 // Author : Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com)
24
25 #ifndef PYCONSOLE_EDITOR_H
26 #define PYCONSOLE_EDITOR_H
27
28 #include "PyConsole.h"
29
30 #include <QTextEdit>
31 #include <QQueue>
32
33 class PyConsole_Interp;
34 class PyInterp_Request;
35 class QEventLoop;
36
37 class PYCONSOLE_EXPORT PyConsole_Editor : public QTextEdit
38 {
39   Q_OBJECT;
40
41 public:
42   PyConsole_Editor( PyConsole_Interp*, QWidget* = 0 );
43   ~PyConsole_Editor();
44
45   PyConsole_Interp* getInterp() const;
46   
47   virtual void   addText( const QString&, const bool = false, const bool = false );
48   bool           isCommand( const QString& ) const;
49
50   virtual void   exec( const QString& );
51   void           execAndWait( const QString& );
52
53   bool           isSync() const;
54   void           setIsSync( const bool );
55
56   bool           isSuppressOutput() const;
57   void           setIsSuppressOutput( const bool );
58
59   bool           isShowBanner() const;
60   void           setIsShowBanner( const bool );
61
62   void           setAutoCompletion( bool );
63   bool           autoCompletion() const;
64
65   bool           isLogging() const;
66
67   virtual QSize  sizeHint() const;
68
69   bool           startLog( const QString& );
70   bool           dump( const QString& );
71
72 signals:
73   void updateDoc( const QString& );
74
75 public slots:
76   void           cut();
77   void           paste();
78   void           clear();
79   void           dump();
80   void           startLog();
81   void           stopLog();
82
83 protected:
84   virtual void   dropEvent( QDropEvent* );
85   virtual void   mousePressEvent( QMouseEvent* );
86   virtual void   mouseReleaseEvent( QMouseEvent* );
87   virtual void   keyPressEvent ( QKeyEvent* );
88   virtual void   customEvent( QEvent* );
89
90   virtual void   insertFromMimeData( const QMimeData* );
91
92   void           putLog( const QString& );
93
94   virtual QString getDumpFileName();
95   virtual QString getLogFileName();
96
97 private:
98   void           multilinePaste( const QString& );
99   void           multiLineProcessNextLine();
100
101   void           handleReturn();
102   void           handleTab();
103   void           handleBackTab();
104   void           clearCompletion();
105   QString        formatCompletion( const QStringList& ) const;
106   QString        formatDocHTML( const QString& ) const;
107   QString        extractCommon( const QStringList& ) const;
108
109   PyInterp_Request* createCmdRequest( const QString& );
110   PyInterp_Request* createTabRequest( const QString& );
111
112   QString        banner() const;
113   inline int     promptSize() const { return myPrompt.size(); }
114
115   PyConsole_Interp* myInterp;           //!< python interpreter
116   QString           myCommandBuffer;    //!< python command buffer
117   QString           myCurrentCommand;   //!< currently being printed command
118   QString           myPrompt;           //!< current command line prompt
119   int               myCmdInHistory;     //!< current history command index
120   QString           myLogFile;          //!< current output log
121   QStringList       myHistory;          //!< commands history buffer
122   QEventLoop*       myEventLoop;        //!< internal event loop
123   bool              myShowBanner;       //!< 'show banner' flag
124   QStringList       myQueue;            //!< python commands queue
125   bool              myIsSync;           //!< synchronous mode flag
126   bool              myIsSuppressOutput; //!< suppress output flag
127   bool              myMultiLinePaste;   //!< true when pasting several lines
128   QQueue<QString>   myMultiLineContent; //!< queue of lines being pasted
129   bool              myAutoCompletion;   //!< auto-completion mode flag
130   bool              myTabMode;          //!< flag that is \c true when editor performs completion
131   QString           myComplBeforePoint; //!< string on which the dir() command is executed
132   QString           myComplAfterPoint;  //!< string on which the results of the dir() are matched
133   int               myComplCursorPos;   //!< cursor position when <TAB> is hit
134
135 };
136
137 #endif // PYCONSOLE_EDITOR_H