Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
ElmerCSC
GitHub Repository: ElmerCSC/elmerfem
Path: blob/devel/ElmerGUI/PythonQt/src/gui/PythonQtScriptingConsole.h
5160 views
1
#ifndef _PythonQtScriptingConsole_H
2
#define _PythonQtScriptingConsole_H
3
4
/*
5
*
6
* Copyright (C) 2006 MeVis Research GmbH All Rights Reserved.
7
*
8
* This library is free software; you can redistribute it and/or
9
* modify it under the terms of the GNU Lesser General Public
10
* License as published by the Free Software Foundation; either
11
* version 2.1 of the License, or (at your option) any later version.
12
*
13
* This library is distributed in the hope that it will be useful,
14
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16
* Lesser General Public License for more details.
17
*
18
* Further, this software is distributed without any warranty that it is
19
* free of the rightful claim of any third person regarding infringement
20
* or the like. Any license provided herein, whether implied or
21
* otherwise, applies only to this software file. Patent licenses, if
22
* any, provided herein do not apply to combinations of this program with
23
* other software, or any other product whatsoever.
24
*
25
* You should have received a copy of the GNU Lesser General Public
26
* License along with this library; if not, write to the Free Software
27
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28
*
29
* Contact information: MeVis Research GmbH, Universitaetsallee 29,
30
* 28359 Bremen, Germany or:
31
*
32
* http://www.mevis.de
33
*
34
*/
35
36
//----------------------------------------------------------------------------------
37
/*!
38
// \file PythonQtScriptingConsole.h
39
// \author Florian Link
40
// \author Last changed by $Author: florian $
41
// \date 2006-10
42
*/
43
//----------------------------------------------------------------------------------
44
45
#include "PythonQt.h"
46
#include <QVariant>
47
#include <QTextEdit>
48
49
class QCompleter;
50
51
//-------------------------------------------------------------------------------
52
//! A simple console for python scripting
53
class PYTHONQT_EXPORT PythonQtScriptingConsole : public QTextEdit
54
{
55
Q_OBJECT
56
57
public:
58
PythonQtScriptingConsole(QWidget* parent, const PythonQtObjectPtr& context, Qt::WindowFlags i = 0);
59
60
~PythonQtScriptingConsole();
61
62
public slots:
63
//! execute current line
64
void executeLine(bool storeOnly);
65
66
//! derived key press event
67
void keyPressEvent (QKeyEvent * e);
68
69
//! output from console
70
void consoleMessage(const QString & message);
71
72
//! get history
73
QStringList history() { return _history; }
74
75
//! set history
76
void setHistory(const QStringList& h) { _history = h; _historyPosition = 0; }
77
78
//! clear the console
79
void clear();
80
81
//! overridden to control which characters a user may delete
82
virtual void cut();
83
84
//! output redirection
85
void stdOut(const QString& s);
86
//! output redirection
87
void stdErr(const QString& s);
88
89
void insertCompletion(const QString&);
90
91
//! Appends a newline and command prompt at the end of the document.
92
void appendCommandPrompt(bool storeOnly = false);
93
protected:
94
//! handle the pressing of tab
95
void handleTabCompletion();
96
97
//! Returns the position of the command prompt
98
int commandPromptPosition();
99
100
//! Returns if deletion is allowed at the current cursor
101
//! (with and without selected text)
102
bool verifySelectionBeforeDeletion();
103
104
//! Sets the current font
105
void setCurrentFont(const QColor& color = QColor(0,0,0), bool bold = false);
106
107
//! change the history according to _historyPos
108
void changeHistory();
109
110
//! flush output that was not yet printed
111
void flushStdOut();
112
113
private:
114
void executeCode(const QString& code);
115
116
PythonQtObjectPtr _context;
117
118
QStringList _history;
119
int _historyPosition;
120
121
QString _clickedAnchor;
122
QString _storageKey;
123
QString _commandPrompt;
124
125
QString _currentMultiLineCode;
126
127
QString _stdOut;
128
QString _stdErr;
129
130
QTextCharFormat _defaultTextCharacterFormat;
131
QCompleter* _completer;
132
};
133
134
135
136
#endif
137
138