Salome HOME
Python console added to the application
[modules/shaper.git] / src / PyConsole / PyConsole_Editor.h
1
2 #ifndef PYCONSOLE_EDITOR_H
3 #define PYCONSOLE_EDITOR_H
4
5 #include "PyConsole.h"
6
7 #include <QTextEdit>
8
9 class PyConsole_Interp;
10 class PyInterp_Request;
11 class QEventLoop;
12
13 class PYCONSOLE_EXPORT PyConsole_Editor : public QTextEdit
14 {
15   Q_OBJECT;
16
17 public:
18   PyConsole_Editor( PyConsole_Interp* theInterp, QWidget *theParent = 0 );
19   ~PyConsole_Editor();
20   
21   virtual void   addText( const QString& str, const bool newBlock = false, const bool isError = false );
22   bool           isCommand( const QString& str ) const;
23
24   virtual void   exec( const QString& command );
25   void           execAndWait( const QString& command );
26
27   bool           isSync() const;
28   void           setIsSync( const bool );
29
30   bool           isSuppressOutput() const;
31   void           setIsSuppressOutput(const bool);
32
33   bool           isShowBanner() const;
34   void           setIsShowBanner( const bool );
35
36   virtual QSize  sizeHint() const;
37
38 public slots:
39     void           cut();
40     void           paste();
41     void           clear();
42     void           handleReturn();
43     void           onPyInterpChanged( PyConsole_Interp* );
44     //.void           dump();
45
46 protected:
47   virtual void   dropEvent( QDropEvent* event );
48   virtual void   mouseReleaseEvent( QMouseEvent* event );
49   virtual void   keyPressEvent ( QKeyEvent* event);
50   virtual void   customEvent( QEvent* event);
51
52   virtual PyInterp_Request* createRequest( const QString& );
53
54   /** Convenience function */
55   inline int promptSize() const { return myPrompt.size(); }
56
57   PyConsole_Interp* myInterp;           //!< python interpreter
58
59   QString           myCommandBuffer;    //!< python command buffer
60   QString           myCurrentCommand;   //!< currently being printed command
61   QString           myPrompt;           //!< current command line prompt
62   int               myCmdInHistory;     //!< current history command index
63   QStringList       myHistory;          //!< commands history buffer
64   QEventLoop*       myEventLoop;        //!< internal event loop
65   QString           myBanner;           //!< current banner
66   bool              myShowBanner;       //!< 'show banner' flag
67   QStringList       myQueue;            //!< python commands queue
68   bool              myIsSync;           //!< synchronous mode flag
69   bool              myIsSuppressOutput; //!< suppress output flag
70 };
71
72 #endif // PYCONSOLE_EDITOR_H