From 07ff5ad8b8e4d0f87770b81b8478aa257567c504 Mon Sep 17 00:00:00 2001 From: Miodrag Milanovic Date: Fri, 13 Jul 2018 19:56:11 +0200 Subject: Made python console use edit line and better --- gui/pythontab.cc | 41 +++++++++++++++++++++++++++++++++++++---- 1 file changed, 37 insertions(+), 4 deletions(-) (limited to 'gui/pythontab.cc') diff --git a/gui/pythontab.cc b/gui/pythontab.cc index 897f87b3..5c349d7c 100644 --- a/gui/pythontab.cc +++ b/gui/pythontab.cc @@ -25,12 +25,20 @@ NEXTPNR_NAMESPACE_BEGIN +const QString PythonTab::PROMPT = ">>> "; +const QString PythonTab::MULTILINE_PROMPT = "... "; + PythonTab::PythonTab(QWidget *parent) : QWidget(parent), initialized(false) { + QFont f("unexistent"); + f.setStyleHint(QFont::Monospace); + // Add text area for Python output and input line console = new PythonConsole(); console->setMinimumHeight(100); - console->setEnabled(false); + console->setReadOnly(true); + console->setTextInteractionFlags(Qt::TextSelectableByMouse | Qt::TextSelectableByKeyboard); + console->setFont(f); console->setContextMenuPolicy(Qt::CustomContextMenu); QAction *clearAction = new QAction("Clear &buffer", this); @@ -41,9 +49,21 @@ PythonTab::PythonTab(QWidget *parent) : QWidget(parent), initialized(false) contextMenu->addAction(clearAction); connect(console, SIGNAL(customContextMenuRequested(const QPoint)), this, SLOT(showContextMenu(const QPoint))); + lineEdit = new LineEditor(&parseHelper); + lineEdit->setMinimumHeight(30); + lineEdit->setMaximumHeight(30); + lineEdit->setFont(f); + lineEdit->setPlaceholderText(PythonTab::PROMPT); + connect(lineEdit, SIGNAL(textLineInserted(QString)), this, SLOT(editLineReturnPressed(QString))); + QGridLayout *mainLayout = new QGridLayout(); mainLayout->addWidget(console, 0, 0); + mainLayout->addWidget(lineEdit, 1, 0); setLayout(mainLayout); + + parseHelper.subscribe(console); + + prompt = PythonTab::PROMPT; } PythonTab::~PythonTab() @@ -54,13 +74,27 @@ PythonTab::~PythonTab() } } +void PythonTab::editLineReturnPressed(QString text) +{ + console->displayString(prompt + text + "\n"); + console->moveCursorToEnd(); + + parseHelper.process(text.toStdString()); + + if (parseHelper.buffered()) + prompt = PythonTab::MULTILINE_PROMPT; + else + prompt = PythonTab::PROMPT; + + lineEdit->setPlaceholderText(prompt); +} + void PythonTab::newContext(Context *ctx) { if (initialized) { pyinterpreter_finalize(); deinit_python(); } - console->setEnabled(true); console->clear(); pyinterpreter_preinit(); @@ -74,7 +108,6 @@ void PythonTab::newContext(Context *ctx) QString version = QString("Python %1 on %2\n").arg(Py_GetVersion(), Py_GetPlatform()); console->displayString(version); - console->displayPrompt(); } void PythonTab::showContextMenu(const QPoint &pt) { contextMenu->exec(mapToGlobal(pt)); } @@ -83,4 +116,4 @@ void PythonTab::clearBuffer() { console->clear(); } NEXTPNR_NAMESPACE_END -#endif \ No newline at end of file +#endif // NO_PYTHON -- cgit v1.2.3 From 5216e488639fc8420d38c35177b796e1cf56ac8b Mon Sep 17 00:00:00 2001 From: Miodrag Milanovic Date: Sat, 14 Jul 2018 14:06:05 +0200 Subject: join python and info into one tab --- gui/pythontab.cc | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'gui/pythontab.cc') diff --git a/gui/pythontab.cc b/gui/pythontab.cc index 5c349d7c..e761128d 100644 --- a/gui/pythontab.cc +++ b/gui/pythontab.cc @@ -16,7 +16,6 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * */ -#ifndef NO_PYTHON #include "pythontab.h" #include @@ -77,7 +76,6 @@ PythonTab::~PythonTab() void PythonTab::editLineReturnPressed(QString text) { console->displayString(prompt + text + "\n"); - console->moveCursorToEnd(); parseHelper.process(text.toStdString()); @@ -114,6 +112,6 @@ void PythonTab::showContextMenu(const QPoint &pt) { contextMenu->exec(mapToGloba void PythonTab::clearBuffer() { console->clear(); } -NEXTPNR_NAMESPACE_END +void PythonTab::info(std::string str) { console->displayString(str.c_str()); } -#endif // NO_PYTHON +NEXTPNR_NAMESPACE_END -- cgit v1.2.3