Canorus  0.7
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
/home/iurt/rpm/BUILD/canorus-0.7.R1002/src/widgets/pyconsole.h
Go to the documentation of this file.
00001 
00008 #ifndef PYCONSOLE_H_
00009 #define PYCONSOLE_H_
00010 
00011 #include <QObject>
00012 #include <QTextEdit>
00013 #include <QMutex>
00014 #include <QWaitCondition>
00015 #include <QToolBar>
00016 #include "core/document.h"
00017 
00018 class CAPyConsole : public QTextEdit {
00019         Q_OBJECT
00020 public:
00021     enum TxtType {
00022                 txtNormal,
00023                 txtStdout,
00024                 txtStderr
00025         };
00026 
00027         CAPyConsole ( CADocument *doc, QWidget *parent=0);
00028 
00029         QString asyncBufferedInput(QString prompt);
00030         void asyncBufferedOutput(QString bufInp, bool bStdErr);
00031         void asyncPluginInit();
00032         void asyncKeyboardInterrupt();
00033 
00034 protected:
00035         void keyPressEvent (QKeyEvent * e);
00036 
00037 private slots:
00038         void txtAppend(const QString & text, TxtType txtType = txtNormal );
00039         void on_txtChanged();
00040         void on_posChanged();
00041         void on_selChanged();
00042         void on_fmtChanged();
00043         void syncPluginInit();
00044 
00045 signals:
00046         void sig_txtAppend(const QString & text, TxtType stdType);
00047         void sig_syncPluginInit();
00048 
00049 private:
00050     enum HistLay {
00051         histPrev,
00052         histNext
00053     };
00054 
00055     struct TxtFragment {
00056                 QString text;
00057                 TxtType type;
00058         };
00059 
00060         // void txtAppend(...) -> is in signals
00061         void txtRevert();
00062         QString txtGetInput(bool bReadText = false);
00063     void txtSetInput(QString input, bool bUpdateText = true);
00064 
00065         void histAdd();
00066     void histGet(HistLay histLay);
00067 
00068         // text in the console
00069         QTextCursor _curInput, _curNew;
00070         int _iCurStart, _iCurNowOld, _iCurNow;
00071     bool _bIgnTxtChange;
00072 
00073         TxtFragment *_tf;
00074         QList<TxtFragment*> _txtFixed;
00075         QString _strInput;
00076 
00077         // history
00078     int _histIndex;
00079         QList<QString> _histList;
00080         QString _histOldInput;  // old _strInput
00081 
00082         QTextCharFormat _fmtNormal;
00083         QTextCharFormat _fmtStdout;
00084         QTextCharFormat _fmtStderr;
00085 
00086         // thread
00087         QString _bufSend;
00088         QMutex *_thrWaitMut;
00089         QWaitCondition *_thrWait;
00090         QMutex *_thrIntrWaitMut;
00091         QWaitCondition *_thrIntrWait;
00092 
00093         // pyconsole '/' commands
00094         bool cmdIntern(QString strCmd);
00095         QString _strEntryFunc;
00096 
00097     // rarely used
00098         CADocument *_canorusDoc;
00099         QWidget* _parent;
00100 };
00101 
00102 #endif /* PYCONSOLE_H_ */