SMILX  1.01
milxQtPythonConsole.h
Go to the documentation of this file.
1 #ifndef _MILXQTPythonConsole_H
2 #define _MILXQTPythonConsole_H
3 
4 /*
5  *
6  * Copyright (C) 2010 MeVis Medical Solutions AG 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 Medical Solutions AG, Universitaetsallee 29,
30  * 28359 Bremen, Germany or:
31  *
32  * http://www.mevis.de
33  *
34  */
35 
36 //----------------------------------------------------------------------------------
44 //----------------------------------------------------------------------------------
45 
46 #include "PythonQt.h"
47 #include <QVariant>
48 #include <QTextEdit>
49 
50 #include "milxQtAliases.h"
51 
52 class QCompleter;
53 
54 //-------------------------------------------------------------------------------
73 class MILXQT_PLUGIN_EXPORT milxQtPythonConsole : public QTextEdit
74 {
75  Q_OBJECT
76 
77 public:
78  milxQtPythonConsole(QWidget* parent, const PythonQtObjectPtr& context, Qt::WindowFlags i = 0);
79 
81 
82 public slots:
84  void executeLine(bool storeOnly);
85 
87  void keyPressEvent (QKeyEvent * e);
88 
90  void consoleMessage(const QString & message);
91 
93  QStringList history()
94  {
95  return _history;
96  }
97 
99  void setHistory(const QStringList& h)
100  {
101  _history = h;
102  _historyPosition = 0;
103  }
104 
106  void clear();
107 
109  virtual void cut();
110 
112  void stdOut(const QString& s);
114  void stdErr(const QString& s);
115 
116  void insertCompletion(const QString&);
117 
119  void appendCommandPrompt(bool storeOnly = false);
120 
121 public:
123  bool hadError()
124  {
125  return _hadError;
126  }
127 
129  void clearError()
130  {
131  _hadError = false;
132  }
133 
134 protected:
135  QAction *copyAct;
136  QAction *cutAct;
137  QAction *pasteAct;
138  QAction *clearAct;
139 
141  void handleTabCompletion();
142 
144  int commandPromptPosition();
145 
148  bool verifySelectionBeforeDeletion();
149 
151  void setCurrentFont(const QColor& color = QColor(0,0,0), bool bold = false);
152 
154  void changeHistory();
155 
157  void flushStdOut();
158 
160  void readSettings();
161 
163  void writeSettings();
164 
166  void createActions();
167 
169  void createConnections();
170 
172  void contextMenuEvent(QContextMenuEvent *currentEvent);
173 
174 
175 private:
176  void executeCode(const QString& code);
177 
178  PythonQtObjectPtr _context;
179 
180  QStringList _history;
181  int _historyPosition;
182 
183  QString _clickedAnchor;
184  QString _storageKey;
185  QString _commandPrompt;
186 
187  QString _currentMultiLineCode;
188 
189  QString _stdOut;
190  QString _stdErr;
191 
192  QTextCharFormat _defaultTextCharacterFormat;
193  QCompleter* _completer;
194 
195  bool _hadError;
196 };
197 
198 #endif //_MILXQTPythonConsole_H
void clearError()
returns true if python cerr had an error
This file defines all the defines, aliases and frequently used functions and variables.
bool hadError()
returns true if python cerr had an error
void setHistory(const QStringList &h)
set history
QAction * copyAct
Copy action for text.
QAction * clearAct
clear action for text
QAction * pasteAct
Paste action for text.
QStringList history()
get history
#define MILXQT_PLUGIN_EXPORT
Define Windows Plugin DLL importing.
QAction * cutAct
Cut action for text.
A simple console for python scripting with some syntax highlighting.