itom
Loading...
Searching...
No Matches
consoleWidget.h
1/* ********************************************************************
2 itom software
3 URL: http://www.uni-stuttgart.de/ito
4 Copyright (C) 2024, Institut für Technische Optik (ITO),
5 Universität 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 "abstractCodeEditorWidget.h"
34#include "../codeEditor/modes/lineBackgroundMarker.h"
35#include "../codeEditor/modes/pyGotoAssignment.h"
36#include "../codeEditor/panels/lineNumber.h"
37
38#include <QKeyEvent>
39#include <QDropEvent>
40#include <qevent.h>
41#include <qstring.h>
42#include <qstringlist.h>
43#include <qdebug.h>
44#include <qsettings.h>
45#include <qtimer.h>
46#include <qelapsedtimer.h>
47#include <qregularexpression.h>
48
49
50
51namespace ito
52{
53
54class DequeCommandList;
55
57{
58 Q_OBJECT
59
60public:
61 ConsoleWidget(QWidget* parent = nullptr);
63
64 static const QString lineBreak;
65 static const QString newCommandPrefix;
66
67 virtual QString codeText(int &line, int &column) const;
68
69protected:
70 virtual void loadSettings();
71 virtual void contextMenuAboutToShow(int contextMenuLine);
72 virtual int startLineOffset(int lineIdx) const;
73 void initMenus();
74
75public slots:
76 virtual void copy();
77 virtual void paste();
78 virtual void cut();
79 void receiveStream(QString text, ito::tStreamMessageType msgType);
80 void pythonRunSelection(QString selectionText);
81 void pythonStateChanged(tPythonTransitions pyTransition);
82 void clearCommandLine();
83 void interruptCommandInput(); // interrupt a possibly running input command
84 void startInputCommandLine(QSharedPointer<QByteArray> buffer, ItomSharedSemaphore *inputWaitCond);
85
86signals:
87 void wantToCopy();
88 void sendToLastCommand(QString cmd);
89
90protected:
91 virtual bool keyPressInternalEvent(QKeyEvent *event);
92 void dropEvent (QDropEvent *event);
93 void dragEnterEvent (QDragEnterEvent *event);
94 void dragMoveEvent (QDragMoveEvent *event);
95 void wheelEvent(QWheelEvent *event);
96 bool canInsertFromMimeData(const QMimeData *source) const;
97 void mouseDoubleClickEvent(QMouseEvent *e);
98
99private slots:
100 void selChanged();
101 void textDoubleClicked(int position, int line, int modifiers);
102 void clearAndStartNewCommand();
103 void toggleAutoWheel(bool enable);
104 void processStreamBuffer();
105
106private:
108 {
109 CmdQueueItem() :
110 m_lineBegin(-1),
111 m_nrOfLines(1)
112 {}
113
114 CmdQueueItem(const QString &text, int lineBegin, int nrOfLines) :
115 m_singleLine(text),
116 m_lineBegin(lineBegin),
117 m_nrOfLines(nrOfLines)
118 {}
119
120 QString m_singleLine;
121 int m_lineBegin;
122 int m_nrOfLines;
123 };
124
126 {
127 QString text;
129 };
130
132 {
133 bool inputModeEnabled;
134 bool calltipsModeCurrentState; //current enable state of calltips mode before starting input text mode (only valid if inputModeEnabled = true)
135 bool autoCompletionModeCurrentState; //current enable state of completion mode before starting input text mode (only valid if inputModeEnabled = true)
136 };
137
138 RetVal initEditor();
139 RetVal clearEditor();
140 RetVal startNewCommand(bool clearEditorFirst = false);
141 RetVal execCommand(int lineBegin, int lineEnd);
142 RetVal useCmdListCommand(int dir);
143
144 RetVal executeCmdQueue();
145
146 void autoLineDelete();
147 void moveCursorToEnd();
149
150 int checkValidDropRegion(const QPoint &pos);
151
152 void enableInputTextMode();
153 void disableInputTextMode();
154
155 QList<ito::TextBlockUserData::AnsiTextCharFormat> parseReceiveStreamBufferForAnsiCodes(const QString &inputText, QString &strippedText);
156 QList<QSharedPointer<QList<ito::TextBlockUserData::AnsiTextCharFormat>>> handleTextLinesAndSplitLongLines(
157 QString &text,
158 const QList<ito::TextBlockUserData::AnsiTextCharFormat> &ansiTextCharFormat,
159 bool smartSplitting);
160 QList<QSharedPointer<QList<ito::TextBlockUserData::AnsiTextCharFormat>>> splitLongLinesText(
161 QString &text,
162 const QSharedPointer<QList<ito::TextBlockUserData::AnsiTextCharFormat>> &ansiTextCharFormat,
163 bool smartSplitting);
164 void updateAnsiTextCharFormat(ito::TextBlockUserData::AnsiTextCharFormat &format, const QString &mainChar, const QString &args);
165
167
168 DequeCommandList *m_pCmdList;
169
170 std::queue<CmdQueueItem> m_cmdQueue;
171
172 bool m_canCopy;
173 bool m_canCut;
174 StreamBuffer m_receiveStreamBuffer;
175 QTimer m_receiveStreamBufferTimer;
176 bool m_splitLongLines;
177 int m_splitLongLinesMaxLength;
178 CmdQueueItem m_currentlyExecutedCommand;
179
180 QSharedPointer<LineBackgroundMarkerMode> m_markErrorLineMode;
181 QSharedPointer<LineBackgroundMarkerMode> m_markCurrentLineMode;
182 QSharedPointer<LineBackgroundMarkerMode> m_markInputLineMode;
183 QSharedPointer<LineNumberPanel> m_lineNumberPanel;
184
187
189
191 QSharedPointer<QByteArray> m_inputStreamBuffer;
195
196 QMap<QString, QAction*> m_contextMenuActions;
197
198 InputTextMode m_inputTextMode;
199
200 ito::TextBlockUserData::AnsiTextCharFormat m_recentAnsiTextCharFormat;
201 QRegularExpression m_ansiEscapeSeqRegExp;
202 bool m_considerAnsiEscapeSequences;
203
204 static const QString longLineWrapPrefix;
205
206};
207
209{
210public:
211 DequeCommandList(int maxLength);
213
214 RetVal add(const QString &cmd);
215 RetVal moveLast();
216 QString getPrevious();
217 QString getNext();
218
219private:
220 int m_maxItems;
221 std::deque<QString> m_cmdList;
222 std::deque<QString>::reverse_iterator m_rit;
223};
224
225} //end namespace ito
226
227#endif
semaphore which can be used for asynchronous thread communication. By using this class it is possible...
Definition sharedStructuresQt.h:58
Definition abstractCodeEditorWidget.h:47
Definition consoleWidget.h:57
int m_startLineBeginCmd
zero-based, first-line of actual (not evaluated command), last line which starts with ">>",...
Definition consoleWidget.h:166
bool m_waitForCmdExecutionDone
true: command in this console is being executed and sends a finish-event, when done.
Definition consoleWidget.h:185
ConsoleWidget(QWidget *parent=nullptr)
Definition consoleWidget.cpp:58
virtual bool keyPressInternalEvent(QKeyEvent *event)
Definition consoleWidget.cpp:422
QString m_temporaryRemovedCommands
removed commands, if python busy, caused by another console instance or script (we assume that these ...
Definition consoleWidget.h:188
RetVal startNewCommand(bool clearEditorFirst=false)
< new command is a new line starting with ">>" (newCommandPrefix)
Definition consoleWidget.cpp:322
std::queue< CmdQueueItem > m_cmdQueue
upcoming events to handle
Definition consoleWidget.h:170
int m_inputStartCol
if python-input command is currently used to ask for user-input, this variable holds the column in li...
Definition consoleWidget.h:193
void dragMoveEvent(QDragMoveEvent *event)
Definition consoleWidget.cpp:2019
void dropEvent(QDropEvent *event)
Definition consoleWidget.cpp:1929
void moveCursorToValidRegion()
Definition consoleWidget.cpp:2207
void autoLineDelete()
delete the first N lines if the command line has more than M (M>=N) lines
Definition consoleWidget.cpp:2312
ItomSharedSemaphore * m_inputStreamWaitCond
if this is != NULL, a input(...) command is currently running in Python and the command line is ready...
Definition consoleWidget.h:190
bool m_pythonBusy
true: python is executing or debugging a script, a command...
Definition consoleWidget.h:186
void processStreamBuffer()
Definition consoleWidget.cpp:1765
int m_inputStartLine
if python-input command is currently used to ask for user-input, this variable holds the line of the ...
Definition consoleWidget.h:192
int checkValidDropRegion(const QPoint &pos)
Definition consoleWidget.cpp:2074
bool m_autoWheel
true if command line should automatically move to the last line if new lines are appended,...
Definition consoleWidget.h:194
static const QString lineBreak
< constants
Definition consoleWidget.h:64
Definition consoleWidget.h:209
Class for managing status values (like errors or warning)
Definition retVal.h:54
Definition apiFunctionsGraph.cpp:40
tStreamMessageType
Definition typeDefs.h:77
Definition consoleWidget.h:108
Definition consoleWidget.h:132
Definition consoleWidget.h:126
Definition textBlockUserData.h:77