HAL
v4.5.0-83-g30c8f0afc
The Hardware Analyzer - a comprehensive reverse engineering and manipulation framework for gate-level netlists.
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
44
class
PythonConsoleAbortThread
:
public
QFrame
45
{
46
Q_OBJECT
47
int
mCount;
48
QLabel
* mLabel;
49
QPushButton
* mAbortButton;
50
QTimer
* mTimer;
51
52
private
Q_SLOTS
:
53
void
handleTimeout();
54
void
handleAbortButton();
55
public
:
56
PythonConsoleAbortThread
(
QWidget
*
parent
=
nullptr
);
57
void
start
();
58
void
stop
();
59
};
60
67
class
PythonConsole
:
public
QTextEdit
,
public
PythonContextSubscriber
68
{
69
Q_OBJECT
70
71
public
:
75
PythonConsole
(
QWidget
*
parent
=
nullptr
);
76
~PythonConsole
();
77
78
enum
PromptType
{
Standard
,
Compound
,
Input
};
79
80
protected
:
93
void
keyPressEvent
(
QKeyEvent
* e)
override
;
94
100
void
mousePressEvent
(
QMouseEvent
*
event
)
override
;
101
102
public
Q_SLOTS
:
103
void
handleThreadFinished
();
104
105
private
Q_SLOTS
:
106
void
handleStyleChanged(
int
istyle);
107
108
Q_SIGNALS
:
109
void
inputReceived
(
QString
input);
110
111
public
:
117
virtual
void
handleStdout
(
const
QString
& output)
override
;
118
124
virtual
void
handleError
(
const
QString
& output)
override
;
125
129
virtual
void
clear
()
override
;
130
134
void
displayPrompt
();
135
141
void
interpretCommand
();
142
148
QString
getCurrentCommand
();
149
155
void
replaceCurrentCommand
(
const
QString
& new_command);
156
162
void
appendToCurrentCommand
(
const
QString
& new_command);
163
169
bool
selectionEditable
();
170
174
void
handleUpKeyPressed
();
175
179
void
handleDownKeyPressed
();
180
184
void
handleTabKeyPressed
();
185
192
void
insertAtEnd
(
const
QString
& text,
QColor
textColor
);
193
199
void
setInputMode
(
bool
state);
200
201
PythonConsoleAbortThread
*
abortThreadWidget
();
202
203
private
:
204
QString
mStandardPrompt;
205
QString
mCompoundPrompt;
206
QString
mInputPrompt;
207
208
int
mPromptBlockNumber;
209
int
mPromptLength;
210
int
mPromptEndPosition;
211
int
mCompoundPromptEndPosition;
212
213
PromptType
mPromptType;
214
bool
mInCompletion;
215
216
QString
mCurrentCompoundInput;
217
QString
mCurrentInput;
218
219
int
mCurrentHistoryIndex;
220
int
mCurrentCompleterIndex;
221
222
std::shared_ptr<PythonConsoleHistory> mHistory;
223
PythonConsoleAbortThread
* mAbortThreadWidget;
224
225
bool
isCompound()
const
{
return
mPromptType ==
Compound
; }
226
bool
isInputMode()
const
{
return
mPromptType ==
Input
; }
227
228
void
keyPressEventInputMode(
QKeyEvent
* e);
229
};
230
}
hal::PythonConsoleAbortThread
Definition:
python_console.h:45
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:68
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:78
hal::PythonConsole::Input
@ Input
Definition:
python_console.h:78
hal::PythonConsole::Compound
@ Compound
Definition:
python_console.h:78
hal::PythonConsole::Standard
@ Standard
Definition:
python_console.h:78
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:
defines.h:45
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 by
1.9.1