HAL
python_console.h
Go to the documentation of this file.
1
// MIT License
2
//
3
// Copyright (c) 2019 Ruhr University Bochum, Chair for Embedded Security. All Rights reserved.
4
// Copyright (c) 2019 Marc Fyrbiak, Sebastian Wallat, Max Hoffmann ("ORIGINAL AUTHORS"). All rights reserved.
5
// Copyright (c) 2021 Max Planck Institute for Security and Privacy. All Rights reserved.
6
// Copyright (c) 2021 Jörn Langheinrich, Julian Speith, Nils Albartus, René Walendy, Simon Klix ("ORIGINAL AUTHORS"). All Rights reserved.
7
//
8
// Permission is hereby granted, free of charge, to any person obtaining a copy
9
// of this software and associated documentation files (the "Software"), to deal
10
// in the Software without restriction, including without limitation the rights
11
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12
// copies of the Software, and to permit persons to whom the Software is
13
// furnished to do so, subject to the following conditions:
14
//
15
// The above copyright notice and this permission notice shall be included in all
16
// copies or substantial portions of the Software.
17
//
18
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24
// SOFTWARE.
25
26
#pragma once
27
28
#include "
gui/python/python_context_subscriber.h
"
29
30
#include <QTextEdit>
31
#include <memory>
32
33
class
QLabel
;
34
class
QPushButton
;
35
class
QTimer
;
36
37
namespace
hal
38
{
39
class
PythonConsoleHistory;
40
41
class
PythonConsoleAbortThread
:
public
QFrame
42
{
43
Q_OBJECT
44
int
mCount;
45
QLabel
* mLabel;
46
QPushButton
* mAbortButton;
47
QTimer
* mTimer;
48
49
private
Q_SLOTS
:
50
void
handleTimeout();
51
void
handleAbortButton();
52
public
:
53
PythonConsoleAbortThread
(
QWidget
*
parent
=
nullptr
);
54
void
start
();
55
void
stop
();
56
};
57
64
class
PythonConsole
:
public
QTextEdit
,
public
PythonContextSubscriber
65
{
66
Q_OBJECT
67
68
public
:
72
PythonConsole
(
QWidget
*
parent
=
nullptr
);
73
~PythonConsole
();
74
75
enum
PromptType
{
Standard
,
Compound
,
Input
};
76
77
protected
:
90
void
keyPressEvent
(
QKeyEvent
* e)
override
;
91
97
void
mousePressEvent
(
QMouseEvent
*
event
)
override
;
98
99
public
Q_SLOTS
:
100
void
handleThreadFinished
();
101
102
private
Q_SLOTS
:
103
void
handleStyleChanged(
int
istyle);
104
105
Q_SIGNALS
:
106
void
inputReceived
(
QString
input);
107
108
public
:
114
virtual
void
handleStdout
(
const
QString
& output)
override
;
115
121
virtual
void
handleError
(
const
QString
& output)
override
;
122
126
virtual
void
clear
()
override
;
127
131
void
displayPrompt
();
132
138
void
interpretCommand
();
139
145
QString
getCurrentCommand
();
146
152
void
replaceCurrentCommand
(
const
QString
& new_command);
153
159
void
appendToCurrentCommand
(
const
QString
& new_command);
160
166
bool
selectionEditable
();
167
171
void
handleUpKeyPressed
();
172
176
void
handleDownKeyPressed
();
177
181
void
handleTabKeyPressed
();
182
189
void
insertAtEnd
(
const
QString
& text,
QColor
textColor
);
190
196
void
setInputMode
(
bool
state);
197
198
PythonConsoleAbortThread
*
abortThreadWidget
();
199
200
private
:
201
QString
mStandardPrompt;
202
QString
mCompoundPrompt;
203
QString
mInputPrompt;
204
205
int
mPromptBlockNumber;
206
int
mPromptLength;
207
int
mPromptEndPosition;
208
int
mCompoundPromptEndPosition;
209
210
PromptType
mPromptType;
211
bool
mInCompletion;
212
213
QString
mCurrentCompoundInput;
214
QString
mCurrentInput;
215
216
int
mCurrentHistoryIndex;
217
int
mCurrentCompleterIndex;
218
219
std::shared_ptr<PythonConsoleHistory> mHistory;
220
PythonConsoleAbortThread
* mAbortThreadWidget;
221
222
bool
isCompound()
const
{
return
mPromptType ==
Compound
; }
223
bool
isInputMode()
const
{
return
mPromptType ==
Input
; }
224
225
void
keyPressEventInputMode(
QKeyEvent
* e);
226
};
227
}
hal::PythonConsoleAbortThread
Definition:
python_console.h:42
hal::PythonConsoleAbortThread::PythonConsoleAbortThread
PythonConsoleAbortThread(QWidget *parent=nullptr)
Definition:
python_console.cpp:471
hal::PythonConsoleAbortThread::stop
void stop()
Definition:
python_console.cpp:520
hal::PythonConsoleAbortThread::start
void start()
Definition:
python_console.cpp:512
hal::PythonConsole
An interactable python console.
Definition:
python_console.h:65
hal::PythonConsole::handleThreadFinished
void handleThreadFinished()
Definition:
python_console.cpp:288
hal::PythonConsole::mousePressEvent
void mousePressEvent(QMouseEvent *event) override
Definition:
python_console.cpp:205
hal::PythonConsole::PromptType
PromptType
Definition:
python_console.h:75
hal::PythonConsole::Input
@ Input
Definition:
python_console.h:75
hal::PythonConsole::Compound
@ Compound
Definition:
python_console.h:75
hal::PythonConsole::Standard
@ Standard
Definition:
python_console.h:75
hal::PythonConsole::PythonConsole
PythonConsole(QWidget *parent=nullptr)
Definition:
python_console.cpp:19
hal::PythonConsole::keyPressEvent
void keyPressEvent(QKeyEvent *e) override
Definition:
python_console.cpp:74
hal::PythonConsole::displayPrompt
void displayPrompt()
Definition:
python_console.cpp:253
hal::PythonConsole::handleUpKeyPressed
void handleUpKeyPressed()
Definition:
python_console.cpp:362
hal::PythonConsole::setInputMode
void setInputMode(bool state)
Definition:
python_console.cpp:245
hal::PythonConsole::~PythonConsole
~PythonConsole()
Definition:
python_console.cpp:38
hal::PythonConsole::handleTabKeyPressed
void handleTabKeyPressed()
Definition:
python_console.cpp:410
hal::PythonConsole::inputReceived
void inputReceived(QString input)
hal::PythonConsole::clear
virtual void clear() override
Definition:
python_console.cpp:240
hal::PythonConsole::handleStdout
virtual void handleStdout(const QString &output) override
Definition:
python_console.cpp:227
hal::PythonConsole::abortThreadWidget
PythonConsoleAbortThread * abortThreadWidget()
Definition:
python_console.cpp:465
hal::PythonConsole::handleDownKeyPressed
void handleDownKeyPressed()
Definition:
python_console.cpp:389
hal::PythonConsole::getCurrentCommand
QString getCurrentCommand()
Definition:
python_console.cpp:328
hal::PythonConsole::selectionEditable
bool selectionEditable()
Definition:
python_console.cpp:355
hal::PythonConsole::interpretCommand
void interpretCommand()
Definition:
python_console.cpp:293
hal::PythonConsole::replaceCurrentCommand
void replaceCurrentCommand(const QString &new_command)
Definition:
python_console.cpp:340
hal::PythonConsole::insertAtEnd
void insertAtEnd(const QString &text, QColor textColor)
Definition:
python_console.cpp:220
hal::PythonConsole::handleError
virtual void handleError(const QString &output) override
Definition:
python_console.cpp:232
hal::PythonConsole::appendToCurrentCommand
void appendToCurrentCommand(const QString &new_command)
Definition:
python_console.cpp:348
hal::PythonContextSubscriber
Interface for handling python outputs.
Definition:
python_context_subscriber.h:36
hal
Definition:
parser_liberty.cpp:10
python_context_subscriber.h
QAbstractScrollArea::event
virtual bool event(QEvent *event) override
QColor
QFrame
QKeyEvent
QLabel
QMouseEvent
QObject::Q_OBJECT
Q_OBJECTQ_OBJECT
QObject::Q_SIGNALS
Q_SIGNALSQ_SIGNALS
QObject::Q_SLOTS
Q_SLOTSQ_SLOTS
QObject::parent
QObject * parent() const const
QPushButton
QString
QTextEdit
QTextEdit::textColor
QColor textColor() const const
QTimer
QWidget
plugins
gui
include
gui
python
python_console.h
Generated on Fri Feb 14 2025 14:22:41 for HAL by
1.9.1