aboutsummaryrefslogtreecommitdiffstats
path: root/gui/pythontab.cc
diff options
context:
space:
mode:
authorEddie Hung <eddie.hung+gitlab@gmail.com>2018-07-15 19:22:57 +0000
committerEddie Hung <eddie.hung+gitlab@gmail.com>2018-07-15 19:22:57 +0000
commit0bae7f5606b15591a23fb63da1c5ff6f93b40747 (patch)
tree7b0760fa1e5c837f9b43cf1c97fa9f55973a169b /gui/pythontab.cc
parent1457a6453c11af34a73460868833a9462e987854 (diff)
parent21bf78dae9ef95e65b549c60061bce9790b1b611 (diff)
downloadnextpnr-0bae7f5606b15591a23fb63da1c5ff6f93b40747.tar.gz
nextpnr-0bae7f5606b15591a23fb63da1c5ff6f93b40747.tar.bz2
nextpnr-0bae7f5606b15591a23fb63da1c5ff6f93b40747.zip
Merge branch 'master' into 'master'
Master See merge request eddiehung/nextpnr!1
Diffstat (limited to 'gui/pythontab.cc')
-rw-r--r--gui/pythontab.cc43
1 files changed, 37 insertions, 6 deletions
diff --git a/gui/pythontab.cc b/gui/pythontab.cc
index 897f87b3..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 <QGridLayout>
@@ -25,12 +24,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 +48,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 +73,26 @@ PythonTab::~PythonTab()
}
}
+void PythonTab::editLineReturnPressed(QString text)
+{
+ console->displayString(prompt + text + "\n");
+
+ 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,13 +106,12 @@ 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)); }
void PythonTab::clearBuffer() { console->clear(); }
-NEXTPNR_NAMESPACE_END
+void PythonTab::info(std::string str) { console->displayString(str.c_str()); }
-#endif \ No newline at end of file
+NEXTPNR_NAMESPACE_END