PythonConsole.h

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (c) 2004 Werner Mayer <wmayer[at]users.sourceforge.net>     *
00003  *                                                                         *
00004  *   This file is part of the FreeCAD CAx development system.              *
00005  *                                                                         *
00006  *   This library is free software; you can redistribute it and/or         *
00007  *   modify it under the terms of the GNU Library General Public           *
00008  *   License as published by the Free Software Foundation; either          *
00009  *   version 2 of the License, or (at your option) any later version.      *
00010  *                                                                         *
00011  *   This library  is distributed in the hope that it will be useful,      *
00012  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00013  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00014  *   GNU Library General Public License for more details.                  *
00015  *                                                                         *
00016  *   You should have received a copy of the GNU Library General Public     *
00017  *   License along with this library; see the file COPYING.LIB. If not,    *
00018  *   write to the Free Software Foundation, Inc., 59 Temple Place,         *
00019  *   Suite 330, Boston, MA  02111-1307, USA                                *
00020  *                                                                         *
00021  ***************************************************************************/
00022 
00023 
00024 #ifndef GUI_PYTHONCONSOLE_H
00025 #define GUI_PYTHONCONSOLE_H
00026 
00027 #include "PythonEditor.h"
00028 
00029 #include <Base/PyObjectBase.h>
00030 
00031 class QPlainTextEdit;
00032 class QPushButton;
00033 
00034 namespace Gui {
00035 
00040 class GuiExport InteractiveInterpreter
00041 {
00042 public:
00043     InteractiveInterpreter();
00044     ~InteractiveInterpreter();
00045 
00046     bool push(const char*);
00047     int compileCommand(const char*) const;
00048     void setBuffer(const QStringList&);
00049     QStringList getBuffer() const;
00050     void clearBuffer();
00051 
00052 private:
00053     bool runSource(const char*) const;
00054     PyObject* compile(const char*) const;
00055     void runCode(PyCodeObject*) const;
00056     void setPrompt();
00057 
00058 private:
00059     struct InteractiveInterpreterP* d;
00060 };
00061 
00066 class GuiExport ConsoleHistory
00067 {
00068 public:
00069     ConsoleHistory();
00070     ~ConsoleHistory();
00071 
00072     void first();
00073     bool more();
00074     bool next();
00075     bool prev();
00076     bool isEmpty() const;
00077     QString value() const;
00078     void append( const QString& );
00079     const QStringList& values() const;
00080 
00081 private:
00082     QStringList _history;
00083     QStringList::ConstIterator it;
00084 };
00085 
00090 class PythonConsoleHighlighter;
00091 class GuiExport PythonConsole : public TextEdit, public WindowParameter
00092 {
00093     Q_OBJECT
00094 
00095 public:
00096     PythonConsole(QWidget *parent = 0);
00097     ~PythonConsole();
00098 
00099     void OnChange( Base::Subject<const char*> &rCaller,const char* rcReason );
00100     void printStatement( const QString& cmd );
00101 
00102 public Q_SLOTS:
00103     void onSaveHistoryAs();
00104     void onInsertFileName();
00105     void onCopyHistory();
00106     void onCopyCommand();
00107 
00108 private Q_SLOTS:
00109     void visibilityChanged (bool visible);
00110 
00111 protected:
00112     void keyPressEvent  ( QKeyEvent         * e );
00113     void showEvent      ( QShowEvent        * e );
00114     void dropEvent      ( QDropEvent        * e );
00115     void dragEnterEvent ( QDragEnterEvent   * e );
00116     void dragMoveEvent  ( QDragMoveEvent    * e );
00117     void changeEvent    ( QEvent            * e );
00118 
00119     void overrideCursor(const QString& txt);
00120 
00122     void contextMenuEvent ( QContextMenuEvent* e );
00123     bool canInsertFromMimeData ( const QMimeData * source ) const;
00124     QMimeData * createMimeDataFromSelection () const;
00125     void insertFromMimeData ( const QMimeData * source );
00126 
00127 private:
00128     void runSource(const QString&);
00129     bool isComment(const QString&) const;
00130     void printPrompt(bool);
00131     void insertPythonOutput(const QString&);
00132     void insertPythonError (const QString&);
00133     void runSourceFromMimeData(const QString&);
00134     void appendOutput(const QString&, int);
00135 
00136 private:
00137     struct PythonConsoleP* d;
00138 
00139     friend class PythonStdout;
00140     friend class PythonStderr;
00141 
00142 private:
00143     PythonConsoleHighlighter* pythonSyntax;
00144 };
00145 
00150 class GuiExport PythonConsoleHighlighter : public PythonSyntaxHighlighter
00151 {
00152 public:
00153     PythonConsoleHighlighter(QObject* parent);
00154     ~PythonConsoleHighlighter();
00155 
00156     void highlightBlock (const QString & text);
00157 
00158 protected:
00159     void colorChanged(const QString& type, const QColor& col);
00160 };
00161 
00162 class GuiExport PythonInputField : public QWidget
00163 {
00164     Q_OBJECT
00165 
00166 public:
00167     PythonInputField(QWidget* parent=0);
00168     ~PythonInputField();
00169     QString getText() const;
00170     void clear();
00171 
00172 protected:
00173     void changeEvent(QEvent *e);
00174     void showEvent(QShowEvent* e);
00175 
00176 Q_SIGNALS:
00177     void textEntered();
00178 
00179 private:
00180     QPushButton* okButton;
00181     QPushButton* clearButton;
00182     QPlainTextEdit* editField;
00183 };
00184 
00185 } // namespace Gui
00186 
00187 #endif // GUI_PYTHONCONSOLE_H

Generated on Wed Nov 23 19:00:32 2011 for FreeCAD by  doxygen 1.6.1