itom  3.0.0
consoleWidget.h
1 /* ********************************************************************
2  itom software
3  URL: http://www.uni-stuttgart.de/ito
4  Copyright (C) 2016, Institut fuer Technische Optik (ITO),
5  Universitaet Stuttgart, Germany
6 
7  This file is part of itom.
8 
9  itom is free software; you can redistribute it and/or modify it
10  under the terms of the GNU Library General Public Licence as published by
11  the Free Software Foundation; either version 2 of the Licence, or (at
12  your option) any later version.
13 
14  itom is distributed in the hope that it will be useful, but
15  WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library
17  General Public Licence for more details.
18 
19  You should have received a copy of the GNU Library General Public License
20  along with itom. If not, see <http://www.gnu.org/licenses/>.
21 *********************************************************************** */
22 
23 #ifndef CONSOLEWIDGET_H
24 #define CONSOLEWIDGET_H
25 
26 #include <queue>
27 
28 #include "common/sharedStructures.h"
29 #include "common/sharedStructuresQt.h"
30 #include "../python/qDebugStream.h"
31 #include "../global.h"
32 
33 #include "abstractPyScintillaWidget.h"
34 
35 #include <QKeyEvent>
36 #include <QDropEvent>
37 #include <qevent.h>
38 #include <qstring.h>
39 #include <qstringlist.h>
40 #include <qdebug.h>
41 #include <qsettings.h>
42 
43 QT_BEGIN_NAMESPACE
44 
45 QT_END_NAMESPACE
46 
47 namespace ito
48 {
49 
50 class DequeCommandList;
51 
53 {
54  Q_OBJECT
55 
56 public:
57  ConsoleWidget(QWidget* parent = NULL);
58  ~ConsoleWidget();
59 
60  static const QString lineBreak;
61 
62 protected:
63  virtual void loadSettings();
64  void autoAdaptLineNumberColumnWidth();
65 
66 public slots:
67  virtual void copy();
68  virtual void paste();
69  virtual void cut();
70  void receiveStream(QString text, ito::QDebugStream::MsgStreamType msgType);
71  void pythonRunSelection(QString selectionText);
72  void pythonStateChanged(tPythonTransitions pyTransition);
73  void clearCommandLine();
74  void startInputCommandLine(QSharedPointer<QByteArray> buffer, ItomSharedSemaphore *inputWaitCond);
75 
76 signals:
77  void wantToCopy();
78  void pythonExecuteString(QString cmd);
79  void sendToLastCommand(QString cmd);
80 
81 
82 protected:
83  void keyPressEvent (QKeyEvent *event);
84  void dropEvent (QDropEvent *event);
85  void dragEnterEvent (QDragEnterEvent *event);
86  void dragMoveEvent (QDragMoveEvent *event);
87  void wheelEvent(QWheelEvent *event);
88  void contextMenuEvent(QContextMenuEvent *event);
89  bool canInsertFromMimeData(const QMimeData *source) const;
90 
91 private slots:
92  void selChanged();
93  void textDoubleClicked(int position, int line, int modifiers);
94  void clearAndStartNewCommand();
95 
96 private:
98  {
99  cmdQueueStruct() { singleLine = ""; m_lineBegin = -1; m_nrOfLines = 1; }
100  cmdQueueStruct(QString text, int lineBegin, int nrOfLines) {singleLine = text; m_lineBegin = lineBegin; m_nrOfLines = nrOfLines; }
101  QString singleLine;
102  int m_lineBegin;
103  int m_nrOfLines;
104  };
105 
106  RetVal initEditor();
107  RetVal clearEditor();
108  RetVal startNewCommand(bool clearEditorFirst = false);
109  RetVal execCommand(int lineBegin, int lineEnd);
110  RetVal useCmdListCommand(int dir);
111 
112  RetVal executeCmdQueue();
113 
114  void moveCursorToEnd();
116 
117  int checkValidDropRegion(const QPoint &pos);
118 
120 
121  DequeCommandList *m_pCmdList;
122 
123  std::queue<cmdQueueStruct> m_cmdQueue;
124 
125  bool m_canCopy;
126  bool m_canCut;
127 
128  QDebugStream *m_pQout;
129  QDebugStream *m_pQerr;
130 
131  unsigned int m_markErrorLine;
132  unsigned int m_markCurrentLine;
133  unsigned int m_markInputLine;
134 
137 
139 
141  QSharedPointer<QByteArray> m_inputStreamBuffer;
142  int m_inputStartLine;
143  int m_inputStartCol;
144  bool m_autoWheel;
145 };
146 
148 {
149 public:
150  DequeCommandList(int maxLength);
151  ~DequeCommandList();
152 
153  RetVal add(const QString &cmd);
154  RetVal moveLast();
155  QString getPrevious();
156  QString getNext();
157 
158 private:
159  int m_maxItems;
160  std::deque<QString> m_cmdList;
161  std::deque<QString>::reverse_iterator m_rit;
162 };
163 
164 } //end namespace ito
165 
166 #endif
bool m_pythonBusy
true: python is executing or debugging a script, a command...
Definition: consoleWidget.h:136
Definition: consoleWidget.h:97
void keyPressEvent(QKeyEvent *event)
reimplementation to process the keyReleaseEvent
Definition: consoleWidget.cpp:447
bool m_waitForCmdExecutionDone
true: command in this console is being executed and sends a finish-event, when done.
Definition: consoleWidget.h:135
Definition: abstractPyScintillaWidget.h:45
RetVal startNewCommand(bool clearEditorFirst=false)
< new command is a new line starting with ">>"
Definition: consoleWidget.cpp:337
Class for managing status values (like errors or warning)
Definition: retVal.h:54
int checkValidDropRegion(const QPoint &pos)
Definition: consoleWidget.cpp:1409
void moveCursorToValidRegion()
Definition: consoleWidget.cpp:1580
Definition: consoleWidget.h:52
Definition: apiFunctionsGraph.cpp:39
ConsoleWidget(QWidget *parent=NULL)
Definition: consoleWidget.cpp:49
semaphore which can be used for asychronous thread communication. By using this class it is possible ...
Definition: sharedStructuresQt.h:57
void dragMoveEvent(QDragMoveEvent *event)
Definition: consoleWidget.cpp:1354
void receiveStream(QString text, ito::QDebugStream::MsgStreamType msgType)
Definition: consoleWidget.cpp:1199
Definition: consoleWidget.h:147
QString m_temporaryRemovedCommands
removed text, if python busy, caused by another console instance or script.
Definition: consoleWidget.h:138
ItomSharedSemaphore * m_inputStreamWaitCond
if this is != NULL, a input(...) command is currently running in Python and the command line is ready...
Definition: consoleWidget.h:140
int m_startLineBeginCmd
zero-based, first-line of actual (not evaluated command), last line which starts with ">>"...
Definition: consoleWidget.h:119
std::queue< cmdQueueStruct > m_cmdQueue
upcoming events to handle
Definition: consoleWidget.h:123
static const QString lineBreak
< constants
Definition: consoleWidget.h:60
Definition: qDebugStream.h:38
bool m_autoWheel
true if command line should automatically move to the last line if new lines are appended, this is set to false upon a wheel event and will be reset to true if the command line is cleared (clc) or if a new input is added
Definition: consoleWidget.h:144