HAL  v4.5.0-257-ge24279b4e
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:
94  void keyPressEvent(QKeyEvent* e) override;
95 
102  void insertFromMimeData(const QMimeData* source) override;
103 
109  void mousePressEvent(QMouseEvent* event) override;
110 
111  public Q_SLOTS:
112  void handleThreadFinished();
113 
114  private Q_SLOTS:
115  void handleStyleChanged(int istyle);
116 
117  Q_SIGNALS:
118  void inputReceived(QString input);
119 
120  public:
126  virtual void handleStdout(const QString& output) override;
127 
133  virtual void handleError(const QString& output) override;
134 
138  virtual void clear() override;
139 
143  void displayPrompt();
144 
150  void interpretCommand();
151 
158 
164  void replaceCurrentCommand(const QString& new_command);
165 
171  void appendToCurrentCommand(const QString& new_command);
172 
178  bool selectionEditable();
179 
183  void handleUpKeyPressed();
184 
188  void handleDownKeyPressed();
189 
193  void handleTabKeyPressed();
194 
201  void insertAtEnd(const QString& text, QColor textColor);
202 
208  void setInputMode(bool state);
209 
211 
212  private:
213  QString mStandardPrompt;
214  QString mCompoundPrompt;
215  QString mInputPrompt;
216 
217  int mPromptBlockNumber;
218  int mPromptLength;
219  int mPromptEndPosition;
220  int mCompoundPromptEndPosition;
221 
222  PromptType mPromptType;
223  bool mInCompletion;
224 
225  QString mCurrentCompoundInput;
226  QString mCurrentInput;
227 
228  int mCurrentHistoryIndex;
229  int mCurrentCompleterIndex;
230 
231  std::shared_ptr<PythonConsoleHistory> mHistory;
232  PythonConsoleAbortThread* mAbortThreadWidget;
233 
234  bool isCompound() const { return mPromptType == Compound; }
235  bool isInputMode() const { return mPromptType == Input; }
236 
237  void keyPressEventInputMode(QKeyEvent* e);
238 
244  void discardInput(bool wholeStatement);
245 
249  static QString expandTabs(const QString& text);
250  };
251 }
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 insertFromMimeData(const QMimeData *source) override
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