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 
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 
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:
57  void start();
58  void stop();
59  };
60 
68  {
69  Q_OBJECT
70 
71  public:
75  PythonConsole(QWidget* parent = nullptr);
77 
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 
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 
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 }
PythonConsoleAbortThread(QWidget *parent=nullptr)
An interactable python console.
void mousePressEvent(QMouseEvent *event) override
PythonConsole(QWidget *parent=nullptr)
void keyPressEvent(QKeyEvent *e) override
void setInputMode(bool state)
void inputReceived(QString input)
virtual void clear() override
virtual void handleStdout(const QString &output) override
PythonConsoleAbortThread * abortThreadWidget()
void replaceCurrentCommand(const QString &new_command)
void insertAtEnd(const QString &text, QColor textColor)
virtual void handleError(const QString &output) override
void appendToCurrentCommand(const QString &new_command)
Interface for handling python outputs.
Definition: defines.h:45
virtual bool event(QEvent *event) override
Q_OBJECTQ_OBJECT
Q_SIGNALSQ_SIGNALS
Q_SLOTSQ_SLOTS
QObject * parent() const const
QColor textColor() const const