-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconsolewidget.cpp
79 lines (66 loc) · 2.05 KB
/
consolewidget.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#include "consolewidget.h"
// #include <Python.h>
//#include <python3.8/Python.h> can use this notation to chose specific versions of python if got wide imports.
// #include <QDebug>
/**
* @brief Construct a new Console Widget:: Console Widget object
*
* @param parent
*/
ConsoleWidget::ConsoleWidget(QWidget *parent) : QWidget(parent), console(new pyConsole())
{
QPushButton* button = new QPushButton(tr("Run"));
lineEdit = new QLineEdit();
lineEdit->setAcceptDrops(true);
lineEdit->setPlaceholderText("Enter Python Commands in here.");
textEdit = new QPlainTextEdit();
textEdit->setPlaceholderText("Outputs Display Here.");
textEdit->setReadOnly(true);
textEdit->setMaximumBlockCount(100);
QVBoxLayout *vbox = new QVBoxLayout;
vbox->addWidget(lineEdit);
vbox->addWidget(button);
vbox->addWidget(textEdit);
//Connect Button Push to the Update Console function.
QObject::connect(button, &QPushButton::clicked, this, &ConsoleWidget::updateConsole , Qt::QueuedConnection);
QObject::connect(lineEdit, &QLineEdit::returnPressed, this, &ConsoleWidget::updateConsole , Qt::QueuedConnection);
this->setLayout(vbox);
}
/**
* @brief Destroy the Console Widget:: Console Widget object
*
*/
ConsoleWidget::~ConsoleWidget()
{
console->~pyConsole();
}
/**
* @brief Called when Button Pressed contains logic that takes text passes to Python and displays output.
*
*/
void ConsoleWidget::updateConsole(){
bool debug = false;
if (debug)
{
qInfo() << "Start of Update Console";
}
//Test1
//lineEdit->setText("Test");
//Test2
/*
QString linetext = lineEdit->text();
QString text = textEdit->toPlainText();
textEdit->setText(text +linetext);
*/
textEdit->appendPlainText(">>>" + lineEdit->text());
QString output = console->pyRun(lineEdit->text());
if (output!="")
{
textEdit->appendPlainText(output);
}
lineEdit->setText("");
if (debug)
{
qInfo() << "End of Update Console";
}
}