![]() |
HAL
|
An interactable python console. More...
#include <python_console.h>
Public Types | |
enum | PromptType { Standard , Compound , Input } |
![]() | |
enum | LineWrapMode |
enum | AutoFormattingFlag |
![]() | |
enum | SizeAdjustPolicy |
![]() | |
enum | Shape |
enum | Shadow |
enum | StyleMask |
![]() | |
enum | RenderFlag |
![]() | |
enum | PaintDeviceMetric |
Public Slots | |
void | handleThreadFinished () |
Signals | |
void | inputReceived (QString input) |
Protected Member Functions | |
void | keyPressEvent (QKeyEvent *e) override |
void | mousePressEvent (QMouseEvent *event) override |
![]() | |
virtual void | keyReleaseEvent (QKeyEvent *e) override |
virtual void | resizeEvent (QResizeEvent *e) override |
virtual void | paintEvent (QPaintEvent *event) override |
virtual void | mouseMoveEvent (QMouseEvent *e) override |
virtual void | mouseReleaseEvent (QMouseEvent *e) override |
virtual void | mouseDoubleClickEvent (QMouseEvent *e) override |
virtual bool | focusNextPrevChild (bool next) override |
virtual void | contextMenuEvent (QContextMenuEvent *event) override |
virtual void | dragEnterEvent (QDragEnterEvent *e) override |
virtual void | dragLeaveEvent (QDragLeaveEvent *e) override |
virtual void | dragMoveEvent (QDragMoveEvent *e) override |
virtual void | dropEvent (QDropEvent *e) override |
virtual void | focusInEvent (QFocusEvent *e) override |
virtual void | focusOutEvent (QFocusEvent *e) override |
virtual void | showEvent (QShowEvent *) override |
virtual void | changeEvent (QEvent *e) override |
virtual void | wheelEvent (QWheelEvent *e) override |
virtual QMimeData * | createMimeDataFromSelection () const const |
virtual bool | canInsertFromMimeData (const QMimeData *source) const const |
virtual void | insertFromMimeData (const QMimeData *source) |
virtual void | inputMethodEvent (QInputMethodEvent *e) override |
virtual void | scrollContentsBy (int dx, int dy) override |
![]() | |
void | setViewportMargins (int left, int top, int right, int bottom) |
void | setViewportMargins (const QMargins &margins) |
QMargins | viewportMargins () const const |
virtual bool | event (QEvent *event) override |
virtual bool | viewportEvent (QEvent *event) |
virtual QSize | viewportSizeHint () const const |
![]() | |
void | initStyleOption (QStyleOptionFrame *option) const const |
![]() | |
virtual void | enterEvent (QEvent *event) |
virtual void | leaveEvent (QEvent *event) |
virtual void | moveEvent (QMoveEvent *event) |
virtual void | closeEvent (QCloseEvent *event) |
virtual void | tabletEvent (QTabletEvent *event) |
virtual void | actionEvent (QActionEvent *event) |
virtual void | hideEvent (QHideEvent *event) |
virtual bool | nativeEvent (const QByteArray &eventType, void *message, long *result) |
virtual int | metric (QPaintDevice::PaintDeviceMetric m) const const override |
virtual void | initPainter (QPainter *painter) const const override |
void | updateMicroFocus () |
void | create (WId window, bool initializeWindow, bool destroyOldWindow) |
void | destroy (bool destroyWindow, bool destroySubWindows) |
bool | focusNextChild () |
bool | focusPreviousChild () |
![]() | |
QObject * | sender () const const |
int | senderSignalIndex () const const |
int | receivers (const char *signal) const const |
bool | isSignalConnected (const QMetaMethod &signal) const const |
virtual void | timerEvent (QTimerEvent *event) |
virtual void | childEvent (QChildEvent *event) |
virtual void | customEvent (QEvent *event) |
virtual void | connectNotify (const QMetaMethod &signal) |
virtual void | disconnectNotify (const QMetaMethod &signal) |
![]() | |
QPaintDevice () | |
An interactable python console.
A widget that represents a simple python console with various features that most python consoles provide.
Definition at line 64 of file python_console.h.
Enumerator | |
---|---|
Standard | |
Compound | |
Input |
Definition at line 75 of file python_console.h.
hal::PythonConsole::PythonConsole | ( | QWidget * | parent = nullptr | ) |
Constructor.
Definition at line 19 of file python_console.cpp.
References QObject::connect(), displayPrompt(), QTextEdit::document, QTextEdit::ensureCursorVisible(), hal::gPythonContext, hal::SettingsItemDropdown::intChanged(), QFrame::NoFrame, QFrame::setFrameStyle(), QTextEdit::setUndoRedoEnabled(), and hal::MainWindow::sSettingStyle.
hal::PythonConsole::~PythonConsole | ( | ) |
Definition at line 38 of file python_console.cpp.
References hal::gPythonContext.
PythonConsoleAbortThread * hal::PythonConsole::abortThreadWidget | ( | ) |
Definition at line 465 of file python_console.cpp.
Referenced by hal::PythonConsoleWidget::PythonConsoleWidget().
void hal::PythonConsole::appendToCurrentCommand | ( | const QString & | new_command | ) |
Append the recently types python command with a string. (Used for auto-completion)
new_command | - The string that should be appended. |
Definition at line 348 of file python_console.cpp.
References QWidget::cursor, QTextCursor::End, and QTextEdit::textCursor().
Referenced by handleTabKeyPressed().
|
overridevirtual |
Clears the console.
Implements hal::PythonContextSubscriber.
Definition at line 240 of file python_console.cpp.
References QTextEdit::clear().
void hal::PythonConsole::displayPrompt | ( | ) |
Used to display the editors content within the QTextEdit.
Definition at line 253 of file python_console.cpp.
References Compound, QWidget::cursor, QTextEdit::document, QTextCursor::End, QTextCursor::EndOfLine, Input, hal::PythonConsoleQssAdapter::instance(), QString::length(), QTextCursor::position(), QTextFormat::setForeground(), QTextEdit::setTextCursor(), Standard, and QTextEdit::textCursor().
Referenced by handleTabKeyPressed(), interpretCommand(), and PythonConsole().
QString hal::PythonConsole::getCurrentCommand | ( | ) |
Get the recently types python command (of the current line).
Definition at line 328 of file python_console.cpp.
References control::command, QWidget::cursor, QTextCursor::End, QTextCursor::KeepAnchor, and QTextEdit::textCursor().
Referenced by handleTabKeyPressed(), handleUpKeyPressed(), and interpretCommand().
void hal::PythonConsole::handleDownKeyPressed | ( | ) |
Handles presses of KEY_DOWN. Used to jump forward in history.
Definition at line 389 of file python_console.cpp.
References QString::fromStdString(), and replaceCurrentCommand().
Referenced by keyPressEvent().
|
overridevirtual |
Prints forwarded error output messages.
output | - The forwarded output string. |
Implements hal::PythonContextSubscriber.
Definition at line 232 of file python_console.cpp.
References QString::endsWith(), insertAtEnd(), hal::PythonConsoleQssAdapter::instance(), and hal::output.
|
overridevirtual |
Prints forwarded standard output messages.
output | - The forwarded output string. |
Implements hal::PythonContextSubscriber.
Definition at line 227 of file python_console.cpp.
References insertAtEnd(), hal::PythonConsoleQssAdapter::instance(), and hal::output.
Referenced by handleTabKeyPressed().
void hal::PythonConsole::handleTabKeyPressed | ( | ) |
Handles presses of TAB. Used to indent or auto-complete the current command.
Definition at line 410 of file python_console.cpp.
References appendToCurrentCommand(), Compound, displayPrompt(), QString::fromStdString(), getCurrentCommand(), hal::gPythonContext, handleStdout(), Input, QTextEdit::insertPlainText(), QString::isEmpty(), log_info, QString::mid(), replaceCurrentCommand(), QString::size(), Standard, and QString::toStdString().
Referenced by keyPressEvent().
|
slot |
Definition at line 288 of file python_console.cpp.
References hal::PythonConsoleAbortThread::stop().
void hal::PythonConsole::handleUpKeyPressed | ( | ) |
Handles presses of KEY_UP. Used to jump back in history.
Definition at line 362 of file python_console.cpp.
References QString::fromStdString(), getCurrentCommand(), and replaceCurrentCommand().
Referenced by keyPressEvent().
|
signal |
Append the console with a text of a certain color.
text | - The appended text. |
textColor | - The color of the appended text. |
Definition at line 220 of file python_console.cpp.
References QTextCursor::End, QTextEdit::insertPlainText(), QTextEdit::moveCursor(), QTextEdit::setTextColor(), and QTextEdit::textColor().
Referenced by handleError(), and handleStdout().
void hal::PythonConsole::interpretCommand | ( | ) |
Process the recently typed python command after pressing ENTER/RETURN. If the command is within (or starts) a compound statement (for example a 'for'-loop), the command is appended to the current compound input. Else, the command (or the finished compound) is interpreted and executed.
Definition at line 293 of file python_console.cpp.
References Compound, QWidget::cursor, displayPrompt(), QTextCursor::End, getCurrentCommand(), hal::gPythonContext, hal::input, Standard, hal::PythonConsoleAbortThread::start(), and QTextEdit::textCursor().
Referenced by keyPressEvent().
|
overrideprotectedvirtual |
Overrides QTextEdit::keyPressEvent. It is used to handle the following (default) inputs:
e | - The key event. |
Reimplemented from QTextEdit.
Definition at line 74 of file python_console.cpp.
References QEvent::accept(), Qt::ControlModifier, QKeySequence::Copy, QTextEdit::copy(), QWidget::cursor, QKeySequence::Cut, QTextCursor::End, handleDownKeyPressed(), handleTabKeyPressed(), handleUpKeyPressed(), interpretCommand(), QKeyEvent::key(), Qt::Key_Backspace, Qt::Key_Control, Qt::Key_Down, Qt::Key_End, Qt::Key_Enter, Qt::Key_Home, Qt::Key_Left, Qt::Key_Return, Qt::Key_Right, Qt::Key_Tab, Qt::Key_Up, QTextEdit::keyPressEvent(), QKeyEvent::matches(), QKeyEvent::modifiers(), QTextCursor::MoveAnchor, QTextEdit::moveCursor(), QTextEdit::setTextCursor(), and QTextEdit::textCursor().
|
overrideprotectedvirtual |
Overrides QTextEdit::mouseEvent.
event | - The mouse event |
Reimplemented from QTextEdit.
Definition at line 205 of file python_console.cpp.
References QAbstractScrollArea::event(), and QTextEdit::mousePressEvent().
void hal::PythonConsole::replaceCurrentCommand | ( | const QString & | new_command | ) |
Replace the recently types python command with another one. (Used e.g. for navigating in the history)
new_command | - The new command. |
Definition at line 340 of file python_console.cpp.
References QWidget::cursor, QTextCursor::End, QTextCursor::KeepAnchor, and QTextEdit::textCursor().
Referenced by handleDownKeyPressed(), handleTabKeyPressed(), and handleUpKeyPressed().
bool hal::PythonConsole::selectionEditable | ( | ) |
Currently unused.
Definition at line 355 of file python_console.cpp.
References QWidget::cursor, QTextEdit::document, and QTextEdit::textCursor().
void hal::PythonConsole::setInputMode | ( | bool | state | ) |
Set input mode on or off. In input mode input for running script is expected.
state | - true=on, false=off |
Definition at line 245 of file python_console.cpp.
References Input, Standard, and hal::state.