aboutsummaryrefslogtreecommitdiffstats
path: root/gui/pythontab.cc
diff options
context:
space:
mode:
authorDavid Shah <davey1576@gmail.com>2018-06-27 12:00:37 +0200
committerDavid Shah <davey1576@gmail.com>2018-06-27 12:00:37 +0200
commit87a5b7212667daa55a72f62c35cc248bdce2c744 (patch)
treecd541aeba55bbc67e1a935bb00b7669a9eed0d32 /gui/pythontab.cc
parent2cc7ade05b52b89186f5210c97ebbc61aa5c166d (diff)
parentbafb4702c7176a08e4a9b2088297071a7bed6656 (diff)
downloadnextpnr-87a5b7212667daa55a72f62c35cc248bdce2c744.tar.gz
nextpnr-87a5b7212667daa55a72f62c35cc248bdce2c744.tar.bz2
nextpnr-87a5b7212667daa55a72f62c35cc248bdce2c744.zip
Merge branch 'master' of gitlab.com:SymbioticEDA/nextpnr
Diffstat (limited to 'gui/pythontab.cc')
-rw-r--r--gui/pythontab.cc33
1 files changed, 27 insertions, 6 deletions
diff --git a/gui/pythontab.cc b/gui/pythontab.cc
index 397920d9..816039ba 100644
--- a/gui/pythontab.cc
+++ b/gui/pythontab.cc
@@ -25,10 +25,8 @@
NEXTPNR_NAMESPACE_BEGIN
-PythonTab::PythonTab(QWidget *parent) : QWidget(parent)
+PythonTab::PythonTab(QWidget *parent) : QWidget(parent),initialized(false)
{
- PyImport_ImportModule("emb");
-
// Add text area for Python output and input line
plainTextEdit = new QPlainTextEdit();
plainTextEdit->setReadOnly(true);
@@ -57,7 +55,25 @@ PythonTab::PythonTab(QWidget *parent) : QWidget(parent)
setLayout(mainLayout);
connect(lineEdit, SIGNAL(textLineInserted(QString)), this, SLOT(editLineReturnPressed(QString)));
+}
+
+PythonTab::~PythonTab()
+{
+ if (initialized)
+ deinit_python();
+}
+void PythonTab::newContext(Context *ctx)
+{
+ if (initialized)
+ deinit_python();
+
+ plainTextEdit->clear();
+
+ init_python("nextpnr", !initialized);
+ python_export_global("ctx", ctx);
+
+ PyImport_ImportModule("emb");
write = [this](std::string s) {
plainTextEdit->moveCursor(QTextCursor::End);
plainTextEdit->insertPlainText(s.c_str());
@@ -65,6 +81,8 @@ PythonTab::PythonTab(QWidget *parent) : QWidget(parent)
};
emb::set_stdout(write);
+ initialized = true;
+
char buff[1024];
sprintf(buff, "Python %s on %s\n", Py_GetVersion(), Py_GetPlatform());
print(buff);
@@ -121,9 +139,12 @@ int PythonTab::executePython(std::string &command)
void PythonTab::editLineReturnPressed(QString text)
{
- std::string input = text.toStdString();
- print(std::string(">>> " + input + "\n"));
- executePython(input);
+ if (initialized)
+ {
+ std::string input = text.toStdString();
+ print(std::string(">>> " + input + "\n"));
+ executePython(input);
+ }
}
void PythonTab::showContextMenu(const QPoint &pt) { contextMenu->exec(mapToGlobal(pt)); }