Path: blob/devel/ElmerGUI/PythonQt/src/gui/PythonQtScriptingConsole.h
5160 views
#ifndef _PythonQtScriptingConsole_H1#define _PythonQtScriptingConsole_H23/*4*5* Copyright (C) 2006 MeVis Research GmbH All Rights Reserved.6*7* This library is free software; you can redistribute it and/or8* modify it under the terms of the GNU Lesser General Public9* License as published by the Free Software Foundation; either10* version 2.1 of the License, or (at your option) any later version.11*12* This library is distributed in the hope that it will be useful,13* but WITHOUT ANY WARRANTY; without even the implied warranty of14* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU15* Lesser General Public License for more details.16*17* Further, this software is distributed without any warranty that it is18* free of the rightful claim of any third person regarding infringement19* or the like. Any license provided herein, whether implied or20* otherwise, applies only to this software file. Patent licenses, if21* any, provided herein do not apply to combinations of this program with22* other software, or any other product whatsoever.23*24* You should have received a copy of the GNU Lesser General Public25* License along with this library; if not, write to the Free Software26* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA27*28* Contact information: MeVis Research GmbH, Universitaetsallee 29,29* 28359 Bremen, Germany or:30*31* http://www.mevis.de32*33*/3435//----------------------------------------------------------------------------------36/*!37// \file PythonQtScriptingConsole.h38// \author Florian Link39// \author Last changed by $Author: florian $40// \date 2006-1041*/42//----------------------------------------------------------------------------------4344#include "PythonQt.h"45#include <QVariant>46#include <QTextEdit>4748class QCompleter;4950//-------------------------------------------------------------------------------51//! A simple console for python scripting52class PYTHONQT_EXPORT PythonQtScriptingConsole : public QTextEdit53{54Q_OBJECT5556public:57PythonQtScriptingConsole(QWidget* parent, const PythonQtObjectPtr& context, Qt::WindowFlags i = 0);5859~PythonQtScriptingConsole();6061public slots:62//! execute current line63void executeLine(bool storeOnly);6465//! derived key press event66void keyPressEvent (QKeyEvent * e);6768//! output from console69void consoleMessage(const QString & message);7071//! get history72QStringList history() { return _history; }7374//! set history75void setHistory(const QStringList& h) { _history = h; _historyPosition = 0; }7677//! clear the console78void clear();7980//! overridden to control which characters a user may delete81virtual void cut();8283//! output redirection84void stdOut(const QString& s);85//! output redirection86void stdErr(const QString& s);8788void insertCompletion(const QString&);8990//! Appends a newline and command prompt at the end of the document.91void appendCommandPrompt(bool storeOnly = false);92protected:93//! handle the pressing of tab94void handleTabCompletion();9596//! Returns the position of the command prompt97int commandPromptPosition();9899//! Returns if deletion is allowed at the current cursor100//! (with and without selected text)101bool verifySelectionBeforeDeletion();102103//! Sets the current font104void setCurrentFont(const QColor& color = QColor(0,0,0), bool bold = false);105106//! change the history according to _historyPos107void changeHistory();108109//! flush output that was not yet printed110void flushStdOut();111112private:113void executeCode(const QString& code);114115PythonQtObjectPtr _context;116117QStringList _history;118int _historyPosition;119120QString _clickedAnchor;121QString _storageKey;122QString _commandPrompt;123124QString _currentMultiLineCode;125126QString _stdOut;127QString _stdErr;128129QTextCharFormat _defaultTextCharacterFormat;130QCompleter* _completer;131};132133134135#endif136137138